LVM

From The Linux Source
Jump to: navigation, search

(all of these apply to both VM and physical systems)

Resizing Existing Mountpoints (adding more space)

1. if this is Enterprise 3 or older, umount partition (not needed under Ent 4 and newer)

# umount /home/arsystem

2. check free space available

# vgdisplay pri | grep "Free  PE"
Free  PE / Size       1413 / 44.16 GB

3. add desired space to partition

Ent 7
# lvextend -l +1413 -r /dev/pri/arsystem
OR
# lvextend -l +1413 /dev/pri/arsystem
# xfs_growfs /dev/pri/arsystem

Ent 5/6
# lvextend -l +1413 -r /dev/pri/arsystem
OR
# lvextend -l +1413 /dev/pri/arsystem
# resize2fs /dev/pri/arsystem

Ent 4 only (e2fsadm not avail on Ent 4);
# lvextend -l +1413 /dev/pri/arsystem
# ext2online /dev/pri/arsystem

Ent 3 only;
# e2fsadm -l +1413 /dev/pri/arsystem

Note: if you run this command and the fsck gives errors, fix the errors by running fsck manually, and then run the command again (it will not do it's resizing until fsck runs cleanly)

4. if this is Ent 3 or older, mount partition (not needed under Ent 4 and newer)

# mount /arsystem

Resizing Existing Mountpoints (reducing space)

1. if this is Ent 3 or older, umount partition (not needed under Ent 4 and newer)

# umount /home/arsystem

2. check free space available

# df -h | grep arsystem
/dev/mapper/pri-arsystem     199G   13M   198G  1% /home/arsystem

3. set desired space of partition

Ent 7
NOTE: if reducing xfs, backup your data, you have to recreate the filesystem, all will be lost!
# lvreduce -L 10G /dev/pri/arsystem
# mkfs -t xfs /dev/pri/arsystem

Ent 5/6
# lvreduce -L 10G /dev/pri/arsystem
# resize2fs /dev/pri/arsystem

Ent 4 only (e2fsadm not avail on Ent 4);
# lvreduce -L 10G /dev/pri/arsystem
# ext2online /dev/pri/arsystem

Ent 3 only;
# e2fsadm -L 10G /dev/pri/arsystem

Note: if you run this command and the fsck gives errors, fix the errors by running fsck manually, and then run the command again (it will not do it's resizing until fsck runs cleanly)

4. if this is Ent 3 or older, mount partition (not needed under Ent 4 and newer)

# mount /home/arsystem

Resizing SWAP

1. unmount swap (the one you want to resize - 'usually' there is only one)

# swapoff /dev/pri/swap

2. check free space, then add desired space to partition

# vgdisplay pri | grep "Free  PE"
Free  PE / Size       1413 / 44.16 GB
# lvextend -L +4g /dev/pri/swap

3. rebuild swap filesystem (there is no swap resize command)

# mkswap /dev/pri/swap

4. re-enable swap

# swapon /dev/pri/swap

5. verify using 'free' command that new size is in use

# free | grep Swap
Swap:      4192924          0    4192924

Adding Partitions (existing space available)

1. create new logical volume;

# lvcreate -L 8G -n arsystem pri
OR;
to use all of the remaining space, check "Free PE" from vgdisplay, then use -l option instead of -L, example;
# vgdisplay pri | grep "Free  PE"
Free  PE / Size       1413 / 44.16 GB
# lvcreate -l 1413 -n arsystem pri

2. create filesystem;

Ent 7
# mkfs -t xfs /dev/pri/arsystem
Ent 6
# mkfs -t ext4 /dev/pri/arsystem
Ent 5 or earlier
# mkfs -t ext3 /dev/pri/arsystem

3. make mountpoint;

# mkdir /home/arsystem

4. add to fstab;

# vi /etc/fstab

5. test fstab entry by mounting w/fstab info;

# mount /home/arsystem

Removing Partitions (for re-allocating/freeing up space)

1. umount partition

# umount /u001

2. remove LVM volume

# lvremove /dev/pri/u001

3. remove from fstab

# vi /etc/fstab

Snapshot Partitions

create a snapshot of an existing LVM partition

# lvcreate -L 1G -s -n remedyss /dev/pri/remedy

Note: this can now be mounted and used to back up this frozen copy of your filesystem. To remove when done, follow Removing Partitions (above)

Restore Snapshots

1. unmount the partition to make sure nothing else can write to it while restoring

# umount /dev/pri/remedy

2. merge the snapshot back into the original partition

# lvconvert --merge /dev/pri/remedyss

Adding New Drives (existing space NOT available)

(this step assumes you added a new drive, whether physical for a physical sys, or virtual for a virtual sys) 1. create a single partition as type LVM (8e) for the whole drive

# fdisk /dev/sdb

Note: if the new drive was added to a 'live' system, and it is not showing under 'fdisk -l', rescan with (may need to do this with more than host0, i.e. host0, host1, etc.):

echo "- - -" > /sys/class/scsi_host/host0/scan

2. initialize new drive as LVM

# pvcreate /dev/sdb1

3. add new drive to existing LVM volume

# vgextend pri /dev/sdb1
OR
# vgcreate sec /dev/sdb1

Renaming Volume Group & Logical Volume Names

  • Rename Logical Volume (partition name)*
# lvrename /dev/pri/HomeVol home

(make sure to update fstab with the change)

  • Rename Volume Group*
# vgrename VolGroup00 pri

(make sure to update fstab with the change)