This is a walkthrough of manageing storage using LVM under Ubuntu
I built a Basic Ubuntu 14.03 machine - nothing fancy.
In VirtualBox I choose to allocate 8Gb of storage.
- Install LVM (Just about the 1st screen)
Wait 5 mins and then the server has been created.
Looking in the Machine
The machine reboots - and I check the disk space...
I can see 57% of the disk is already used - but interestingly I can see RHEL is already using Logical Volumes.
I will do the following 3 tests - there are more tests shown using the RHEL LVM page.
-Add a new disk drive and add to Volume Group
Shut the machine down - and on command prompt do the following.
Create a Disk
If your storage device is VMDK - then you need to convert that to VDI
VBoxManage createmedium --format /srv/d1/VirtualBox/HardDisks/disk2.vdi
I now add this (cheating throught the GUI) else
vboxmanage storageattach 01bcc3cd-341a-46dc-bf7f-23f6b1bf51a3 --storagectl "SATA" --port 2 --device 0 --type hdd --medium /srv/d1/VirtualBox/HardDisks/disk2.vdi
Adding The Storage
Boot the machine - and as root
df Take note of the logical volume mapping (ex. /dev/mapper/vg_lvm/lv_root)
Take note of the filesystem partition of your physical volume sits (ex. /dev/sda2)
fdisk /dev/sdb We need to organise the partitions
Select your partition (we are creating from new from /dev/sdb)
Create a new partition
Make it a primary partition
The partition number to make it on (same as we deleted)
reboot We must reboot in order to have the new partition table loaded
vgextend my_volume_group /dev/sdb1 Add Disk to Volume Group
pvresize /dev/sdb1 Resizes the physical volume pvscan Use to verify the new size lvextend -l +100%FREE /dev/vg_lvm/lv_root Extend the logical volume to take all free space resize2fs /dev/vg_lvm/lv_root Resize the file system df See your newly sized volume
And that is it! With the last df command, you should see that your volume increased!
df fdisk -l fdisk /dev/sda d 2 n p 2 <return> <return> w reboot pvresize /dev/sda2 pvscan lvextend -l +100%FREE /dev/vg_lvm/lv_root resize2fs /dev/vg_lvm/lv_root
Shut the VM down and create a new drive.
vboxmanage createmedium disk --filename ~/VirtualBox\ VMs/RH_LVM_test/disk3.vdi --format VDI --size 2500 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Medium created. UUID: c5be9a2b-478f-4556-b078-6c6fbf0e33b6
Add Storage to VM
Now add this Disk to the VM
VBoxManage storageattach 01bcc3cd-341a-46dc-bf7f-23f6b1bf51a3 --storagectl "SATA" --port 2 --device 0 --type hdd --medium ~/VirtualBox\ VMs/RH_LVM_test/disk3.vdi
Note u may need to alter the port value depending how many other Disks you have.
We should now have our existing disk available - but the new drive is currently now used.
Shows /dev/sdb and is 2.6 Gb is size.
o create new Partition Table
n New Partition
1 Partition No
return Start Block
return End Block
w Write and Exit
Add Physical Volume to a Volume Group
Check what VG there are
vgextend vg_lvm /dev/sdb1
At this point the new Disk in in the new Volume Group (But now the Logical Volume)
Add to Logical Volume
lvextend /dev/vg_lvm/lv_root /dev/sdb1
You should now see that the storage available has increased.
Resize the LV
If you are using RHEL/Fedora etc then you can increase the LV with
Add New Disk is easy, expand existing disk is easy - but ONLY if you are using Logical Volumes.