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.
Run: 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
Run: sudo apt-get install lvm2
Create Physical Volumes out of additional drives:
Run: sudo pvcreate /dev/vdb
Create Volume Group named “MyVolGroup” out of all additional drives:
Run: sudo vgcreate MyVolGroup /dev/vdb
Create Logical Volume “MyLv” with all the available pace of the Volume Group “MyVolGroup”
Run: sudo lvcreate -l 100%FREE -n MyLv MyVolGroup
Format LV “MyLv” with the ext4 file system
Run: sudo mkfs.ext4 /dev/MyVolGroup/MyLv
Create a mount point.
Run: sudo mkdir /mnt/data
Mount the logical volume to the mount point
Run: sudo mount /dev/mapper/MyVolGroup-MyLv /mnt/data/
Modify /etc/fstab so that the LV is mounted during the boot
Run: 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
Run: sudo df -h
Reboot VM
Run: sudo reboot