RHEL7: Extend existing unencrypted logical volumes.

Share this link

Note: This is an RHCSA 7 exam objective.

Prerequisites

This tutorial requires 200MB of available disk 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.

Note1: 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).
Note2: With RHEL 7.3, the NetworkManager service got two new directives in its unit file: ProtectSystem=true and ProtectHome=read-only. These directives forbid some changes made to system (/usr, /boot, /root, /run/user) and /home directories, mainly the creation of symbolic links to them (see details here). For most operations, this shouldn’t change anything, but it’s better to know that.

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 votes, average: 5.00 out of 5)
Loading...
19 comments on “RHEL7: Extend existing unencrypted logical volumes.
  1. hunter86_bg says:

    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” + “resize2fs”
    Some time ago i failed the exam because the time was not enough to fix the mistake with resizing logical volumes.The safest way to resize is via “lvresize” with the -r option.

  2. Ahmad says:

    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

    • CertDepot says:

      Concerning the xfs_growfs command, both options work. You can try.
      Furthermore, I advise you to use the following command:
      # lvextend -r –size +50M /mnt
      This way you do everything in only one step, which is quicker and less prone to error (both are important aspects during the exam).
      Concerning the second point, you are specifying an absolute size smaller than the current one.
      Either you specify a relative size (+50M for example) or a bigger absolute size (300M for example).
      lvextend is only used for increasing size, not for reducing it (->lvreduce).
      Also, you can’t reduce the size of a xfs file system (however, this works with ext4).

  3. shireeshk says:

    I have seen some of the sample questions where a floating range was mentioned.
    For instance, increase lv to 390M and the size of the floating range should set between 380M and 400M.

    What exactly the floating range mean here? is it something to do with volume group?

  4. Sultan says:

    Hi CertDepot
    First of all, thank you very much for your efforts.
    I have my RHCSA exam on this Friday (first time, no NDA so far). I need to know three things.

    1. My understanding is that in the exam objectives, reducing logical volumes (lvreduce) is not included and only “Extend existing logical volumes” is specifically written. Same was mentioned by Sander in one of his videos. Can you please confirm this?

    2. In case it is not part of the exam objectives (possibility due to the fact that size of xfs can’t be reduced) or in the exam, existing file systems are only xfs. It will not be possible to reduce any of them. In that case, if available disk space is not enough to complete a given task, then the only solution will be to delete swap partition and then vgreduce, do the task and make the remaining space as swap.

    Please confirm if this approach is correct.

    3. In case if it is in the exam objectives and the root partition is ext4 with free space. Can you please give a quick way to reduce the size of the root partition. Although, I have done it but still need to know if a quicker and better way is possible.

    Thanks in advance.

    • CertDepot says:

      1) Even though reducing an ext4 file system is not in the exam objectives, you are supposed to know how to do it.
      2) I don’t know if it’s the only solution but it is a solution.
      3) Reducing the root partition is a complex operation. This is not part of the exam objectives (the root partition is a special case). I wouldn’t try to reduce the root partition during the exam: it’s too risky.

      • Sultan says:

        Thank you very much for your reply and confirmation. I have successfully reduced Ext4 root logical volume without any rescue disk and following is my procedure.

        1. Reboot system with “rd.break” option at grub2 menu
        2. Copy “resize2fs” file to tmp folder of ramfs as I couldn’t find it in ramfs .
        # cp /sysroot/usr/sbin/resize2fs /tmp
        3. unmount /sysroot
        4. Run fsck on root file system
        # e2fsck -f /dev/rhel/root
        5. Run resize2fs on root file system (reduce to 3GB in my case).
        # /tmp/resize2fs /dev/rhel/root 3G
        6. exit and boot normally and login to the system.
        7. Check locking_type in the lvm config and change it to 1
        # grep locking_type /etc/lvm/lvm.conf
        # locking_type = 4
        change it to locking_type = 1
        8. Then run lvreduce
        # lvreduce -L 3G /dev/rhel/root
        Done.
        I was stuck at point-7 but got this info from a blog.

  5. Pat says:

    Is it really necessary to convert the partition into lvm before join them to a volume? There is an example in this video of Ralph Nyberg https://youtu.be/iLQJIDC6MAM?t=3m19s

    • CertDepot says:

      Yes. You have to execute the pvcreate command on a partition before using it.

      • Pat says:

        partition converted to LVM —>pvcreate—>vgcreate

        Is that correct?

        • CertDepot says:

          Partition creation with fdisk/parted -> pvcreate -> vgcreate/vgextend

          • Pat says:

            Sorry to get back to the subject. I just try to find out if converting the partition into lvm is necessary before applying the command pvcreate. So I would like to ask you if the following is correct:

            create partition with fdisk—> convert the partition to lvm with fdisk—>pvcreate -> vgcreate/vgextend

          • CertDepot says:

            You don’t need to convert the partition to lvm with fdisk.
            You only need to create the partition and define the type of partition with fdisk.
            After, you run pvcreate and vgcreate/vgextend.

          • Pat says:

            Thanks Certdepot

  6. wbrunc says:

    Thank you for the great site. Any reason why you tend to use –size ( instead of the easier -L ) and
    –name ( instead of easier -n ) for your lvcreate and lvextend commands ? Just wondering.

Leave a Reply

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |