Tag Archives: resize

LVM and RAID guide

http://www.davelachapelle.ca/guides/ubuntu-lvm-guide/

Installing necessary tools:

apt-get install lvm2 dmsetup mdadm reiserfsprogs xfsprogs

Raid Setup:

Please refer to some of my other guides regarding setting up various raid levels. You can, and I would highly recommend, setting up your drives in a raid configruation prior to adding them to a logical volume. By doing so, you’ll have properly redundant drives to keep all of your precious data safe.

To remove the raid super block:
mdadm --zero-superblock /dev/vdb

Create RAID1 array:
mdadm -v --create /dev/md0 --level=raid1 --raid-devices=2 /dev/sdx1 /dev/sdy1
OR
mdadm -v --create /dev/md1 --level=raid10 --raid-devices=4 /dev/sdr1 /dev/sds1 /dev/sdt1 /dev/sdu1

This will take some time, which cat /proc/mdstat will tell you.

LVM Layout

Very basically an LVM consists of multiple drives, which make up a “Volume Group”. This Volume Group, can then be divided up into Logical Volumes, and expanded / contracted at will. Any Logical Volume can be larger than the physical size of any one disk, but the total size of all Logical Volumes, obviously, cannot exceed the total space your disks afford you.

Create GPT partition for LVM using parted tool:

Traditional MBR(MSDOS) disk label has limitation of 2^32 (2TiB) in capacity and 15 in partition numbers(including logical partitions), while GUID Partition Table (GPT) supports 2^64 KiB (2 ZiB) and 128 partitions by default.

Lets start by determining what disks are attached to our system:

fdisk -l

LVM Setup

Create LVM Group and Volumes:

Now we’ll put a LVM group and volumes on /dev/md1. I use vg- for volume group names and lv_ for the logical volumes in the volume groups. Using descriptive names, like lv_home, will save your sanity later when you’re creating filesystems and mountpoints. The -L option specifies the size of the volume:

pvcreate /dev/md1
vgcreate vg_server1 /dev/md1
lvcreate -L4g -nlv_home vg_server1
lvcreate -L2g -nlv_var vg_server1
lvcreate -L1g -nlv_tmp vg_server1

This creates a new partition assigned the whole drive capacity.

parted /dev/vg_server1/lv_home mklabel gpt (or msdos)
parted /dev/vg_server1/lv_home mkpart primary ext4 1 -1

You can use pvdisplay, vgdisplay and lvdisplay to see the fruits of your labors. Use vgdisplay to see how much space is left.

Create file system:

mkfs -t ext4 /dev/vg_server1/lv_home

Check disk free space:

df -h /dev/mapper/vg_server1-lv_home

Resize LVM root partition:

lvextend -L+1G /dev/mapper/vg1-lvRoot
resize2fs /dev/mapper/vg1-lvRoot

Expanding (virtual machine) partition

1) Resize virtual disk in VMware vSphere.
2) Boot GParted CD, resize extended partition, deactivate LV, resize LV, activate LV.
3) From GParted terminal extend LV: lvextend -L +12G /dev/vg01/root
4) From GParted terminal resize file system: resize2fs /dev/vg01/root

Detail on the fly resize guide you can find here:
http://theducks.org/2009/11/expanding-lvm-partitions-in-vmware-on-the-fly/