Mount Linux 2nd Drive

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.

Step 1

Log into VM using the credentials that were emailed when the VM was built and run sudo apt update and sudo apt upgrade.

Step 2

Run command below to view the basic details about all available drives in the VM.

Run: sudo lsblk

../_images/mount_secondary1.png

The secondary drive in the screenshot above is /dev/vdb.

Note that your secondary drive may be named something different.

Step 3

Install Logical Volume Manager library

Run: sudo apt-get install lvm2

Step 4

Create Physical Volumes out of additional drives:

Run: sudo pvcreate /dev/vdb

../_images/mount_secondary2.png

Step 5

Create Volume Group named “MyVolGroup” out of all additional drives:

Run: sudo vgcreate MyVolGroup /dev/vdb

../_images/mount_secondary3.png

Step 6

Create Logical Volume “MyLv” with all the available pace of the Volume Group “MyVolGroup”

Run: sudo lvcreate -l 100%FREE -n MyLv MyVolGroup

../_images/mount_secondary4.png

Step 7

Format LV “MyLv” with the ext4 file system

Run: sudo mkfs.ext4 /dev/MyVolGroup/MyLv

../_images/mount_secondary5.png

Step 8

Create a mount point.

Run: sudo mkdir /mnt/data

Step 9

Mount the logical volume to the mount point

Run: sudo mount /dev/mapper/MyVolGroup-MyLv /mnt/data/

Step 10

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

../_images/mount_secondary6.png

Step 11

Logical Volume is mounted on /mnt/data

Run: sudo df -h

../_images/mount_secondary7.png

Step 12

Reboot VM

Run: sudo reboot