lvm migration

This is a walkthrough of manageing storage using LVM under RHEL

Basic MAchine

I built a Basic RHEL 6.4 machine - nothing fancy.

In VirtualBox I choose to allocate 8Gb of storage.

I chose

  • basic storage
  • overwrite partitions

For the server type I chose

  • basic server

Wait 5 mins and then the server has been created.

Definitions

We of course need to definitions to carry on with.

  • Logical Volume
    • Volume Group
    • Physical Volume

So this can be looked as

  • LV1
    • VG1
    • /dev/sda
    • /dev/sdb
    • VG2
    • /dev/sdc
    • /dev/sdd

Looking in the Machine

The machine reboots - and I check the disk space...

df -kh

I can see 57% of the disk is already used - but interestingly I can see RHEL is already using Logical Volumes.

Volume Group

Add to a VolumeGroup

vgextend vg1 /dev/sda3

Show Volume Group

To see a VolumeGroup

vgdisplay

List All Physical Volumes

pvscan

To See Physical Volume

pvdisplay

To Change the Size of physical Volume

pvresize

Practical Tests

I will do the following 3 tests

  • expand the initial storage using vmtools
  • create new virtual drive 2Gb
  • create new virtual drive 4Gb

Shut the machine down - and on command prompt do the following.

VMDK Disk ?

If your storage device is VMDK - then you need to convert that to VDI

 VBoxManage clonehd --format VDI myserver.vmdk \
/srv/d1/VirtualBox/HardDisks/myserver.vdi

After expanding (next section) - replace the boot disk with the VDI one - and continue the walkthrough.

Expand Storage

vboxmanage list vms
"ii Fixed " {242b4fd4-71a8-4fbf-b8ae-924bcd2a9a4b}
"InfoServer" {819db113-6621-4485-b2df-92979dd68e0c}
"II & Data Stage & DataClient" {7afd2d0b-d381-4607-9d54-6a918ad90d62}
"EAI 9.02  & Data Stage & DataClient Clone" {71d322a6-0c8b-4fcc-a8af-da7d097ae558}
"RH_LVM_test" {01bcc3cd-341a-46dc-bf7f-23f6b1bf51a3}

I want to see the storage for RH_LVM_test.

vboxmanage showvminfo 01bcc3cd-341a-46dc-bf7f-23f6b1bf51a3    

Using grep of SATA I can see -

Storage Controller Name (1):            SATA
SATA (0, 0): /Users/tim/VirtualBox VMs/RH_LVM_test/RH_LVM_test.vdi (UUID: df54fba1-29df-4128-a564-44d50f70c0b4)

So simple resize

vboxmanage modifymedium  df54fba1-29df-4128-a564-44d50f70c0b4 --resize 10000

The following steps will allow you to resize your partition. In a terminal run the following commands in bold (you need root permissions to run fdisk):

df Take note of the logical volume mapping (ex. /dev/mapper/vg_lvm/lv_root)

fdisk -l

Take note of the filesystem partition of your physical volume sits (ex. /dev/sda2) fdisk /dev/sda

Run fdisk of this phyisical volume d Delete a partition 2 Select your partition (we are using 2 from /dev/sda2) n Create a new partition p Make it a primary partition 2 The partition number to make it on (same as we deleted) Set the starting block (keep the default as it is usually correct) Set the ending block (keep the default as it is fine for our use case) w Write the partition (will also exit fdisk shell)

reboot We must reboot in order to have the new partition table loaded pvresize /dev/sda2 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

Add Storage

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.

Boot Machine

We should now have our existing disk available - but the new drive is currently now used.

fdisk -l

Shows /dev/sdb and is 2.6 Gb is size.

fdisk /dev/sdb

o create new Partition Table

n New Partition

p Primary

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

 vgdisplay

Then

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

resize2fs /dev/mapper/vg_lvm-lv-root

Conclusion

Add New Disk is easy, expand existing disk is easy - but ONLY if you are using Logical Volumes.

I