Attaching a Volume to a VM

You can attach a volume to a virtual machine (VM) within the same Subregion to add additional storage. You can attach several volumes to a VM (up to 40), for example to separate different types of data. For more information, see About Volumes > Volumes Attachment and Device Names.

Linking a Volume to a VM Using Cockpit v2

  1. In the Volumes dashboard, check the box of the volume you want to link.
    The volume is selected.

    You can also select a VM in the VMs dashboard and click IconLink Link Volume.

  2. Click IconLink Link VM.
    The LINK VM dialog box appears.

  3. In the VM list, select the VM you want to link the volume to.

  4. In the Device list, select the device name you want to assign to the volume.

  5. Click Link.
    The volume is linked to the selected VM.

    Once the volume is attached, you must mount it on an operating system level to make it available for use. For more information, see Initializing a Volume from a VM.

Linking a Volume to a VM Using OSC CLI

The LinkVolume command attaches a Block Storage Unit (BSU) volume to a virtual machine (VM).
The volume and the VM must be in the same Subregion. The VM can be running or stopped. The volume is attached to the specified VM device.

Request sample
$ osc-cli api LinkVolume --profile "default" \
    --VolumeId "vol-12345678" \
    --VmId "i-12345678" \
    --DeviceName "/dev/sdb"

This command contains the following attributes that you need to specify:

  • DeviceName: The name of the device. For a root device, you must use /dev/sda1. For other volumes, you must use /dev/sdX, /dev/sdXX, /dev/xvdX, or /dev/xvdXX (where the first X is a letter between b and z, and the second X is a letter between a and z).

  • DryRun: (optional) If true, checks whether you have the required permissions to perform the action.

  • VmId: The ID of the VM you want to attach the volume to.

  • VolumeId: The ID of the volume you want to attach.

The LinkVolume command returns the following elements:

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  }
}

Once the volume is attached, you must mount it on an operating system level to make it available for use. For more information, see Initializing a Volume from a VM.

Attaching a Volume to an Instance Using AWS CLI

Before you begin: Install and configure AWS CLI. For more information, see Installing and Configuring AWS CLI.

To attach a volume to an instance, use the attach-volume command following this syntax:

Request sample
$ aws ec2 attach-volume \
    --profile YOUR_PROFILE \
    --volume-id vol-12345678 \
    --instance-id i-87654321 \
    --device /dev/xvdb \
    --endpoint https://fcu.eu-west-2.outscale.com

This command contains the following attributes that you need to specify:

The attach-volume command returns a result as follows:

  • AttachTime: The time at which the attachment was initiated.

  • InstanceId: The ID of the instance.

  • VolumeId: The ID of the volume.

  • State: The attachment state of your volume (attaching | detaching | attached | detached).

  • Device: The device name you specified when attaching the volume.

Result sample
{
"AttachTime": "2016-02-05T13:56:48.970Z",
"InstanceId": "i-87654321",
"VolumeId": "vol-12345678",
"State": "attaching",
"Device": "/dev/xvdb"
}

The volume is attached to the specified instance.

Once the volume is attached, you must mount it on an operating system level to make it available for use. For more information, see Initializing a Volume from a VM.

Related Pages

Corresponding API Methods

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.