Some LVM Notes

A few LVM notes to jog the brain

A. Steps to create the logical volume..

List the current physical volumes. In this instance, were interested in a blank 20GB SATA – /dev/sdb. You can extend a logical volume by adding additional phyical volumes later.

fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b5a0f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 248832 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 32 2611 20719617 5 Extended
/dev/sda5 32 2611 20719616 8e Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Format the entire disk as an LVM partition
fdisk /dev/sdb
n – new partition
p – primary
1 – partition number
Enter – First cylinder
Enter – last cylinder
t – change type
1 – our partition
8e – LVM
w – write

Do the same for any additional disks to be added to the volume group

Prepare the new partitions(s) for LVM:
pvcreate /dev/sdb1

Display the new physical volume:
pvdisplay

“/dev/sdb1″ is a new physical volume of “19.99 GiB”
— NEW Physical volume —
PV Name /dev/sdb1
VG Name
PV Size 19.99 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 8dPHo4-Rztw-hOLJ-KW9M-hfjj-XwUJ-g3vyUr

Create a Volume Group
vgcreate wwwfiles /dev/sdb1

Display your Volume Group
vgscan
or
vgdisplay
— Volume group —
VG Name wwwfiles
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.99 GiB
PE Size 4.00 MiB
Total PE 5118
Alloc PE / Size 0 / 0
Free PE / Size 5118 / 19.99 GiB
VG UUID w6sdJY-9ehv-8XVE-7azw-WIQz-s9yD-XYyspc

Create a Logical Volume or two in the Group
lvcreate --name site1 --size 4G wwwfiles
lvcreate --name site2 --size 4G wwwfiles

Display the Logical Volumes
lvscan
or
lvdisplay
— Logical volume —
LV Name /dev/wwwfiles/site1
VG Name wwwfiles
LV UUID Lh2yxC-GjpH-RRzC-LG6r-m5h5-zK7A-7lvkYE
LV Write Access read/write
LV Status available
# open 0
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 251:3

— Logical volume —
LV Name /dev/wwwfiles/site2
VG Name wwwfiles
LV UUID KVfvbZ-ok5E-IINJ-mjAq-DSoj-7NrS-ojtADK
LV Write Access read/write
LV Status available
# open 0
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 251:4

We now need to add a filesystem to the Logical Volume:
mkfs.ext3 /dev/wwwfiles/site1

The Logical Volumes can now be mounted onto the system:
mkdir /var/www/site1
mount /dev/wwwfiles/site1 /var/www/site1

check df -h to make sure successful

To make the mount persistent, add a line to /etc/fstab:
/dev/wwwfiles/site1 /var/www/site1 ext3 rw,noatime 0 0

B. Enlarge a Logical Volume & filesystem

Unmount it:
umount /var/www/site1

Enlarge the Logical Volume:
lvextend -L5G /dev/wwwfiles/site1

Check the filesystem:
e2fsck -f /dev/wwwfiles/site1

Resize the filesystem:
resize2fs /dev/wwwfiles/site1

Remount & check successful:
mount /dev/wwwfiles/site1 /var/www/site1
df -h

C. Shrink a Logical Volume & filesystem

Unmount it:
umount /var/www/site1

Check the filesystem. Resizing is specified in blocks, so we need to calculate from this result, how many blocks to give it:
e2fsck -f /dev/wwwfiles/site1

Resize the filesystem:
resize2fs /dev/wwwfiles/site1 1048576

Shrink the Logical Volume:
lvreduce -L4G /dev/wwwfiles/site1

Remount:
mount /dev/wwwfiles/site1 /var/www/site1
check df -h to make sure successful

D. Adding another hard disk

Format the entire disk as an LVM partition:
fdisk /dev/sdc
n – new partition
p – primary
1 – partition number
Enter – First cylinder
Enter – last cylinder
t – change type
1 – our partition
8e – LVM
w – write

Prepare the new partitions(s) for LVM:
pvcreate /dev/sdc1

Add /dev/scc1 to our Volume Group:
vgextend wwwfiles /dev/sdc1

Check for the additional space with vgdisplay

E. Remove a disk

Move data off the disk to be removed:
pvmove /dev/sdb1 /dev/sdf1

Remove /dev/sdb1 from the Volume Group:
vgreduce wwwfiles /dev/sdb1

Verify with vgdisplay

Remove the Physical Volume:
pvremove /dev/sdb1

Verify with pvdisplay

*notes*

lvextend can be called in several ways
-L12G = sets to 12GB
-L+2G = adds an additional 2GB
-L+100%FREE = adds all of the remaining free space in the Volume Group

Enlarge a Logical Volume
lvextend -L5G /dev/wwwfiles/site1

Reduce a Logical Volume
lvreduce -L2G /dev/wwwfiles/site1

Delete a Logical Volume
lvremove /dev/wwwfiles/site1

Rename a Logical Volume
lvrename site1 site3

Delete a Volume Group
vgremove wwwfiles

Rename a Volume Group
vgrename wwwfiles files

Remove a physical volume
pvremove /dev/sdb1

You can leave a response, or trackback from your own site.

Leave a Reply