- 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
- Increase the Size of a Linux Root Partition Without Rebooting
- Table of Contents
- Introduction
- Requirements
- Provision Additional Space
- Verify
- Summary
- Red Hat Customer Portal
- Log in to Your Red Hat Account
- Red Hat Account
- Customer Portal
- Select Your Language
- How to Resize a Partition using fdisk
- Prerequisites
- Procedure
- More Information
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!!
Источник
Increase the Size of a Linux Root Partition Without Rebooting
Table of Contents
Introduction
A typical Linux server deployed from a ProfitBricks supplied image has a single storage volume, /dev/vda . If we take a look at that using fdisk we will see that the disk is divided into two partitions. The first one, /dev/vda1 , is the boot partition where the OS resides. The second partition, /dev/vda2 , is configured as swap space.
In the example above, the total 50 GB storage volume is split into 46 GB usable space and 4 GB for swap. What if after provisioning we find that 46 GB of disk space is not enough but we prefer not to add an additional storage volume? The goal is to increase the amount of disk space available on the root filesystem. This can be accomplished with minimal disruption. We do not need to reboot the server!
Requirements
- A Linux Server created from a ProfitBricks supplied image.
- SSH or console access (via the DCD) to the Linux Server.
- The partprobe command. Can be installed from the parted package on most Linux distributions.
- The fdisk , swapoff , mkswap , swapon , and resize2fs commands. Likely available by default.
- A current snapshot or other backup of the system you are working on. Just to be safe!
Provision Additional Space
To increase the size of the hard drive, go into the DCD (Data Center Designer) and upscale the drive.
After you have increased the amount of drive space, click on «provisioning» to process the change. Takes around a minute and your hard drive is bigger.
We then need to switch off the swap — so make sure you can live a few minutes without swap space:
Once swap has been disabled, we need to reconfigure the partitions using fdisk :
We will delete the two existing partitions first. We run fdisk /dev/vda and then use the d command to delete partition 2, and then delete partition 1. Follow the example below:
Now we recreate our partitions. In the example we have 4 GB of swap space. So we need to keep at least that much space available for the new swap partition.
Recreate /dev/vda1 first. Press n to create a new partition. Enter p to create a primary partition. We can press Enter to accept the default value of 2048 for the first sector. Then enter a size for the partition. You can enter a value in GB, so if we are increasing the disk to 100 GB, we subtract our 4 GB for swap, and enter +96G for 96 GB.
Now we recreate the swap partition following a simalar process. Press n and then p to create a new primary partition. Press Enter to accept the default value for «First sector». We can also press Enter again to accept the default value for «Last sector».
Since this second partition is going to be used for swap space, we need to change the partition type. This can be done by pressing t at the fdisk prompt. We then press 2 to select the second partition. If you want to see the list of available partition types, press L, otherwise enter 82 to select «Linux swap / Solaris».
fdisk helpfully informs us that we have changed the partition type with the message:
After that, we save using the w command and are returned to a shell prompt:
You may get a message like this before the shell prompt:
Lets forgo rebooting and instead tell the kernel about the new partitions using partprobe :
We should be returned to the shell prompt with no output from partprobe .
Now we need to resize our filesystem on /dev/vda1 :
The filesystem on /dev/vda1 is now 25165824 (4k) blocks long.
Initialize the new swap location of /dev/vda2 :
Finally we edit /etc/fstab and replace the old UUID with the new one returned in the output of the mkswap command. The line to change has no value for «mount point» and has «type» set to swap.
After editing /etc/fstab , we need to enable swap again:
Verify
We can verify the new larger disk size by utilizing df and/or fdisk .
We can also confirm that the server was not rebooted by looking at the output of uptime :
Summary
We have successfully increased the amount of disk space available on our Linux server. If you have any questions or comments, please leave them here, or in the DevOps Community section of this site.
Источник
Red Hat Customer Portal
Log in to Your Red Hat Account
Your Red Hat account gives you access to your profile, preferences, and services, depending on your status.
If you are a new customer, register now for access to product evaluations and purchasing capabilities.
Need access to an account?
If your company has an existing Red Hat account, your organization administrator can grant you access.
Red Hat Account
Customer Portal
For your security, if you’re on a public computer and have finished using your Red Hat services, please be sure to log out.
Select Your Language
How to Resize a Partition using fdisk
Prerequisites
- A created partition that you know the name of. To check the name, run cat /etc/fstab. The first field is the name of the partition. The only way to change a partition size using fdisk is by deleting and recreating it so ensure that the information on the file system is backed up.
- Make sure the partition you are resizing is the last partition on a particular disk.
Disclaimer: The following information has been provided by Red Hat, but is outside the scope of our posted service level agreement and support procedures. The information has been tested however is provided as-is and any configuration settings or installed applications made from the information in this article could make your Operating System unsupported by Red Hat Support Services and non-recoverable. The intent of this article is to provide you with information to accomplish your system needs. Use the information in this article at your own risk.
On disks with a GUID Partition Table (GPT), using the parted utility is recommended, as fdisk GPT support is in an experimental phase.
Procedure
1. Unmount the partition:
2. Run fdisk disk_name.
3. Check the partition number you wish to delete with the p. The partitions are listed under the heading “Device”.
4. Use the option d to delete a partition. If there is more than one, fdisk prompts for which one to delete.
5. Use the option n to create a new partition. Follow the prompts and ensure you allow enough space for any future resizing that is needed. It is possible to specify a set, human-readable size instead of using sectors if this is preferred.
Note: It is recommended to follow fdisk’s defaults as the default values (for example, the first partition sectors) and partition sizes specified are always aligned according to the device properties.
Warning: If you are recreating a partition in order to allow for more room on a mounted file system, ensure you create it with the same starting disk sector as before. Otherwise the resize operation will not work and the entire file system may be lost.
6. Check the partition table to ensure that the partitions are created as required using the p option.
7. Write the changes with the w option when you are sure they are correct.
Important: Errors in this process that are written could cause instability with the selected file system.
8. Run fsck on the partition.
9. Finally, if you need to increase or decrease the file system, refer to the How to Shrink an ext2/3/4 File System with resize2fs, or the How to Grow an ext2/3/4 File System with resize2fs.
If you don’t need to increase or decrease the file system, mount the partition.
More Information
man fdisk
– man page for fdisk, has basic information about what fdisk is and what it supports.
man fstab
– man page for the /etc/fstab file including how to read the table.
The m option within fdisk
– this option lists all the available commands within fdisk.
Источник