Linux reduce partition size

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

Читайте также:  Как создать заметку windows 10

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

Читайте также:  Для слежения за компьютером windows

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.

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!!

Источник

How to Extend/Reduce LVM’s (Logical Volume Management) in Linux – Part II

Previously we have seen how to create a flexible disk storage using LVM. Here, we are going to see how to extend volume group, extend and reduce a logical volume. Here we can reduce or extend the partitions in Logical volume management (LVM) also called as flexible volume file-system.

Extend/Reduce LVMs in Linux

Requirements

When do we need to reduce volume?

May be we need to create a separate partition for any other use or we need to expand the size of any low space partition, if so we can reduce the large size partition and we can expand the low space partition very easily by the following simple easy steps.

My Server Setup – Requirements
  1. Operating System – CentOS 6.5 with LVM Installation
  2. Server IP – 192.168.0.200

How to Extend Volume Group and Reduce Logical Volume

Logical Volume Extending

Currently, we have One PV, VG and 2 LV. Let’s list them one by one using following commands.

Logical Volume Extending

There are no free space available in Physical Volume and Volume group. So, now we can’t extend the lvm size, for extending we need to add one physical volume (PV), and then we have to extend the volume group by extending the vg. We will get enough space to extend the Logical volume size. So first we are going to add one physical volume.

For adding a new PV we have to use fdisk to create the LVM partition.

  1. To Create new partition Press n.
  2. Choose primary partition use p.
  3. Choose which number of partition to be selected to create the primary partition.
  4. Press 1 if any other disk available.
  5. Change the type using t.
  6. Type 8e to change the partition type to Linux LVM.
  7. Use p to print the create partition ( here we have not used the option).
  8. Press w to write the changes.

Restart the system once completed.

Create LVM Partition

List and check the partition we have created using fdisk.

Verify LVM Partition

Next, create new PV (Physical Volume) using following command.

Verify the pv using below command.

Create Physical Volume

Extending Volume Group

Add this pv to vg_tecmint vg to extend the size of a volume group to get more space for expanding lv.

Let us check the size of a Volume Group now using.

Extend Volume Group

We can even see which PV are used to create particular Volume group using.

Check Volume Group

Here, we can see which Volume groups are under Which Physical Volumes. We have just added one pv and its totally free. Let us see the size of each logical volume we have currently before expanding it.

Check All Logical Volume

  1. LogVol00 defined for Swap.
  2. LogVol01 defined for /.
  3. Now we have 16.50 GB size for / (root).
  4. Currently there are 4226 Physical Extend (PE) available.

Now we are going to expand the / partition LogVol01. After expanding we can list out the size as above for confirmation. We can extend using GB or PE as I have explained it in LVM PART-I, here I’m using PE to extend.

For getting the available Physical Extend size run.

Check Available Physical Size

There are 4607 free PE available = 18GB Free space available. So we can expand our logical volume up-to 18GB more. Let us use the PE size to extend.

Use + to add the more space. After Extending, we need to re-size the file-system using.

Expand Logical Volume

  1. Command used to extend the logical volume using Physical extends.
  2. Here we can see it is extended to 34GB from 16.51GB.
  3. Re-size the file system, If the file-system is mounted and currently under use.
  4. For extending Logical volumes we don’t need to unmount the file-system.
Читайте также:  Драйвера для нетбуков asus под windows

Now let’s see the size of re-sized logical volume using.

Resize Logical Volume

  1. LogVol01 defined for / extended volume.
  2. After extending there is 34.50GB from 16.50GB.
  3. Current extends, Before extending there was 4226, we have added 4607 extends to expand so totally there are 8833.

Now if we check the vg available Free PE it will be 0.

See the result of extending.

Verify Resize Partition

  1. New Physical Volume added.
  2. Volume group vg_tecmint extended from 17.51GB to 35.50GB.
  3. Logical volume LogVol01 extended from 16.51GB to 34.50GB.

Here we have completed the process of extending volume group and logical volumes. Let us move towards some interesting part in Logical volume management.

Reducing Logical Volume (LVM)

Here we are going to see how to reduce the Logical Volumes. Everyone say its critical and may end up with disaster while we reduce the lvm. Reducing lvm is really interesting than any other part in Logical volume management.

  1. Before starting, it is always good to backup the data, so that it will not be a headache if something goes wrong.
  2. To Reduce a logical volume there are 5 steps needed to be done very carefully.
  3. While extending a volume we can extend it while the volume under mount status (online), but for reduce we must need to unmount the file system before reducing.

Let’s wee what are the 5 steps below.

  1. unmount the file system for reducing.
  2. Check the file system after unmount.
  3. Reduce the file system.
  4. Reduce the Logical Volume size than Current size.
  5. Recheck the file system for error.
  6. Remount the file-system back to stage.

For demonstration, I have created separate volume group and logical volume. Here, I’m going to reduce the logical volume tecmint_reduce_test. Now its 18GB in size. We need to reduce it to 10GB without data-loss. That means we need to reduce 8GB out of 18GB. Already there is 4GB data in the volume.

While reducing size, we need to reduce only 8GB so it will roundup to 10GB after the reduce.

Reduce Logical Volume

Here we can see the file-system information.

Check File System Size

  1. The size of the Volume is 18GB.
  2. Already it used upto 3.9GB.
  3. Available Space is 13GB.

First unmount the mount point.

Unmount Parition

Then check for the file-system error using following command.

Scan Parition for Errors

Note: Must pass in every 5 steps of file-system check if not there might be some issue with your file-system.

Next, reduce the file-system.

Reduce File System

Reduce the Logical volume using GB size.

Reduce Logical Partition

To Reduce Logical volume using PE Size we need to Know the size of default PE size and total PE size of a Volume Group to put a small calculation for accurate Reduce size.

Here we need to do a little calculation to get the PE size of 10GB using bc command.

Press CRTL+D to exit from BC.

Calculate PE Size

Reduce the size using PE.

Reduce Size Using PE

Re-size the file-system back, In this step if there is any error that means we have messed-up our file-system.

Resize File System

Mount the file-system back to same point.

Mount File System

Check the size of partition and files.

Here we can see the final result as the logical volume was reduced to 10GB size.

Verify Logical Volume Size

In this article, we have seen how to extend the volume group, logical volume and reduce the logical volume. In the next part (Part III), we will see how to take a Snapshot of logical volume and restore it to earlier stage.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Оцените статью