Detaching a Volume from a VM

You can detach a volume from a virtual machine (VM), which enables you to attach it to another VM and then access your data again.

Unlinking a Volume from a VM Using Cockpit v2

For Linux VMs, the mounting of the volume must be permanent to prevent failure when starting the VM. For more information, see Initializing a Volume from a VM > (optional) Make the Mounting Permanent.

  1. In the Volumes dashboard, check the box of the volume you want to unlink from a VM.

    • Unlinking a volume on which data is being used or written may damage your resources.

    • You can unlink the root device from a VM if this VM is stopped. However, you will not be able to restart this VM using this root device.

    The volume is selected.

    You can also select a VM in the VMs dashboard and click IconUnlink Unlink Volume.

  2. Click IconUnlink Unlink from VM.
    A confirmation dialog box appears.

  3. Click Unlink.
    The volume is unlinked from the VM.

Unlinking a Volume from a VM Using OSC CLI

For Linux VMs, the mounting of the volume must be permanent to prevent failure when starting the VM. For more information, see Initializing a Volume from a VM > (optional) Make the Mounting Permanent.

The UnlinkVolume command detaches a Block Storage Unit (BSU) volume from a virtual machine (VM).
To detach the root device of a VM, this VM must be stopped.

Request sample
$ osc-cli api UnlinkVolume --profile "default" \
    --VolumeId "vol-12345678"

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

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

  • ForceUnlink: (optional) Forces the detachment of the volume in case of previous failure. Important: This action may damage your data or file systems.

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

The UnlinkVolume 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"
  }
}

Unlinking a Volume from a VM Using oapi-cli

For Linux VMs, the mounting of the volume must be permanent to prevent failure when starting the VM. For more information, see Initializing a Volume from a VM > (optional) Make the Mounting Permanent.

The UnlinkVolume command detaches a Block Storage Unit (BSU) volume from a virtual machine (VM).
To detach the root device of a VM, this VM must be stopped.

Request sample
$ oapi-cli --profile "default" UnlinkVolume \
    --VolumeId "vol-12345678"

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

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

  • ForceUnlink: (optional) Forces the detachment of the volume in case of previous failure. Important: This action may damage your data or file systems.

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

The UnlinkVolume 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"
  }
}

Detaching a Volume from an Instance Using AWS CLI

For Linux instances, the mounting of the volume must be permanent to prevent failure when starting the instance. For more information, see Initializing a Volume from a VM > (optional) Make the Mounting Permanent.

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

To detach a volume from an instance, use the detach-volume command following this syntax:

Request sample
$ aws ec2 detach-volume \
    --profile YOUR_PROFILE \
    --volume-id vol-12345678 \
    --endpoint https://fcu.eu-west-2.outscale.com

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

The detach-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 the 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":"detaching",
 "Device":"/dev/xvdb"
}

The volume is detached from the instance and is now available.

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.