Skip to end of banner
Go to start of banner

Manage a Data Volume

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 27 Next »


This page:

After creating your instance, it is important to have a place to store your data. The usual way to do this is with a data volume attached to your instance.

Storing input or output data on the root volume of your instance can quickly fill it up, leading to problems with using or even logging into the instance. Follow the instructions below to use a data volume instead.

Create and Attach a Data Volume

Create and attach a volume


  1. Log in to the Nimbus dashboard.
  2. Navigate to Volumes > Volumes, then click + Create Volume to bring up the Create Volume dialogue window.

    You may see an existing volume already there, with a name like 91bd1e23-ce06-41e0-aeb5-41382df48170. It is most likely the root volume for your instance, and you can ignore it.


    1. Enter a volume name
    2. Enter a Size in gigabytes
    3. Click Create Volume
  3. Back on the Volumes page, click the drop-down arrow next to Edit Volume and click Manage Attachments.

  4. Select an instance to attach this volume to
  5. Click Attach Volume

Create a filesystem


Once you have attached the volume as above, confirm that the volume is properly attached.

You may see the /dev/sda or /dev/vda device when working with volumes and filesystems, e.g. with the df command. This is the root volume, mounted at / (known as slash or root), where the operating system and system files are stored. You will not be performing any format or mount commands on this device.

For instances created before May 2022, volumes will be seen by the instance with device names such as /dev/vda or /dev/vdc instead of the newer and more common /dev/sda or /dev/sdc

If your instance uses the old vdX names, replace sdX with vdX

  • Use ssh to log in to your instance from a terminal
  • Check that you have properly attached the volume (you should see a list of sdX disks):

    $ lsblk
    
    sda       8:0    0   40G  0 disk 
    ├─sda1    8:1    0 39.9G  0 part /
    ├─sda14   8:14   0    4M  0 part 
    └─sda15   8:15   0  106M  0 part /boot/efi
    sdc       8:32   0   80G  0 disk 

    In the output above, there is a 40GB root disk (sda) and 1 x 80GB volume storage disk (sdc).

    Check the 80GB volume storage disk:

    $ sudo fdisk -l /dev/sdc

    You should see this returned:

    Disk /dev/sdc: 80 GiB, 85899345920 bytes, 167772160 sectors
    Disk model: QEMU HARDDISK   
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
  • (Only new volumes) Format the volume with a new filesystem:

    Do this step only for new volumes. Do NOT do this step for existing volumes, as it will wipe any existing data on it.

    $ sudo mkfs.ext4 /dev/sdc

    *** Wait 30 seconds before the next step ***

Mount the filesystem


  1. Check the UUID of your volume: 

    $ sudo blkid
    
    /dev/sda1: LABEL="cloudimg-rootfs" UUID="095994dc-6b15-45a9-bb21-a1c68493be18" TYPE="ext4" PARTUUID="3632202a-4dcc-4d02-8249-d55b4719ce75"
    /dev/sdc: UUID="0d5a2683-2645-4b84-bad0-256d0f1693a8" TYPE="ext4"
  2. Mount the volume (/dev/sdc) to a new directory called /data (making sure to copy the UUID) as such:

    $ sudo mkdir /data
    $ sudo mount UUID="0d5a2683-2645-4b84-bad0-256d0f1693a8" /data
  3. Check your new /data volume is mounted correctly:

    $ lsblk | grep sdc
    
    sdc       8:32   0   80G  0 disk /data


  4. Check that you can write files to your new volume:

    cd /data
    touch test.txt

    If you see an error about 'permission denied', you most likely need to change the owner of the volume to ubuntu (that's you!) with the following command

    sudo chown ubuntu /data

You have now successfully attached and mounted your data volume.

You need only create and attach a volume to your instance once, and should only format the filesystem once.

If your instance is rebooted for any reason, you will need to mount your volume again.

You can also only mount one data volume with one instance at a time.  If you want to access the same volume from multiple instances, we suggest mounting it on one instance, then sharing it out to the others on your private network via NFS


Re-mount a volume after a reboot


It is possible for the disk name of your volume to change after rebooting your instance. If so, follow the instructions to re-mount your volume with the correct disk name.

  1. First, check the UUID of your volume: 

    $ sudo blkid
    
    /dev/sda1: LABEL="cloudimg-rootfs" UUID="095994dc-6b15-45a9-bb21-a1c68493be18" TYPE="ext4" PARTUUID="3632202a-4dcc-4d02-8249-d55b4719ce75"
    /dev/sdc: UUID="0d5a2683-2645-4b84-bad0-256d0f1693a8" TYPE="ext4"
  2. Mount the volume (/dev/sdc) to your directory (e.g. /data) (making sure to copy the UUID) as such:

    $ sudo mkdir /data
    $ sudo mount UUID="0d5a2683-2645-4b84-bad0-256d0f1693a8" /data


Resize a Volume


It is possible to resize an existing data volume to make it larger, if additional space is required in an instance. This option is dependent on a few things:

  • You need to have sufficient volume storage quota in your project. Go to the Overview page on the Nimbus dashboard to see how much volume storage is available.
  • You cannot resize a root volume of an instance (the volume mounted as /dev/sda1 or /dev/vda1 inside the instance). If you require a larger root volume, your only option is to delete the instance and re-create it with a larger root volume on the Source section during instance creation.
  • You cannot shrink an existing volume. The new volume size must be larger than the old size.

Provided it meets all these requirements, you can resize a volume by the following steps:

  1. Log on to the instance, and make sure that any file systems on that volume are unmounted (use umount if it is mounted):

    $ df -h
    $ sudo umount /data
  2. Leaving your instance login active, log on to the Nimbus dashboard, go to the Volumes page, and select Manage Attachments from the drop-down menu to the right of the volume
  3. Click Detach Volume, and confirm
  4. Once detached, select Extend Volume from the drop-down menu to the right of the volume
  5. Enter the new size in GB (it must be larger than the current size), then click Extend Volume
  6. To re-attach the volume, select Manage Attachments from the drop-down menu to the right of the volume
  7. Select the instance you want to attach it to, make a note of the value of the Device Name field (usually /dev/sdc), then click on Attach Volume
    1. Go back to your active instance login from step 2, and check for the UUID of that volume: 

      $ blkid
      
      /dev/sda1: LABEL="cloudimg-rootfs" UUID="095994dc-6b15-45a9-bb21-a1c68493be18" TYPE="ext4" PARTUUID="3632202a-4dcc-4d02-8249-d55b4719ce75"
      /dev/sdc: UUID="0d5a2683-2645-4b84-bad0-256d0f1693a8" TYPE="ext4"
    2. make sure that the operating system can see the attached volume:
  8. $ sudo fdisk -l /dev/sdc
  9. Run a file system check on the partition first (assuming that the partition is /dev/sdc, although fdisk will tell you if the partition has a different name like /dev/sdc1):

    $ sudo e2fsck -f /dev/sdc


  10. Resize the partition to use the additional space added to the volume:

    $ sudo resize2fs /dev/sdc


  11. You can now mount the volume again (replace /data with the mount point you normally use for the volume):

    $ sudo mount UUID="0d5a2683-2645-4b84-bad0-256d0f1693a8" /data



  • No labels