Whenever you build a Linux VM with two or more drives, the first drive contains the operating system (OS) and is automatically attached to the VM. You need to manually “attach” the second and subsequent drives after the VM is built in order to use it/them. There are multiple ways of doing this, the tutorial below demonstrates how to create and mount a logical volume using a logical volume manager (LVM). In this example, there is a 15GB drive on which the OS is installed (primary drive) and a second 25GB drive for extra storage.
Log into VM using the credentials that were emailed when the VM was built and run sudo apt update and sudo apt upgrade.
Run command below to view the basic details about all available drives in the VM.
sudo lsblk
The secondary drive in the screenshot above is /dev/vdb.
Note that your secondary drive may be named something different.
Install Logical Volume Manager library
sudo apt-get install lvm2
Create Physical Volumes out of additional drives:
sudo pvcreate /dev/vdb
If there is warning reported that the physical volume cannot be initialised, this means /dev/vdb has some existing metadata or data that prevents it from being initialized as a physical volume. This occurs if the drive was previously mounted on a VM.
To get the name of the Volume:
sudo vgscan
To activate the volume group so that its logical volumes can be accessed:
sudo vgchange -ay MyVolGroup
This makes the logical volumes available for mounting. Please continue to Step 8
Create Volume Group named “MyVolGroup” out of all additional drives:
sudo vgcreate MyVolGroup /dev/vdb
Create Logical Volume “MyLv” with all the available pace of the Volume Group “MyVolGroup”
sudo lvcreate -l 100%FREE -n MyLv MyVolGroup
Format LV “MyLv” with the ext4 file system
sudo mkfs.ext4 /dev/MyVolGroup/MyLv
Create a mount point.
sudo mkdir /mnt/data
Mount the logical volume to the mount point
sudo mount /dev/mapper/MyVolGroup-MyLv /mnt/data/
Modify /etc/fstab so that the LV is mounted during the boot
sudo nano /etc/fstab
Append the following to the end of the fstab file
/dev/mapper/MyVolGroup-MyLv /mnt/data ext4 defaults 0 0
Logical Volume is mounted on /mnt/data
sudo df -h
Reboot VM
sudo reboot