2 Easy Methods To Extend - Shrink Resize Primary Partition in Linux - GoLinuxCloud
2 Easy Methods To Extend - Shrink Resize Primary Partition in Linux - GoLinuxCloud
MENU
Table of Contents
Lab Environment to resize primary partition (RHEL/CentOS 7/8) in Linux
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 X
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.
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 1/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
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.
WARNING:
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.
ALSO READ:
NOTE:
I will only demonstrate the steps to extend non lvm root partition, but using the same methods you
X
can also shrink and change size of partition to lower value in Linux. But be sure to backup your data.
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 2/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
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
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.
Number Start End Size Type File system Flags <--- This is my partition l
1 1049kB 538MB 537MB primary ext4 boot
2 538MB 11.3GB 10.7GB primary ext4
3 11.3GB 12.3GB 1074MB primary linux-swap(v1)
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.
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 3/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
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.
ALSO READ:
I will turn off my swap (disable swap partition) and use this space to extend non lvm root partition in Linux
Update /etc/fstab to make sure swap partition is not mounted at boot up stage.
X
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 4/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
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. ~10GB
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 5/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
To complete the steps to resize non lvm root partition, execute resizefs for ext3 and ext4 partitions or
xfs_growfs for xfs partition 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.
ALSO READ:
Now we must create Swap partition which we deleted earlier in this article. We will again use parted utility
to create swap partition
X
[root@centos-8 ~]# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 6/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
( t d) it
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
Now you can reboot your Linux server to make sure everything is OK and resize primary partition was
successful.
ALSO READ:
Similar to parted command, you can also use fdisk utility to resize primary partition and extend non lvm
root partition.
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 .
Advertisement
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
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 9/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
ALSO READ:
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 10/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
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.
Command (m for help): d <-- Now we need to delete root partition before we extend non l
Partition number (1,2, default 2): 2 <-- provide the root's partition number
Command (m for help): p <-- Print the partition table with the new changes
Disk /dev/sda: 15 GiB, 16106127360 bytes, 31457280 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5290bf38
Command (m for help): n <-- Next we will create and expand partition for root
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p <-- This will be a primary partition
Partition number (2-4, default 2): 2 <-- For root partition we know the partition numbe
First sector (1050624-31457279, default 1050624): 1050624 <-- Use the same first sector
Last sector, +sectors or +size{K,M,G,T,P} (1050624-31457279, default 31457279): +11G <-
X
ALSO READ:
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 11/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
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
Command (m for help): n <-- Now we will also create a new swap partition
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): p <-- This also will be a primary partition
Partition number (3,4, default 3): 3 <-- We can give any partition number here but we w
First sector (24119296-31457279, default 24119296): <-- This can be the same as default
Last sector, +sectors or +size{K,M,G,T,P} (24119296-31457279, default 31457279): +512M
Command (m for help): t <-- We must also change the filesystem type of our swap partit
Update the kernel regarding the recent changes we did to change size of partition
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
X
ALSO READ:
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 13/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
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 for ext3 and ext4 partitions or xfs_growfs for xfs partition to expand partition on
/dev/sda2 with the new changes
Lastly I hope the steps from the article to resize primary partition and extend non lvm root partition on
X
RHEL/CentOS 7/8 Linux was helpful. So, let me know your suggestions and feedback using the comment
section.
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 14/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
Didn't find what you were looking for? Perform a quick search across GoLinuxCloud
Search …
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.
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 15/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
← Older Comments
imran rasheed
december 4, 2020 at 1:25 pm
Reply
sudo
december 15, 2020 at 9:26 am
Works great on Debian 8 as well. It required a reboot after fdisk write with w.
Reply
jhony
january 19, 2021 at 9:24 pm
I have just used this fantastic guide on a vps (Gentoo installed) and it worked flawlessly.
Thank you very much!
Reply
kurdtech
march 31, 2021 at 7:15 am
You the man keep the hard work, thank you for your clean vivid instruction.
X
Reply
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 16/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
joe oppenheim
april 16, 2021 at 3:03 pm
Cant see who wrote this article but wow, great article. I read a dozen other web pages trying to
describe how to achieve this and NONE of them mentioned the most obvious issue: The SWAP
partition is in the way!!!!
Thanks for the article! Well done and keep posting.
Reply
eddy r
february 17, 2022 at 8:45 pm
Hey, very detailed instruction, thank you for that! I was able to do the same with fdisk on RHEL 8 but
that didn’t work on my RHEL 7 machine. Your way with parted was nearly the same but helped me still
a lot! Just one thing to add: If you have a xfs Filesystem you can extend it later with xfs_growfs instead
of resize2fs …
Cheers!
Reply
admin
february 17, 2022 at 11:01 pm
Thanks for the Hint, I missed to add that part earlier. Updated the article.
Reply
X
masham
march 17, 2022 at 2:50 pm
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 17/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
Reply
joe
july 20, 2022 at 1:53 am
Reply
ali
october 5, 2022 at 4:42 pm
Reply
← Older Comments
Leave a Comment
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 18/19
11/27/22, 11:48 PM 2 easy methods to extend/shrink resize primary partition in Linux | GoLinuxCloud
Name *
Email *
Save my name and email in this browser for the next time I comment.
Notify me via e-mail if anyone answers my comment.
Post Comment
https://www.golinuxcloud.com/extend-resize-primary-partition-non-lvm-linux/ 19/19