- 2 easy methods to extend/shrink resize primary partition in Linux
- Lab Environment to resize primary partition (RHEL/CentOS 7/8) in Linux
- Method 1: Change size of partition using parted CLI utility
- List available partitions
- Disable swap partition
- Delete swap and expand partition
- Re-create swap partition
- Method 2: Change size of partition using fdisk utility
- List available partitions
- Delete swap partition
- Part 1 — Resize root partition
- Create swap partition
- Part 2 — Resize root partition
- Related Posts
- 5 easy steps to resize root LVM partition in RHEL/CentOS 7/8 Linux
- Lab Environment
- Step 1: Backup your data (Optional but recommended)
- Step 2: Boot into rescue mode
- Step 3: Activate Logical Volume
- Step 4: Perform File system Check
- Step 5: Resize root LVM partition
- Reduce or Shrink root LVM partition size in Linux
- Increase root partition size in Linux
- Verify the new size of root partition
- Related Posts
- 14 thoughts on “5 easy steps to resize root LVM partition in RHEL/CentOS 7/8 Linux”
2 easy methods to extend/shrink resize primary partition in Linux
Table of Contents
Related Searches: How to resize primary partition in Linux. How to extend non lvm root partition. How to change size of partition in Linux using parted and fdisk without destroying data. Steps to expand partition in RHEL/CentOS 7 and 8 Linux. Perform Disk Management in CentOS. How to use unallocated space to change size of partition in a disk in Linux. How to resize root partition not on LVM in Linux. Step by step guide to resize primary partition. How to expand partition with examples in Linux. centos disk management. rhel 7 extend non lvm root partition. centos 7 resize root partition. Steps to resize primary partition to extend non lvm root partition in linux. how to add unallocated disk space to a partition in Linux. centos shrink or extend non lvm root partition. add space to partition. fdisk extend partition. resize boot partition. extend non lvm root partition in linux. change size of partition.how to expand partition. centos resize primary partition. rhel change size of partition.
Earlier I had shared steps to create a file system and check file system type in Linux . Now in this article I will share the steps to resize primary partition, here we will extend non lvm root partition. With LVM it is far more easier and less riskier to change size of partition in an volume group in Linux .
- This article covers steps to resize primary partition (non-lvm) which can be dangerous and can leave your Linux system in an unusable broken state. It is important that you backup your content before you attempt to change size of partition.
- You can change size of partition (non-lvm) only on the last partition on the storage device with unallocated space. If the respective partition is not the last partition then the only way to expand partition is to backup your data , rebuild the disk and partitions, then restore the data. No tool such as gparted, parted or fdisk can help you change size of partition in such case.
- You must have some unallocated space or free space available in the concerned device to be able to expand partition. In some of the virtual environment you have an option to change the storage device size but on physical node if there is no enough unallocated space then resize primary partition (extend non lvm root partition) is not possible
- This article assumes you’re using either a GPT partition table, or an msdos partition table using primary partition types to extend non lvm root partition.
Lab Environment to resize primary partition (RHEL/CentOS 7/8) in Linux
I have performed resize primary partition operation on Virtual Machine running on Oracle VirtualBox installed on Linux server . My VM is running with CentOS 8 but I have also verified these steps on RHEL/CentOS 7 and RHEL 8 Linux.
Here my VM is installed on /dev/sda device where /dev/sda1 is boot partition, /dev/sda2 is root while /dev/sda3 is for swap.. Additionally I have left some unallocated free space in /dev/sda for the demonstration of this article to extend non lvm root partition.
Method 1: Change size of partition using parted CLI utility
You can either use gparted (GUI utility) or parted (CLI utility) to change size of partition in Linux. Here we plan to resize primary partition which in our case is /dev/sda.
List available partitions
To list the available partitions in /dev/sda we will execute below command
As I mentioned in the disclaimer section, you can change size of partition only on the last partition of the device but here root partition ( /dev/sda2 ) is not the last one instead swap ( /dev/sda3 ) is my last partition. So to expand root partition I must delete swap device to be able to to use unallocated space and extend non lvm root partition. After deleting swap, root partition will become the last partition on /dev/sda after which we can resize primary partition.
Disable swap partition
Currently I have around 1GB reserved for swap partition
I will turn off my swap (disable swap partition) and use this space to extend non lvm root partition in Linux
Verify the swap partition space, as you see not it is 0
Update /etc/fstab to make sure swap partition is not mounted at boot up stage.
Delete swap and expand partition
Now to resize primary partition /dev/sda2 and expand partition to a new value we must first delete swap partition using parted utility. As we need root partition to be the last partition of /dev/sda before we expand partition.
But our root partition is showing the same size as earlier i.e.
To complete the steps to resize non lvm root partition, execute resizefs to expand partition and refresh the changes
Re-verify the new size of root partition to make sure our steps to extend non lvm root partition was successful.
Re-create swap partition
Now we must create Swap partition which we deleted earlier in this article. We will again use parted utility to create swap partition
Now with parted we only created a partition with file system type as swap. Use mkswap to turn this partition into swap.
Next we must update /etc/fstab with the UUID of our new swap partition. To get the new UUID of swap partition
Update this UUID in /etc/fstab as shown below
Finally turn on the new swap partition
Verify the new swap partition
Now you can reboot your Linux server to make sure everything is OK and resize primary partition was successful.
Method 2: Change size of partition using fdisk utility
Similar to parted command, you can also use fdisk utility to resize primary partition and extend non lvm root partition.
List available partitions
Before we resize primary partition, let us list the available partitions
Now as you see my existing root partition /dev/sda2 size is
10G . Here we will expand partition with +1GB using unallocated disk space from /dev/sda .
Delete swap partition
Currently my swap partition is enabled and is the last partition of /dev/sda . So we must first delete swap partition here before we change size of partition as we need root to be the last partition in /dev/sda
So we will turn off the swap partition before we disable it
Now it is time to use fdisk utility to resize partition
Part 1 — Resize root partition
We will continue with the steps to extend non lvm root partition in the same fdisk session. Note down the start sector of the root partition before you expand partition.
Create swap partition
After we resize primary partition, in the same fdisk session we will also create a new swap partition which we had deleted initially with new start and end sector
Update the kernel regarding the recent changes we did to change size of partition
But our swap partition is still shown as 0
Now let us complete our steps to create swap partition using mkswap
Next update /etc/fstab with the UUID for your new swap partition. You can use blkid to get the UUID
Update the same in /etc/fstab as shown below
Now you can turn on the swap partition
Verify the same using free command
Part 2 — Resize root partition
If not done already in above steps, once you exit fdisk utility, update the kernel regarding the recent changes we did to change size of partition
We are not done with resize primary partition, as df command still shows old partition size for root partition
Execute resize2fs to expand partition on /dev/sda2 with the new changes
Now you can verify the new size of root partition
Lastly I hope the steps from the article to resize primary partition and extend non lvm root partition on RHEL/CentOS 7/8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.
Related Posts
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
Источник
5 easy steps to resize root LVM partition in RHEL/CentOS 7/8 Linux
Table of Contents
In this article I will share the step by step guide to resize root LVM partition on RHEL/CentOS 7/8 Linux with examples. The basic requirement to increase or decrease partition size is that the respective partition must not be mounted. Now you cannot unmount root partition so online resize is not possible. You must boot into rescue mode to resize root LVM partition.
Lab Environment
I have verified the steps from this article to (extend and shrink) resize root LVM partition (ext4) on RHEL/CentOS 7 and 8 Linux environment.
The screenshots are captured from CentOS 8 node running on Oracle VirtualBox installed on a Linux server.
I have a very simple environment with minimal partitions.
Below are the available logical volumes. As you see I have not created too many logical volumes.
Step 1: Backup your data (Optional but recommended)
Since you plan to shrink root LVM partition it is important that you backup your data before starting with the process. As if anything goes wrong you will end up with an unusable system.
Step 2: Boot into rescue mode
You cannot shrink root LVM partition online without reboot. Also you will need your RHEL/CentOS 7/8 ISO DVD depending on your environment to boot into rescue mode. Here I am using CentOS 8 so I will use the vanilla DVD of CentOS 8 to go to rescue mode.
Once you boot your Linux node with rescue DVD you can enable SSH and configure network in rescue mode. In this example I have disabled consistent network device naming and assigned a static IP address but you can also use DHCP by using ip=dhcp
For more information on the used syntax you can check Network boot options
In the next screen, select «3» to skip to shell. Make sure the file system is not mounted. If you select 1 or 2 then the root partition will get mounted on /mnt/sysimage which will not allow you to resize root LVM partition.
Since I have enabled SSH and configured network for my rescue mode, I have connected using Putty. Currently the system is mounted with LIVE DVD as you can see so our LVM root partition is not in mounted state so we can decrease or increase root partition size.
Step 3: Activate Logical Volume
Next we must activate our logical volume before we can shrink root LVM filesystem.
To list the available logical volumes and volume groups:
Step 4: Perform File system Check
Next run a file system check to make sure the file system is proper and not corrupted. Without a file system check you cannot shrink root LVM partition or any other partition.
Step 5: Resize root LVM partition
Once you boot in rescue mode, you can resize root LVM partition or any other partition which you cannot un-mount runtime in default.target such as boot partition. In the below examples we will decrease root LVM partition size and also increase root LVM partition size.
Reduce or Shrink root LVM partition size in Linux
Next use resize2fs to resize root LVM partition. Currently my » / » file system is 13.5 GB which I want to decrease root partition size to 7GB
Next use lvreduce with the same size (7G) as used in above command to decrease root partition size.
So the resize root LVM partition was successful. You can mount the root file system on /mnt/sysimage to verify the size
As you see my root partition is now 7GB
Increase root partition size in Linux
Now to extend root partition size I will use the same node. Here we will increase root partition size by 1GB from 7G to 8G.
lvextend command was successful, next we will execute resize2fs to increase root partition size
Post resize2fs you can verify the changes for which you must mount the root partition. Since we are in rescue mode we will mount it on /mnt/sysimage
Next using df command we see we were successfully able to increase root partition size
Verify the new size of root partition
Now above command will only mount the root partition. Next we will mount all other partitions to properly verify our changes before we boot into default.target
Since we have already mounted root partition, next we will mount boot partition. Now if you have any other partitions on your system then you can mount them as well.
Next use chroot to change file system to /mnt/sysimage .
Verify if everything is working as expected before you reboot the node to default.target
Lastly I hope the steps from the article to resize root LVM partition on RHEL/CentOS 7/8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.
Related Posts
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
14 thoughts on “5 easy steps to resize root LVM partition in RHEL/CentOS 7/8 Linux”
I came across the bad logic number error when going through step 4 and step 5. It blocked me here and I googled, not finding a solution that works for me.
You can try to repair the file system but in such cases most likely you have to first fix the hard disk before attempting the resize
If you have CentOS7, you should make sure if your filesystem is ext, not xfs.
You can check your filesystem with
If your filesystem is xfs, then step 4 and 5 will not work since those steps are for ext filesystem.
root lvm needs to be continuous on hard disk or not? Can we have the original root lvm, then the original swap or var or opt lvm and then the root lvm extended part?
If it is LVM then the scenario what you are explaining is not possible because LVM are always combined, we only extend VG to make sure LVM is extended. Even with non-lvm I don’t think we can have a setup with such combination
is this a theoretical question or you have a setup like this?
Can you show us lvdisplay –maps from root or other lvextend-ed lvm…
I’d like to see if it is continuous after lvextend… lvextend is of course possible just is some space is available in vg. But if we originally had root lvm, then swap lvm, then var lvm (all that on one disk, one pv, one vg) and then extened root, does –maps for root show 2 Physical extents groups. thanks
I don’t have the same setup any more. You can try this locally on any VM with your scenario to verify.
Thanks for the write up!
Following this instructions, I had trouble with trying to resize / (root) under /dev/mapper/vg_blah-lv_root .
But it was successfully done with parameter pointing to /dev/vg_blah-lv_root.
Error message when it could not resize via /dev/mapper/vg_blah-lv _root was : ” /usr/sbin/fsadm: execvp failed: Input/output error \n Filesystem check failed» despite I ran e2fsck -f /dev/mapper/vg_blah-lv_root without any bad block before and after that.
did it, works, root can have 2 physical extents groups…
Great, thanks for sharing this with us.
Thank you for very good manual ! I did it step by step and everything works ! It’s not so easy but it’s understandable for me.
Hi, I am using windows and centos 8 stream dual boot. I want to extend the size of the centos root. So I shrank some memory from my windows and created a new partition using GParted. And in the rescue mode i created the physical volume of this partition and tried to use this to extend the root of the centos. When I tried to run e2fsck -f /dev/mapper/cs-root, it is not running and showing me superblock invalid, bad magic number in super block, run e2fsck -b 8193 and /dev/mapper/cs-root contains a xfs file system. Due to this i could not use resize2fs command even though i can use lvextend command. Due to have any solution for this problem?
Did you try performing a format on the newly created partition on the windows and then create a Physical Volume on top of it?
No, but I used “lvextend” and then used “fsadm resize /dev/mapper/cs-root”, when the filesystem is mounted. It successfully extended the size of the root.
Источник