<<

Logical Volumes

Linux Logical Volumes

Create partitions for each physical volume ()

fdisk /dev/hde type = 8e

Create partitions for each physical volume (parted) - http://www.fistagon.us/wp/2010/06/12/warning-the-resulting-partition-is-not-properly-aligned- for-best-performance/  http://eatingsecurity.blogspot.com/2008/03/using-parted-and-lvm2-for-large.html

(parted) mklabel gpt Warning: The existing disk on /dev/sdf will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Yes

(parted) print Model: ATA WDC WD2500JB-98G (scsi) Disk /dev/sdf: 250GB Sector size (logical/physical): 512B/512B Partition Table: gpt

Number Start End Size Name Flags

(parted) mkpart primary 0 250G Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? C

(parted) mkpart primary 1 250G

(parted) print Model: ATA WDC WD2500JB-98G (scsi) Disk /dev/sdf: 250GB Sector size (logical/physical): 512B/512B Partition Table: gpt

Number Start End Size File system Name Flags 1 1049kB 250GB 250GB primary

(parted) quit Information: You may need to update /etc/fstab.

Designate physical volumes pvcreate /dev/hde1 /dev/hdf1 /dev/hdg1

Create Volume Group named vg0 vgcreate vg0 /dev/hde1 /dev/hdf1 /dev/hdg1

Create Logical Volume named lv0 If using entire Volume Group as Logical Volume, determine total size 1. vgdisplay vg0 | grep "Total PE" Total PE 178854

create lvcreate -l 178854 vg0 -n lv0

Create filesystem mkfs -t /dev/mapper/vg0-lv0

Mount -t ext3 /dev/mapper/vg0-lv0 /www

add to /etc/fstab /dev/mapper/vg0-lv0 /www ext3 defaults 1 2

Adding a physical volume, then extending the logical volume fdisk /dev/sdb pvcreate /dev/sdb1

Physical volume "/dev/sdb1" successfully created vgextend vg0 /dev/sdb1

Volume group "vg0" successfully extended vgdisplay vg0 | grep "Total PE"

Total PE 953870 lvextend -l 953870 /dev/vg0/lv0

Extending logical volume lv0 to 3.64 TB Logical volume lv0 successfully resized resize2fs /dev/vg0/lv0 (may need to do fsck first)

Live extend fs ( ext3 only )

ext2online /dev/vg0/lv0

References:

http://tldp.org/HOWTO/LVM-HOWTO/ http://www.redhat.com/docs/manuals/csgfs/browse/4.6/Cluster_Logical_Volume_Manager/index.html

http://linuxlah.blogspot.com/2006/05/howto-extend-lvm-partition-at-rhel4.html

Shrinking from one logical volume and adding to others.

1. shrinking /mnt/free - note any data on this filesystem is likely to be lost, move and/or backup if its important.

# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg0-lv_root 20G 3.7G 15G 20% / /dev/mapper/vg0-lv_free 64G 180M 61G 1% /mnt/free /dev/mapper/vg0-lv_tmp 20G 173M 19G 1% /tmp /dev/mapper/vg0-lv_global 97G 23G 70G 25% /usr/global /dev/mapper/vg0-lv_var 9.7G 288M 9.0G 4% /var /dev/md0 494M 25M 444M 6% /boot tmpfs 16G 0 16G 0% /dev/shm

# lvreduce -L 10240 vg0/lv_free WARNING: Reducing active logical volume to 10.00 GB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv_free? [y/n]: y Reducing logical volume lv_free to 10.00 GB Logical volume lv_free successfully resized

Note the above has a mistake, it should be -10240 to reduce the size by 10GB instead it reduce the size to 10 GB

Now add 10 GB to /tmp then expand the filesystem [root@newbach ~]# lvextend -L +10240 vg0/lv_tmp Extending logical volume lv_tmp to 30.00 GB Logical volume lv_tmp successfully resized # resize2fs /dev/mapper/vg0-lv_tmp resize2fs 1.39 (29-May-2006) Filesystem at /dev/mapper/vg0-lv_tmp is mounted on /tmp; on-line resizing required Performing an on-line resize of /dev/mapper/vg0-lv_tmp to 7864320 (4k) blocks. The filesystem on /dev/mapper/vg0-lv_tmp is now 7864320 blocks long.

Here is where I found the mistake, I tried repeating the above proceedure:

# lvreduce -L 10240 vg0/lv_free New size (320 extents) matches existing size (320 extents) Run `lvreduce --help' for more information.

# lvextend -L +10240 vg0/lv_var Extending logical volume lv_var to 20.00 GB Logical volume lv_var successfully resized

# resize2fs /dev/mapper/vg0-lv_var resize2fs 1.39 (29-May-2006) Filesystem at /dev/mapper/vg0-lv_var is mounted on /var; on-line resizing required Performing an on-line resize of /dev/mapper/vg0-lv_var to 5242880 (4k) blocks. The filesystem on /dev/mapper/vg0-lv_var is now 5242880 blocks long.

Now correct the mistake, how do I determine what is available to add back to /mnt/free

# vgdisplay vg0 --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 9 VG Access read/write VG Status resizable MAX LV 0 Cur LV 5 Open LV 4 Max PV 0 Cur PV 1 Act PV 1 VG Size 215.66 GB PE Size 32.00 MB Total PE 6901 Alloc PE / Size 5760 / 180.00 GB Free PE / Size 1141 / 35.66 GB VG UUID V6axye-E5Mp-3bgV-fLL0-Jvt0-p0ad-wYhZR1

# lvextend -l 1141 /dev/vg0/lv_free Extending logical volume lv_free to 35.66 GB Logical volume lv_free successfully resized

# resize2fs /dev/vg0/lv_free resize2fs 1.39 (29-May-2006) Please run 'e2fsck -f /dev/vg0/lv_free' first.

# e2fsck -f /dev/vg0/lv_free e2fsck 1.39 (29-May-2006) The filesystem size (according to the superblock) is 17211392 blocks The physical size of the device is 9347072 blocks Either the superblock or the partition table is likely to be corrupt! Abort? yes # mkfs -t ext3 /dev/vg0/lv_free mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Block size=4096 (log=2) Fragment size=4096 (log=2) 4676672 inodes, 9347072 blocks 467353 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 286 block groups 32768 blocks per group, 32768 fragments per group 16352 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624

Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. # mount /mnt/free

# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg0-lv_root 20G 3.7G 15G 20% / /dev/mapper/vg0-lv_tmp 30G 173M 28G 1% /tmp /dev/mapper/vg0-lv_global 97G 23G 70G 25% /usr/global /dev/mapper/vg0-lv_var 20G 293M 19G 2% /var /dev/md0 494M 25M 444M 6% /boot tmpfs 16G 0 16G 0% /dev/shm /dev/mapper/vg0-lv_free 36G 177M 34G 1% /mnt/free