Skip to main content

Initialize a volume from a VM

After attaching a volume to a VM (Virtual Machine), you must initialize it to make it usable.

Create the volume file system (new empty volume only)

  1. Connect to your VM.

  2. (optional) To obtain the device name of the volume you want to mount, run the following command to display the list of devices attached to the VM:

    $ lsblk
    warning

    Inside the VM, a device that you named xvdX or xvdXX in your account is typically renamed sdY or sdYY.

  3. (optional) To check that the volume is empty, run the following command:

    $ sudo file -s /dev/DEVICE_NAME

    If the command returns only data, the volume has no file system and you must create one.

    If the command returns anything else, the volume already has a file system.

  4. To create and format an xfs file system on the whole volume, run the following command:

    sudo mkfs -t xfs /dev/DEVICE_NAME
    warning

    We recommend that you do not partition volumes or use LVM on the Numspot cloud, as these practices can degrade volume performance. It is preferable to use volumes directly as they are.

Mount the volume

  1. To create a directory that will serve as the mount point for the volume, run the following command:
    $ sudo mkdir /MOUNT_POINT
  2. To mount the volume on the mount point, run the following command:
    $ sudo mount /dev/DEVICE_NAME /MOUNT_POINT
    info

    To confirm that the mount was successful, you can run the df -hT command to display the list of all volumes mounted on the VM.

    The volume is initialized from your VM and ready to be used.

Make the mount permanent

danger

For the volume mount to persist across reboots, you must edit the /etc/fstab file, which configures and mounts the VM volumes. To avoid any potential loss of access to your data, we recommend that you create a backup of this file before editing it, using the following command:

$ sudo cp /etc/fstab /etc/fstab.orig
  1. Open the /etc/fstab file using the following command:

    $ sudo vim /etc/fstab
  2. Press i to enable insert mode, then add the following line at the end of the file:

    /dev/DEVICE_NAME /MOUNT_POINT xfs defaults,nofail 0 2

    To learn more about the possible configuration options, see for example the fstab page in the Ubuntu documentation.

  3. Press Esc, then type :wq to save the file.

  4. (optional) To check the validity of the file, run the following command to reload it:

    $ sudo mount -a

    If the command returns an error message, the options contained in the file are not valid. You must then restore the original file and reconfigure it.

    info

    To restore the original /etc/fstab file, run the following command:

    $ sudo mv /etc/fstab.orig /etc/fstab