RHEL7: Extend existing unencrypted logical volumes.

Share this link

Note: This is an RHCSA 7 exam objective.

Prerequisites

This tutorial requires 200MB of available space.

Before extending any unencrypted logical volume, let’s create one of 100MB called lv_vol in the vg volume group:

# lvcreate --size 100M --name lv_vol vg

Only unencrypted Ext4 and XFS file systems can be extended, not vfat.

Note: In this tutorial, the lvextend and lvreduce commands are used to respectively increase and decrease the size of a logical volume. For brevity’s sake, the lvresize command is not discussed here, but the same operations can be done in a slightly different way with this command (see comments).

Ext4 logical volume extension

To create an ext4 file system on the previously created logical volume, type:

# mkfs.ext4 /dev/vg/lv_vol
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Optionally, mount the new file system on /mnt:

# mount /dev/vg/lv_vol /mnt

To allocate all the space available in the volume group to an unencrypted Ext4-formatted logical volume (here /dev/vg/lv_vol), type:

# lvextend -l +100%FREE -r /dev/vg/lv_vol

Note: The file system is automatically extended (-r) without any need to unmount it.

To extend the size of an unencrypted Ext4-formatted logical volume (here /dev/vg/lv_vol) by 50MB, type:

# lvextend --size +50M -r /dev/vg/lv_vol
  Rounding size to boundary between physical extents: 52.00 MiB
  Extending logical volume lv_vol to 152.00 MiB
  Logical volume lv_vol successfully resized
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg-lv_vol is mounted on /mnt; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/mapper/vg-lv_vol is now 155648 blocks long.

Although there is no reason to do so, you can still do it in two steps:

# lvextend --size +50M /dev/vg/lv_vol
  Rounding size to boundary between physical extents: 52.00 MiB
  Extending logical volume lv_vol to 152.00 MiB
  Logical volume lv_vol successfully resized
# resize2fs /dev/vg/lv_vol
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg/lv_vol is mounted on /mnt; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/vg/lv_vol is now 155648 blocks long.

Ext4 logical volume reduction

Conversely, to reduce the size of a logical volume (here by 50MB), you have to follow these steps:
Unmount the file system (here /dev/vg/lv_vol):

# umount /dev/vg/lv_vol

Reduce the size of the logical volume (here /dev/vg/lv_vol) and the associated file system at the same time (-r):

# lvreduce --size -50M -r /dev/vg/lv_vol
  Rounding size to boundary between physical extents: 48.00 MiB
fsck from util-linux 2.23.2
/dev/mapper/vg-lv_vol: 11/37544 files (9.1% non-contiguous), 10390/155648 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vg-lv_vol to 106496 (1k) blocks.
The filesystem on /dev/mapper/vg-lv_vol is now 106496 blocks long.

  Reducing logical volume lv_vol to 104.00 MiB
  Logical volume lv_vol successfully resized

Mount the file system (here /dev/vg/lv_vol):

# mount /dev/vg/lv_vol /mnt

XFS logical volume extension

To create a XFS file system on the previously created logical volume called lv_vol (see prerequisites), type:

# mkfs.xfs /dev/vg/lv_vol
meta-data=/dev/vg/lv_vol isize=256 agcount=4, agsize=6400 blks
         = sectsz=512 attr=2, projid32bit=1
         = crc=0
data     = bsize=4096 blocks=25600, imaxpct=25
         = sunit=0 swidth=0 blks
naming   =version 2 bsize=4096 ascii-ci=0 ftype=0
log      =internal log bsize=4096 blocks=853, version=2
         = sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

Mount the new file system on /mnt:

# mount /dev/vg/lv_vol /mnt

To extend the size of an unencrypted XFS-formatted logical volume (here /dev/vg/lv_vol) by 50MB, type:

# lvextend --size +50M -r /dev/vg/lv_vol
  Rounding size to boundary between physical extents: 52.00 MiB
  Extending logical volume lv_vol to 152.00 MiB
  Logical volume lv_vol successfully resized
meta-data=/dev/mapper/vg-lv_vol isize=256    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 25600 to 38912

Note1: The file system is automatically extended (-r) without any need to unmount it.
Note2: You can’t reduce a XFS file system even though you unmount it. You have to back it up (with tar or another tool), drop it and recreate it.

Although there is no reason to do so, you can still do it in two steps:

# lvextend --size +50M /dev/vg/lv_vol
  Rounding size to boundary between physical extents: 52.00 MiB
  Extending logical volume lv_vol to 152.00 MiB
  Logical volume lv_vol successfully resized
# xfs_growfs /mnt
meta-data=/dev/mapper/vg-lv_vol isize=256    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 25600 to 38912

Note: The xfs_growfs command accepts only a mounted XFS filesystem as parameter.

Additional Resources

Although outside of the RHCSA objectives, TheGeekDiary website offers an interesting tutorial about shrinking the LVM root file system.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Leave a Reply

4 Comments on "RHEL7: Extend existing unencrypted logical volumes."

Notify of
Sort by:   newest | oldest
hunter86_bg
Member
You can alternatively use “lvresize” command. Ex: “lvresize -L 10G -r /dev/vg/lv_vol” Explanation: -L option – sets volume to fixed 10 GB (using smaller “g” will assume GiB) -r = resizing file system automatically ( replaces “e2fsck” and “resize2fs”/”xfs_growfs”) which can speed things up NB: before mounting a resized logical volume without “-r” option, ALWAYS resize the file system. Example : shrinking the log. volume – first reduce the file system to the needed size by : “e2fsck /” “resize2fs / ” Then resize the volume via “lvreduce”/”lvresize”. When extending the log. volume – first “lvextend”/”lvresize” and then “e2fsck” +… Read more »
Ahmad
Member
Ahmad

Hi

In extending xfs, I think you shoud use the below command:
# lvextend –size +50M /dev/vg/lv_vol
# xfs_growfs /dev/vg/lv_vol

and not:

# lvextend –size +50M /dev/vg/lv_vol
# xfs_growfs /mnt

Please correct me if I’m wrong?

I have another question: when I tried to extend the xfs, I receive the below error:
# lvextend -L 16M /dev/datacontainer10/datacopy10
New size given (1 extents) not larger than existing size (50 extents)
Run `lvextend –help’ for more information.

Can you please advise what is wrong?
P.S: extent is 50, and PE size is 16

wpDiscuz

RHCSA7: Task of the day

Allowed time: 10 minutes.
Archive and compress the content of the /opt directory (create files if none exists).
Uncompress and unarchive the resulting file in /root

RHCE7: Task of the day

Allowed time: 10 minutes.
Set up a NFS server that exports the /opt directory in read-only mode.

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...