[How To] Add a 3rd disk to a VM and mount using LVM

Sometimes, you need to add 3rd disk to a VM to increase disk space and use only a portion of it. For example, a VM is shared by a number of users. You’ve run out of disk space. You add 1TB HDD and allocate 250GB to a new user, leaving the rest of the disk space to be used at later stage. Below are the steps that need to be performed at the OS level to make sure the allocated space is accessible.

Assuming that you’ve added the 1TB HDD as a 3rd Hard Drive to the VM and rebooted the server. I’ve assumed you’re using VMware Vcenter, however, it should still work for Virtual Box. The steps are tested in Ubuntu 14.04 and RHEL 6.

Note: Please test configs in DEV/UAT before jumping into Production machines. And please back up before attempting this change. I’m not responsible for lost data.

Now, we need to create a new partition and add 250G as allocated space.

fdisk /dev/sdc
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1

First cylinder (1-2610, default 1): "enter"
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +250G
Using default value 2610
Command (m for help): t
Selected partition 1

Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Once, a drive is assigned, we need to perform the steps in LVM to add a logical volume and mount it to an accessible location

~# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created

Extend the vg_data volume group

~# vgextend vg_data /dev/sdc1
Volume group "vg_data" successfully extended

Create the logical volume

:~# lvcreate -L 250G -n NewVolume vg_data

Format the volume to Ext4 (assuming you’re using ext4 as the filesystem)
:~# mkfs.ext4 /dev/vg_data/NewVolume

Mount the drive in /opt

mkdir /opt/NewVolume
mount /dev/vg_data/NewVolume /opt/NewVolume

To make the mount permanent you need to edit /etc/fstab and add the mount information

Leave a Reply

tuxtrixmod
Close Menu
%d bloggers like this: