How to Resize a Partition in Linux (2024)

How to Resize a Partition in Linux (1)

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 How to Resize a Partition in Linux (2)

The primary way of resizing drive partitions in Linux is to delete the old one and create a new one, 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 element, 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 - 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 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.

FREE WHITEPAPER

Linux Management Best Practices

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

How to Resize a Partition in Linux (3)

How to Resize a Partition in Linux (4)

Shrinking or Extending Linux Partition

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

How to Resize a Partition in Linux (5)

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

How to Resize a Partition in Linux (6)

  • /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):

How to Resize a Partition in Linux (7)

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

How to Resize a Partition in Linux (8)

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

How to Resize a Partition in Linux (9)

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

How to Resize a Partition in Linux (10)

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:

How to Resize a Partition in Linux (11)

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.
  • You cannot shrink the current element 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 one:

How to Resize a Partition in Linux (12)

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 +<size>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 consistency by running e2fsck:

How to Resize a Partition in Linux (13)

Note the highlighted line - the tool shows that there is a mismatch in the file system configuration and current 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:

How to Resize a Partition in Linux (14)

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:

How to Resize a Partition in Linux (15)

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.

MSP360 Managed Backup.
Simple. Reliable.

Powerful cross-platform backup and disaster recovery that leverages the public cloud to enable a comprehensive data protection strategy.

How to Resize a Partition in Linux (16)

How to Resize a Partition in Linux (17)

How to Resize a Partition in Linux (2024)
Top Articles
Travelex Insurance Review: Worth It? - NerdWallet
Travelex Travel Insurance: What to Know - NerdWallet
417-990-0201
How Much Does Dr Pol Charge To Deliver A Calf
Robot or human?
Falgout Funeral Home Obituaries Houma
Wild Smile Stapleton
27 Places With The Absolute Best Pizza In NYC
Overzicht reviews voor 2Cheap.nl
Rubfinder
Lqse-2Hdc-D
10 Great Things You Might Know Troy McClure From | Topless Robot
Oppenheimer Showtimes Near Cinemark Denton
今月のSpotify Japanese Hip Hopベスト作品 -2024/08-|K.EG
Sand Castle Parents Guide
Learn2Serve Tabc Answers
Hellraiser III [1996] [R] - 5.8.6 | Parents' Guide & Review | Kids-In-Mind.com
Zoe Mintz Adam Duritz
Publix Super Market At Rainbow Square Shopping Center Dunnellon Photos
Lowes Undermount Kitchen Sinks
Baja Boats For Sale On Craigslist
Johnnie Walker Double Black Costco
Ou Class Nav
What Individuals Need to Know When Raising Money for a Charitable Cause
Divina Rapsing
CohhCarnage - Twitch Streamer Profile & Bio - TopTwitchStreamers
Babydepot Registry
Christmas Days Away
Inmate Search Disclaimer – Sheriff
Bursar.okstate.edu
Smayperu
Rvtrader Com Florida
A Small Traveling Suitcase Figgerits
Greater Keene Men's Softball
How To Get Soul Reaper Knife In Critical Legends
Uc Santa Cruz Events
Mvnt Merchant Services
Dee Dee Blanchard Crime Scene Photos
Gateway Bible Passage Lookup
Www.craigslist.com Waco
Courtney Roberson Rob Dyrdek
Shell Gas Stations Prices
National Weather Service Richmond Va
Mychart University Of Iowa Hospital
Lyons Hr Prism Login
Wisconsin Volleyball titt*es
Ouhsc Qualtrics
St Als Elm Clinic
Unpleasant Realities Nyt
Diablo Spawns Blox Fruits
Coleman Funeral Home Olive Branch Ms Obituaries
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 6355

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.