Меню Рубрики

Resize partition linux extended

2 easy methods to extend/shrink resize primary partition 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 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.

Источник

Resize Partitions in Linux

Resize Partitions in Linux

In this article, we will overview how to resize a partition in a Linux. We will use only built-in tools and commands.

Before you begin with partitions, make sure you have a solid backup. Once data is deleted it cannot be undeleted. Build an effective backup strategy for your Linux system: download our free

The primary way of resizing drive partitions in Linux is to delete the old one and create a new partition, using the previous starting sector (you can think about it like “left bound of the new partition”). Then you need to simply modify the file system properties to fit the new bounds. If done carefully, you will not lose your data on the modified partition, despite the frightening phrase «delete the partition».

Preparation

Linux has built-in tools (commands) to work with partitions:

  • df / lsblk — allows you to list available drives, including block devices.
  • mount / umount — simple tools allowing you to detach a partition to change its properties.
  • fdisk — partitions management tool. It will recreate partitions with newly specified bounds.
  • e2fsck — allows checking of the modified file system for errors.
  • resize2fs — modifies existing file system to fit new partition size bounds.

In this example, we are going to use Ubuntu Server 14 as an instance in Amazon EC2 cloud. So, the disk we are working with is a block EBS device called /dev/xvdb.

Note: depending on your Linux distribution and available storage devices, volume and drive names can be different. You have also use the sudo command if your current account doesn’t have “root” privileges.

  • Best practices in system setup and management
  • Ways to properly secure your Linux system
  • Guide to optimal file structure organization

Shrinking or Extending Linux Partition

First of all, let’s find the partition we want to resize. Use df -h command to list available partitions:

The last line contains the device /dev/xvdb1 — it is our working partition. Note that there are actually 2 names:

  • /dev/xvdb — it is whole device.
  • /dev/xvdb1 — one partition allocated on /dev/xvdb device.

You can check it using, for example, the lsblk tool (for block-level devices only):

I have created the file file_should_remain.test to check whether the resized partition did not lose its data

We need to unmount the volume before modifications — just run the umount command, where mounting point is a file system’s representation of the device. And don’t forget sudo to get appropriate permissions:

command» width=»599″ height=»33″ data-src=»https://www.msp360.com/resources/wp-content/uploads/2018/04/Linux-partition-resize-4.png» loading=»lazy» data-srcset=»https://www.msp360.com/resources/wp-content/uploads/2018/04/Linux-partition-resize-4.png 599w, https://www.msp360.com/resources/wp-content/uploads/2018/04/Linux-partition-resize-4-300×17.png 300w» data-sizes=»auto»/>

Now run fdisk command with our test disk name as an argument and then type “p” to print its partitions list:

The last line contains important info about the current partition size and its bounds: “Start” and “End”. Remember “Start” value (2048 in this example). Now delete this partition by typing “d” and then type “w” to save these modifications:

After the old partition is removed we need to create the new one, either a bigger or smaller size. The following procedure is the same for both actions, but keep in mind that:

  • You can extend the partition only to the space available at the “right” side. Simply saying, free space should be at the end of the resizing the partition.
  • You cannot shrink the current partition to a size smaller than the actual data stored.
  • It is a must to specify the same starting point as the previous partition while creating the new one. Otherwise, you may lose your data!

In our example, the new partition will be a smaller size so the Shrink operation will be performed. Let’s run fdisk again and type “n” — creating the new partition:

You may use default values in most fdisk questions, but carefully check these highlighted on the picture above: first sector (starting point) and last sector. You can use the + G format to specify the desired partition size in Gigabytes (use “M” for Megabytes). Finish by typing “w” to save changes.

Now we need to verify partition consistency by running e2fsck:

Note the highlighted line — the tool shows that there is a mismatch in the file system configuration and current partition size. This is due to shrinking the partition with no changes made to the file system metadata. Just answer “no” to continue checking.

Let’s fix the error using resize2fs and then check the filesystem again:

Now the file system block size is the same as for partition configuration. Finally, let’s mount the resized volume and check that our data is still here:

As you can see, our test file is still here and the partition has a new size.

Conclusion

That’s it. Now you have fresh-new partitions. If you have any questions or comments regarding the article, let us know.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

  • Очистка файлов mac os
  • Очистка реестра mac os x
  • Очистка оперативной памяти mac os
  • Очистка кэша safari mac os
  • Очистка корзины mac os через терминал