Managing Cloud Server disks > Activating a disk added to a Linux Cloud Server

05 Activating a disk added to a Linux Cloud Server

The operations described may affect the system and data, potentially causing malfunctions or data loss:
  • always back up your data or the entire server externally before performing any operation;
  • if available, create a snapshot of the server from the management panel before making changes to the system;
  • for unmanaged services, you are responsible for managing the operating system and software;
  • if in doubt, consult a trusted system administrator or check the latest official documentation for the operating system or software in use.

Prerequisites

The procedure uses the fdisk and parted commands and requires LVM (Logical Volume Manager) for volume management.
If they are not available on the version you are using, install them before starting the procedure:
  • to install parted or LVM2 on Debian:

    sudo apt install parted

    sudo apt install lvm2

  • to install parted on AlmaLinux (this also installs or updates LVM2):

    sudo dnf install -y parted


This procedure has been tested on the following operating systems:
  • Ubuntu 24.04 and 22.04
  • Debian 12 and 11
  • AlmaLinux 9 and 8
  • Rocky Linux 9 and 8
The following procedure is not guaranteed to work on operating systems that are no longer supported (CentOS 6 and 7, Debian 9 and 10, Ubuntu 16, 18 and 20.04).

Summary of steps:
  1. identify the new disk;
  2. create a new LVM partition on the disk;
  3. create a Physical Volume (PV);
  4. create a Volume Group (VG);
  5. create a Logical Volume (LV);
  6. format the newly created logical volume with the required file system;
  7. retrieve the volume UUID;
  8. create the mount point;
  9. mount the volume manually;
  10. check that the volume is mounted;
  11. configure automatic mounting at boot (edit /etc/fstab);
  12. check that fstab is correct;
  13. check the disk status and the mount point of the newly added disk.
Connect to your Cloud Server via SSH as the root user and follow these steps:
  1. to identify the new disk, run the command:

    lsblk

    look for a disk with no mounted partitions, for example /dev/sdb
    if you have a third disk named /dev/sdc and want to use that disk, use sdc instead of sdb, for example;
    check that you have identified the correct disk (be careful not to format the wrong disk) by running:

    sudo fdisk -l /dev/sdb

  2. use the parted command to create the GPT partition table and an LVM partition by running these three commands in sequence:

    sudo parted /dev/sdb --script mklabel gpt

    sudo parted /dev/sdb --script mkpart primary 0% 100%

    sudo parted /dev/sdb --script set 1 lvm on

  3. to create the Physical Volume (PV), enter:

    sudo pvcreate /dev/sdb1

    in this case, you are creating the PV on the sdb disk. If you want to create it on the sdc disk, enter sudo pvcreate /dev/sdc1;
    the name assigned to the PV (in this example /dev/sdb1) must then be entered correctly in every command where the PV needs to be specified;
  4. to create the Volume Group (VG), enter:

    sudo vgcreate vg-hd1 /dev/sdb1

    in this case, you are creating the VG with the name vg-hd1, but you can choose a different name;
    the name assigned to the VG (in this example vg-hd1) must then be entered correctly in every command where the VG needs to be specified;
  5. to create the Logical Volume (LV), enter:

    sudo lvcreate -l 100%FREE -n lvdata vg-hd1

    in this case, you are creating the LV with the name lvdata, but you can choose a different name;
    100%FREE indicates that the LV is being created using 100% of the available space;
    the name assigned to the LV (in this example lvdata) must then be entered correctly in every command where the LV needs to be specified;
  6. to format the newly created Logical Volume, specify the file system (ext4 in this example) by entering:

    sudo mkfs.ext4 /dev/vg-hd1/lvdata

    if you choose a different file system (e.g. xfs), make sure that it is compatible with your operating system;
    remember to specify it correctly in the following commands, for example when mounting via UUID;
  7. to display only the UUID (Universally Unique Identifier), enter:

    sudo blkid -s UUID -o value /dev/vg-hd1/lvdata

    you will receive an alphanumeric code such as 7905b5e7-6ce3-4750-9c98-4d4c187aafe6;
  8. create the mount point by assigning a name to the directory (data-HD1 in this example) using the command:

    sudo mkdir -p /mnt/data-HD1

    the name assigned to the directory must then be entered correctly in every command where the mount point needs to be specified;
  9. mount the volume manually using the UUID (see step 7 - 7905b5e7-6ce3-4750-9c98-4d4c187aafe6) and the mount point (see step 8 - /mnt/data-HD1) with the command:

    sudo mount UUID=7905b5e7-6ce3-4750-9c98-4d4c187aafe6 /mnt/data-HD1

    make sure there is only one space between the UUID and the mount point, otherwise the mount will fail;
  10. check the mount using the mount point (see step 8 - /mnt/data-HD1) with the command:

    df -h | grep /mnt/data-HD1

  11. to configure automatic mounting at boot (by editing /etc/fstab):
    • create a backup of the fstab file by entering:

      sudo cp /etc/fstab /etc/fstab.backup

    • open the /etc/fstab file with a text editor (nano in this example):

      sudo nano /etc/fstab

    • at the bottom of the file, add the following line, preceded by the comment (#Automatic mounting of additional disk):

      #Automatic mounting of additional disk:
      UUID=7905b5e7-6ce3-4750-9c98-4d4c187aafe6 /mnt/data-HD1 ext4 defaults 0 2

      using the UUID (see step 7 - 7905b5e7-6ce3-4750-9c98-4d4c187aafe6) and the mount point (see step 8 - /mnt/data-HD1);
      always pay attention to spacing and any unwanted characters when copying the data;
      the final 0 and 2 values in this line should be left at their default values;
    • if you used the nano editor, save, exit and return to the terminal using the following commands:
      CTRL+O
      ENTER
      CTRL+X
      if you used an editor other than nano, check the corresponding commands to save, exit and return to the terminal;
  12. after exiting the editor, check that fstab is correct using the command:

    sudo mount -a

    if no errors are returned, the mount configuration is valid;
    only if you are notified that the fstab file has been edited but systemd is still using the old version, consider restarting the server or run the following command:

    systemctl daemon-reload

  13. check the disk status using the command:

    lsblk