Nethence Newdoc Olddoc Lab Your IP BBDock  

Warning: those guides are mostly obsolete, please have a look at the new documentation.


LVM2 usage and administration
Note. on Slackware and Redhat
Exclude CDrom from LVM,
cd /etc/lvm/
cp lvm.conf lvm.conf.dist
vi lvm.conf
change the filter directive to,
filter = [ "r|/dev/cdrom|" ]
Note. Fo SAN and multipathing, you might also want to exclude sd* and let LVM handle only dm-0.
Create PV/VG/LV/filesystem
Note. If you are using a partition instead of the whole harddrive for the physical volume, make sure it has type,
8e Linux LVM
Create a physical volume, a volume group and a logical volume,
pvcreate /dev/sdb
vgcreate vgdata /dev/sdb
vgdisplay | grep Free
lvcreate -l FREE_PE -n data vgdata
mkfs.ext4 /dev/vgdata/data
Add PV & extend VG/LV/filesystem
Proceed like e.g.,
pvcreate /dev/...
vgextend vgdata /dev/...
vgdisplay | grep Free
lvextend -l +FREE_PE /dev/vgdata/data
resize2fs /dev/vgdata/data
Note. filesystem extention may be be performed on-line (ext4)
Display physical volumes, volume groups and logical volumes,
#vgdisplay -v
vgs -l
Hot-grow the size of the root file system with no reboot
Make sure it's an ext3, ext4 or XFS file system first,
mount | grep 'on / '
On the same boot disk
If possible, hot-grow the vdisk size (see if the VM infrastructure you are using allows you do do that on that vdisk) and rescan,
ls -l /sys/class/scsi_device/
for device in `ls -1 /sys/class/scsi_device/`; do echo 1 > "/sys/class/scsi_device/$device/device/rescan"; echo $device; sleep 1; done
then add a "Linux LVM" partition (change sda3 partition number accordingly),
fdisk /dev/sda
nevermind the warning,
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
and rescan partitions with,
partprobe -s
#partx -v -a /dev/sda
and make it join the vg,
pvcreate /dev/sda3 
vgextend vg_rhel6vm1 /dev/sda3 
On a additional disk
If you cannot, add a vdisk and rescan,
ls -l /sys/class/scsi_host/
echo "- - -" > /sys/class/scsi_host/host0/scan
and make it join the vg,
pvcreate /dev/sdb
vgextend vg_rhel6vm1 /dev/sdb
Growing the LV and the filesystem (-r)
then extend the lv and grow the ext4 filesystem,
vgdisplay vg_rhel6vm1 | grep Free
lvextend -l +2559 /dev/vg_rhel6vm1/lv_root
#lvextend -r -l +2559 /dev/vg_rhel6vm1/lv_root
Growing the fs seperately
For ext3/ext4,
df -h
resize2fs /dev/vg_rhel6vm1/lv_root
For XFS,
xfs_growfs /dev/mapper/vg_rhel7-lv_root
Refs about vdisk.
Increase A VMware Disk Size (VMDK) Formatted As Linux LVM without rebooting:
Howto extend LVM on VMWare Guest running Linux:
Can I increase the size of a Linux VM's .vmdk disk without a reboot?:
Refs. about xfs.
Reduce the size of a filesystem and logical volume
Update, just use the lvreduce -r feature to do both at once.
First, reduce the filesystem size,
fsck -f /dev/mapper/vg_data-lv_data
...144315055/199750656 blocks
#lvreduce -r -L 650G /dev/vg_data/lv_data
resize2fs /dev/mapper/vg_data-lv_data 650G
...170393600 (4k) blocks.
Then reduce the LV size,
echo $((199750656 * 4096))
lvdisplay --units B /dev/vg_data/lv_data
lvreduce -L 650G /dev/vg_data/lv_data
echo $((170393600 * 4096))
lvdisplay --units B /dev/vg_data/lv_data
Using LVM2 pvmove to relocate extents from a physical volume to another one
This should work on any GNU/Linux that has LVM version 2. As for on-line resizing, you should have an ext3 file system, at least (grow only, not shrink). In this example I've got two drives, a 3TB (/dev/sdb) and a 2TB (/dev/sdc) hard disk. The 3TB is free to be erased and will be used as a new physical volume. The 2TB drive has a Linux LVM DOS partition on it hence an LVM physical volume on /dev/sdc1. I need to move the vgdata volume group that it contains, to the larger 3TB disk. In brief, I need to move the physical extents from /dev/sdc1 to /dev/sdb.
Move the extents to the new and larger disk
Create the new physical volume and add it to the volume group,
pvcreate /dev/sdb
vgextend vgdata /dev/sdb
you can now proceed with 'pvmove',
pvmove -v -i 5 /dev/sdc1 /dev/sdb
Note. With the "-v -i 5" command arguments, prmove prints some information at the beginning and one line to print the percentage every 5 seconds.
Note. pvmove reduces the size of the volume group on sdc and increases it on sdb.
Note. Once a pvmove is initiated, you can stop (^C) and get back to the process simply by typing (other command line arguments will be ignored anyway),
Ok, all done? Then remove /dev/sdc from the volume group,
vgreduce vgdata /dev/sdc
#or vgreduce --all vgdata
now check the physical volumes again,
eventually wipe-out the physical volume from the relying disk,
pvremove /dev/sdc1
Extend the logical volume and check again,
lvextend --extents +100%FREE /dev/vgdata/lvdata
now extend the file system that's on it (on-line resizing for growing works for ext3 and ext4 at least),
df -h
fsadm -l resize /dev/vgdata/lvdata
note. The -l option seems to be required for a logical volume, eventhough it's already resized.

(obsolete, see the new doc)