Resize LVM

Creating a new Logical Volume

In this example we will create a new logical volume called wworks, mounted at /wworks which will be part of the vg00 Volume Group at /dev/mapper/vg00-lv_wworks

1. Check to see how much free space you have to allocate the new logical volume:

[root@gi-rgs-rng01 /]# vgdisplay | egrep 'Name|Free'
  VG Name               vg00
  Free  PE / Size       2515 / 78.59 GB

2. Create the new logical volume and assign it to the vg00 volume group:

[root@gi-rgs-rng01 /]# lvcreate -L 30G -n lv_wworks vg00
  Logical volume "lv_wworks" created

3. Format it with a journalled filesystem:

mkfs.ext3 -j /dev/mapper/vg00-lv_wworks

4. Add the new entry to fstab (use the others as a template):

[root@gi-rgs-rng01 /]# cat /etc/fstab | grep wworks
/dev/vg00/lv_wworks     /wwworks                ext3    defaults        1 2

5. Mount the new logical volume and test it:

[root@gi-rgs-rng01 /]# mount -a && df -h | egrep 'File|wworks' && echo "test">/wworks/neil.test && cat /wworks/neil.test
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-lv_wworks
                     30G   76M   28G   1% /wworks
test

6. You can also see it as a member of the vg00 Volume Group:

[root@gi-rgs-rng01 /]# lvs
LV        VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
lv_home   vg00 -wi-ao 10.00G
lv_log    vg00 -wi-ao 10.00G
lv_root   vg00 -wi-ao 15.00G
lv_swap   vg00 -wi-ao  5.88G
lv_tmp    vg00 -wi-ao  2.00G
lv_var    vg00 -wi-ao 15.00G
lv_wworks vg00 -wi-ao 30.00G

Reducing the size of an LVM

In this example we will reduce the size of /var/log which is an LV at /dev/mapper/vg00-lv_log

[root@gi-rgs-rng01 /]# df -h | egrep 'Filesystem|log'
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-lv_log
                     50G   85M   47G   1% /var/log

1. Ensure the filesystem is unmounted

$ umount /var/log

2. If the mount point is in use try identifying what's using it with lsof:

$ lsof | grep "/var/log"

3. Ensure /var/log is no longer mounted.

$ df -h | grep "/var/log"

Ensure the amount of data contained within the LV does not exceed the size you will be reducing it to or this will result in data loss.

4. First the filesystem needs to be checked.

[root@gi-rgs-rng01 /]# e2fsck -f /dev/mapper/vg00-lv_log
e2fsck 1.35 (28-Feb-2004)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg00-lv_log: 56/6553600 files (19.6% non-contiguous), 227290/13107200 blocks

5. Now reduce the filesystem to 10GB.

[root@gi-rgs-rng01 /]# resize2fs /dev/mapper/vg00-lv_log 10G
resize2fs 1.35 (28-Feb-2004)
Resizing the filesystem on /dev/mapper/vg00-lv_log to 2621440 (4k) blocks.
The filesystem on /dev/mapper/vg00-lv_log is now 2621440 blocks long.

6. Now reduce the size of the LV:

[root@gi-rgs-rng01 /]# lvreduce -L 10G /dev/mapper/vg00-lv_log
  WARNING: Reducing active logical volume to 10.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_log? [y/n]: y
  Reducing logical volume lv_log to 10.00 GB
  Logical volume lv_log successfully resized

7. Remount the partition and check the new size is correct:

[root@gi-rgs-rng01 /]# mount -a ; df -h | egrep 'Filesystem|log'
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-lv_log
                    9.9G   69M  9.3G   1% /var/log
                    
                    

Extending the size of a Logical Volume

In this example we will extend the size of /wworks which is an LV at /dev/mapper/vg00-lv_wworks, to 50GB.

1. Ensure the filesystem is unmounted

$ umount /wworks

2. If the mount point is in use try identifying what's using it with lsof:

$ lsof | grep "/wworks"

3. Ensure /var/log is no longer mounted.

$ df -h | grep "/wworks"

4. Extend the size of the logical volume:

$ lvextend -L 50GB /dev/mapper/vg00-lv_wworks

5. Now extend the filesystem to that new size

$ resizefs /dev/mapper/vg00-lv_wworks 50G

6. Remount the partition and check the new size is correct:

$ mount -a ; df -h | egrep 'Filesystem|wworks'
 
linux/linux-resize-lvm.txt · Last modified: 09/01/2021 23:28 by andrew