Share, , Google Plus, Pinterest,

Print

Posted in:

Increase Root Partition Size – LVM – CentOS

Since i have been getting alot of questions on how to increase root partition size on a linux system i decided (finally!) to write a how to about this topic. Linux root partition is different from all other partitions on your system since it holds all of the system files required for your system to run and operate.

This is the reason why you can not increase root partition size as simply as any other partition – you can not just un-mount it because the system will not let you since it is using it.

To increase root partition size, we have to boot off a bootable live CD/DVD or USB image and increase root partition size from there and this requires SYSTEM DOWNTIME! It is not possible to increase root partition size without system downtime!

For this how to i have set up a virtual linux system and filled up it’s root partition, as you can see in the picture below. I will use CentOS ISO to boot a live system which will enable me to increase root partition size.

My CentOS servers root partition is located on a LVM which makes it easier to resize. If you have your root partition size located on a standard  (/dev/sdaX, /dev/sdbY, …) you can not follow this how to, to increase your root partition size!

Let’s learn how to Increase Root Partition Size!

1. Prepare Your CentOS 7 Live CD/DVD or USB Image

Make sure you have a live CD/DVD or USB image to boot off from. In this how to i will use CentOS 7 DVD ISO image, but in the end you can do the same with Fedora, Ubuntu or any other live CD/DVD ISO image.

2. Identify Your Root Partition

Make sure you will be able to identify the root partition when in live system. Since we are increasing a LVM root partition this should be a no brainer else, the easiest way would be remembering it’s size. If you have many partitions the same size you could check the start and end blocks.

Using LVM i identified my root partition as /dev/mapper/centos-root LVM partition (centos/root) which means it is in a VG (Volume Group) called “centos” and a LV (Logical Volume) called “root”. Read more about managing LVM’s HERE.

Identify root partition
Identify root partition

3. Add Additional Disk

Add additional disk to your system so we can increase root partition size or make sure you have free space available on your existing disk configuration. Since i am using virtual system i added an additional 2GB disk to it which is recognized as /dev/sdb in my system.

4. Reboot Your System

Insert the live image into your CD/DVD drive or USB port and reboot the system. Since i am using a virtual system i will insert CentOS 7 ISO to virtual CD/DVD drive. At boot time jump to “boot menu” and choose the correct medium to boot off from.

Insert CentOS 7 DVD ISO
Insert CentOS 7 DVD ISO
Boot menu
Boot menu

After this, the CentOS 7 menu should appear.

5. Choose “Troubleshooting”

When your CentOS 7 ISO boots choose “Troubleshooting” option from the first menu.

CentOS 7 menu: Troubleshoot
CentOS 7 menu: Troubleshoot

6. Choose “Rescue a CentOS system”

In the second menu choose “Rescue a CentOS System”.

CentOS menu: Rescue CentOS system
CentOS menu: Rescue CentOS system

7. Skip Mounting Existing Linux Installations

When asked to find and mount any existing linux installations choose “Skip”. Since we are increasing our root partition, this partition must not be mounted.

Skip mounting existing linux installations
Skip mounting existing linux installations

When hiting “Enter” you will drop to bash shell.

8. Prepare New Disk

Since i added a completely new 2GB disk to my virtual system i must prepare this disk for use with LVM. Read more about managing LVM’s HERE. If you are extending your root partition with existing empty partition the process is similar just use the partition identifier (sdaX or sdbX) when running commands.

Checking current disk configuration with “fdisk -l”.

Checking current disk configuration
Checking current disk configuration
Checking current disk configuration
Checking current disk configuration

We must prepare new additional disk by creating a new PV (Physical Volume) and extend our VG (Volume Group) as shown in the picture below – identified in Step 2 and with fdisk, VG to extend is called “centos”.

Prepare additional disk
Prepare additional disk

As we can see in the next screenshot our VG called centos now has 511 free PE (Physical Extents) – see “Free PE / Size” row – which means we can increase our root LV (Logical Volume) by 511 PE.

Check number of free PE
Check number of free PE

9. Increase Root Partition Size

To wrap things up we need to extend root LV with “lvextend” command. In my case i am extending it by 511 PE (as much as there are free) and i am also using the parameter “-r” at the end of my command which automatically resizes the filesystem too!

The command sytnax i used is “lvextend -l +511 centos/root -r”. DO NOT FORGET the “+” sign before PE number! If you do, you might loose data!

Increase root partition
Increase root partition
Increase root partition
Increase root partition

