Simple LVM Linux How-to
1. fdisk harddisk i.e.
# fdisk /dev/sdb
create at least 1 partition and gave label 8e (Linux LVM)
2. Create Physical Volume
# pvcreate /dev/sdb1
3. Create / Adding Volume Group
# vgcreate VolGroup01 /dev/sdb1
4. Activating new / deactivated Volume Group
# vgchange -a y VolGroup01
5. View Volume Group information
# vgdisplay
6. Deactivate a volume group
(Make sure that no logical volumes are present in the volume group, see later section for how to do this.)
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 26.97 GB
PE Size 32.00 MB
Total PE 863
Alloc PE / Size 269 / 8.41 GB
Free PE / Size 594 / 18.56 GB
I think those numbers should be 0 (zero)
# vgchange -a n VolGroup01
7. Remove a volume group (make sure you deactivated first)
# vgremove VolGroup01
8. Adding Physical Volume to (existing) Volume Group
# vgextend VolGroup00 /dev/sdb1
9. Display Physical Volume information
# pvdisplay
10. Removing Physical Volume
(If the physical volume is still used you will have to migrate the data to another physical volume using pvmove.)
Make sure the Physical Volume not used
Total PE 593
Free PE 593
Allocated PE 0
I think Allocated PE should be 0 and Total PE & Free PE numbers should be same.
# vgreduce VolGroup01 /dev/sdb1
11. Create Logical Volume
To create a 1500MB linear LV named 'testlv' and its block device special '/dev/testvg/testlv':
# lvcreate -L1500 -ntestlv testvg
To create a 100 LE large logical volume with 2 stripes and stripe size 4 KB.
# lvcreate -i2 -I4 -l100 -nanothertestlv testvg
If you want to create an LV that uses the entire VG, use vgdisplay to find the "Total PE" size, then use that when running lvcreate.
# vgdisplay testvg | grep "Total PE"
Total PE 10230
# lvcreate -l 10230 testvg -n mylv
This will create an LV called mylv filling the testvg VG.
If you want the logical volume to be allocated from a specific physical volume in the volume group, specify the PV or PVs at the end of the lvcreate command line.
# lvcreate -L 1500 -ntestlv testvg /dev/sdg
Create Logical Volume named LogVol02 with capacity 20% of total VolGroup00 from /dev/sdb1
# lvcreate -l20%VG -nLogVol02 VolGroup00 /dev/sdb1
12. View Logical Volume information
# lvdisplay
13. Using a logical volume
Format it first
# mkfs.ext3 /dev/VolGroup00/LogVol02
Create a mount folder (if needed) & mount it
# mkdir /mnt/data
# mount /dev/VolGroup00/LogVol02 /mnt/data
You can it to your /etc/fstab for automatic mounting
14. Removing a logical volume
A logical volume must be closed before it can be removed:
(un-mount it if mounted)
# umount /dev/myvg/homevol
# lvremove /dev/myvg/homevol
lvremove -- do you really want to remove "/dev/myvg/homevol"? [y/n]: y
lvremove -- doing automatic backup of volume group "myvg"
lvremove -- logical volume "/dev/myvg/homevol" successfully removed
15. Extending a logical volume
To extend a logical volume you simply tell the lvextend command how much you want to increase the size. You can specify how much to grow the volume, or how large you want it to grow to:
# lvextend -L12G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
will extend /dev/myvg/homevol to 12 Gigabytes.
# lvextend -L+1G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 13 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
Resize the filesystem
# umount /dev/myvg/homevol/dev/myvg/homevol
# resize2fs /dev/myvg/homevol
# mount /dev/myvg/homevol /home
16. Reducing a logical volume
# umount /home
# resize2fs /dev/myvg/homevol 524288
# lvreduce -L-1G /dev/myvg/homevol
# mount /home
Source: http://tldp.org/HOWTO/LVM-HOWTO/
LVM command list: http://linux.web.cern.ch/linux/scientific4/docs/rhel-sag-en-4/s1-disk-stora
ge-lvm.html
1. fdisk harddisk i.e.
# fdisk /dev/sdb
create at least 1 partition and gave label 8e (Linux LVM)
2. Create Physical Volume
# pvcreate /dev/sdb1
3. Create / Adding Volume Group
# vgcreate VolGroup01 /dev/sdb1
4. Activating new / deactivated Volume Group
# vgchange -a y VolGroup01
5. View Volume Group information
# vgdisplay
6. Deactivate a volume group
(Make sure that no logical volumes are present in the volume group, see later section for how to do this.)
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 26.97 GB
PE Size 32.00 MB
Total PE 863
Alloc PE / Size 269 / 8.41 GB
Free PE / Size 594 / 18.56 GB
I think those numbers should be 0 (zero)
# vgchange -a n VolGroup01
7. Remove a volume group (make sure you deactivated first)
# vgremove VolGroup01
8. Adding Physical Volume to (existing) Volume Group
# vgextend VolGroup00 /dev/sdb1
9. Display Physical Volume information
# pvdisplay
10. Removing Physical Volume
(If the physical volume is still used you will have to migrate the data to another physical volume using pvmove.)
Make sure the Physical Volume not used
Total PE 593
Free PE 593
Allocated PE 0
I think Allocated PE should be 0 and Total PE & Free PE numbers should be same.
# vgreduce VolGroup01 /dev/sdb1
11. Create Logical Volume
To create a 1500MB linear LV named 'testlv' and its block device special '/dev/testvg/testlv':
# lvcreate -L1500 -ntestlv testvg
To create a 100 LE large logical volume with 2 stripes and stripe size 4 KB.
# lvcreate -i2 -I4 -l100 -nanothertestlv testvg
If you want to create an LV that uses the entire VG, use vgdisplay to find the "Total PE" size, then use that when running lvcreate.
# vgdisplay testvg | grep "Total PE"
Total PE 10230
# lvcreate -l 10230 testvg -n mylv
This will create an LV called mylv filling the testvg VG.
If you want the logical volume to be allocated from a specific physical volume in the volume group, specify the PV or PVs at the end of the lvcreate command line.
# lvcreate -L 1500 -ntestlv testvg /dev/sdg
Create Logical Volume named LogVol02 with capacity 20% of total VolGroup00 from /dev/sdb1
# lvcreate -l20%VG -nLogVol02 VolGroup00 /dev/sdb1
12. View Logical Volume information
# lvdisplay
13. Using a logical volume
Format it first
# mkfs.ext3 /dev/VolGroup00/LogVol02
Create a mount folder (if needed) & mount it
# mkdir /mnt/data
# mount /dev/VolGroup00/LogVol02 /mnt/data
You can it to your /etc/fstab for automatic mounting
14. Removing a logical volume
A logical volume must be closed before it can be removed:
(un-mount it if mounted)
# umount /dev/myvg/homevol
# lvremove /dev/myvg/homevol
lvremove -- do you really want to remove "/dev/myvg/homevol"? [y/n]: y
lvremove -- doing automatic backup of volume group "myvg"
lvremove -- logical volume "/dev/myvg/homevol" successfully removed
15. Extending a logical volume
To extend a logical volume you simply tell the lvextend command how much you want to increase the size. You can specify how much to grow the volume, or how large you want it to grow to:
# lvextend -L12G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
will extend /dev/myvg/homevol to 12 Gigabytes.
# lvextend -L+1G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 13 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
Resize the filesystem
# umount /dev/myvg/homevol/dev/myvg/homevol
# resize2fs /dev/myvg/homevol
# mount /dev/myvg/homevol /home
16. Reducing a logical volume
# umount /home
# resize2fs /dev/myvg/homevol 524288
# lvreduce -L-1G /dev/myvg/homevol
# mount /home
Source: http://tldp.org/HOWTO/LVM-HOWTO/
LVM command list: http://linux.web.cern.ch/linux/scientific4/docs/rhel-sag-en-4/s1-disk-stora
ge-lvm.html