As we can see at the end of command output, data blocks number increased and with that the partition size also.

10. Reboot the System

It is time to remove live image from CD/DVD or USB and reboot to boot our existing system. After that we can check the root partition free disk space.

Check root partition free space
Check root partition free space

As we can see we have 2GB of free space available on root partition which means we succeded increasing root partition size and came to an end of this how to. I hope this helps you guys.

 

  • Pingback: Resize Partition and Filesystem with fdisk & resize2fs - GeekPeek.Net()

  • Pingback: GeekPeek.Net RSS Feed()

  • Martin B

    Hi, I have a Centos 6 server with the following setup:
    2x 80GB Sata hard drives.
    On each drive I have the following
    1 partition for /boot RAID 1
    1 partition for / RAID 1

    The root partition was created with a VG and a LVM.
    I just bought 2 new 3TB hard drive to extend my root partition. These new drives are connected as /dev/sdc and /dev/sdd. My goal is to add these 2 HD configure as RAID 1 to extend my root partition which I’m running out of space.

    Here are the steps that I followed to extend my root partition and add the 2 new HD.
    mdadm –create /dev/md2 –level=1 –raid-device=2 /dev/sdc /dev/sdd
    vgextend VG_GROUP /dev/md2
    lvextend -l +100%FREE /dev/VG_GROUP/LogVol00
    resize2fs /dev/mapper/VG_GROUP/LogVol00

    Now when I reboot, Grub start and when trying to load the kernel, I have a kernel panic error – not syncing. It looks like the kernel and or boot loader does not recognized my new extended root partition.

    Is someone have an idea on how to fix this ?

  • Pingback: Installing a Private Enterprise File Share and Sync Appliance on Windows Azure Compute Services | Storage Made Easy Blog()

  • Minthang Sitlhou

    Hi,

    I followed your tutorial on my Vbox CentOS 6.5 machine, but exremely sorry to say that this tutroial needs some serious modifications.

    #1.I don’t understand why you have encourage using a live CD when the same can be performed without a live CD in a live system under VBOX.

    PS: Pardon me if your tutorial is reference with a production server.

    #2. While creating a physical disk, you have not created an LVM partition and assigned the file type corresponding to the root file system type. After which, the new LVM partiton has to be used to extend the volume group. Also, in the tutorial above you have created the whole of “/dev/sdb” partition as one physical group while the usual way is to create a new partiton first,assign a file system then convert the sub-partiton, e.g “dev/sdb1” as a physical group.

    #3. After the volume group was extended with the newly created LVM partition, the new volume/LVM partition was not resize or reinitialized to its default using the command:

    resize2fs /dev/sdX

    Following this article, I ran into grub issue which took me to a black screen with only the grub prompt.

    Hope, you will once again inspect the information you have provided.

    • Mitch

      Hi Minthang,

      #1 Yes, it could also be done on a live system in VBOX, but as you said i used VBOX as a reference. Some people might be using physical machines.

      #2 There is at least one advantage in doing so and no disadvantages i know of currently. The advantage is when sometime in future i would be increasing the disk size of /dev/sdb the /dev/sdb volume group will automatically get free block extensions once increased without the need of using vgextend to extend the volume group. As said i know no disadvantages of using /dev/sdb over /dev/sdb1.

      #3 If you would read the tutorial closely you would notice the “-r” parameter when using lvextend which is actually running resize2fs command as you specified.

      Don’t just diss other peoples posts, do your homework, and read posts carefully so you do not miss “-r” parameters. Maybe this would help you avoid black screen and grub command prompt.

      • Minthang Sitlhou

        Definitely, I missed the “-r” option. Will give it a try once again. Thanks for your feedback.

  • sanga

    i think we need to add the newly created PV to Volume Group, then increase the LVM. I got error by following this post

    • Mitch

      Hi sanga, did you miss the step 8 where it says “We must prepare new additional disk by creating a new PV (Physical Volume) and extend our VG (Volume Group)”. Looking at the screenshot provided, i did the “vgextend” command ? Regards, Mitch

  • Symon

    Hi, at step 9 before the lvextend command the logical volume must be activated. I got an error..

  • Spaniard

    Thank you for this!

  • krems

    You lost me at step 8. I have usr partion on dev/sda2/ I’m trying to increase
    typing pvcreate dev/sda3 says device not found.
    Typing pvcreate /dev/sda, says it’s excluded bya filter. /dev/sda2, says can’t initialize without -ff