{"id":28432,"date":"2019-01-31T18:42:55","date_gmt":"2019-01-31T14:42:55","guid":{"rendered":"https:\/\/www.msp360.com\/resources\/?p=28432"},"modified":"2025-08-21T14:27:08","modified_gmt":"2025-08-21T10:27:08","slug":"linux-resize-partition","status":"publish","type":"post","link":"https:\/\/www.msp360.com\/resources\/blog\/linux-resize-partition\/","title":{"rendered":"Resize Partitions in Linux"},"content":{"rendered":"<p>In this article, we will overview how to resize a partition in a Linux. We will use only built-in tools and commands.<\/p>\n<p><!--more--><\/p>\n<blockquote><p>Before you begin with partitions, make sure you have a solid backup solution in place. Check <a href=\"https:\/\/www.msp360.com\/backup\/free-backup-software\/\">MSP360 Free Backup software<\/a> for Linux: a command-line based solution designed to automate file-level backups.<\/p><\/blockquote>\n<p>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 \u201cleft bound of the new partition\u201d). Then you need to simply modify the file system properties to fit the new bounds. If done carefully, <b>you will not lose your data on the modified element<\/b>, despite the frightening phrase \"delete the partition\".<\/p>\n<h2>Preparation<\/h2>\n<p>Linux has built-in tools (commands) to work with partitions:<\/p>\n<ul>\n<li><b>df<\/b> \/ <b>lsblk<\/b> - allows you to list available drives, including block devices.<\/li>\n<li><b>mount<\/b> \/ <b>umount<\/b> - simple tools allowing you to detach a partition to change its properties.<\/li>\n<li><b>fdisk<\/b> - management tool. It will recreate partitions with newly specified bounds.<\/li>\n<li><b>e2fsck<\/b> - allows checking of the modified file system for errors.<\/li>\n<li><b>resize2fs<\/b> - modifies existing file system to fit new size bounds.<\/li>\n<\/ul>\n<p>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.<\/p>\n<p><i>Note: depending on your Linux distribution and available storage devices, volume and drive names can be different. You have also use the <\/i><b><i>sudo<\/i><\/b><i> command if your current account doesn\u2019t have \u201croot\u201d privileges.<\/i><\/p>\n<div class=\"call-to-action\">\n<div class=\"call-to-action__left\" style=\"width: 75%;\">\n<div class=\"call-to-action__tag\">FREE WHITEPAPER<\/div>\n<div class=\"call-to-action__title\">Linux Management Best Practices<\/div>\n<div class=\"call-to-action__text\">\n<ul>\n<li>Best practices in system setup and management<\/li>\n<li>Ways to properly secure your Linux system<\/li>\n<li>Guide to optimal file structure organization<\/li>\n<\/ul>\n<!--HubSpot Call-to-Action Code --><span class=\"hs-cta-wrapper hs-cta-deferred\" id=\"hs-cta-wrapper-8e06a2b5-4126-47b5-a276-f21b9cf3140d\" data-portal=\"5442029\" data-id=\"8e06a2b5-4126-47b5-a276-f21b9cf3140d\"><span class=\"hs-cta-node hs-cta-8e06a2b5-4126-47b5-a276-f21b9cf3140d\" id=\"hs-cta-8e06a2b5-4126-47b5-a276-f21b9cf3140d\"><!--[if lte IE 8]><div id=\"hs-cta-ie-element\"><\/div><![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/5442029\/8e06a2b5-4126-47b5-a276-f21b9cf3140d\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"hs-cta-img\" id=\"hs-cta-img-8e06a2b5-4126-47b5-a276-f21b9cf3140d\" style=\"border-width:0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/5442029\/8e06a2b5-4126-47b5-a276-f21b9cf3140d.png\" alt=\"CTA\"><\/a><\/span><\/span><!-- end HubSpot Call-to-Action Code -->\n<\/div>\n<\/div>\n<div class=\"call-to-action__right\" style=\"width: 25%;\"><img decoding=\"async\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2019\/09\/Group-2-19.png\" alt=\"WP icon\" \/><\/div>\n<\/div>\n<h2>Shrinking or Extending Linux Partition<\/h2>\n<p>First of all, let\u2019s find the partition we want to resize. Use <b>df -h<\/b> command to list available elements:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21075 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-1.png\" alt=\"Resize Linux Partition: Use df -h command to list available partitions\" width=\"605\" height=\"213\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-1.png 605w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-1-300x106.png 300w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><br \/>\nThe last line contains the device <b>\/dev\/xvdb1<\/b> - it is our working partition. Note that there are actually 2 names:<\/p>\n<ul>\n<li>\/dev\/xvdb - it is whole device.<\/li>\n<li>\/dev\/xvdb1 - one partition allocated on \/dev\/xvdb device.<\/li>\n<\/ul>\n<p>You can check it using, for example, the <b>lsblk<\/b> tool (for block-level devices only):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21076 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-2.png\" alt=\"Resize Linux Partition: Use the lsblk tool to check partitions\" width=\"599\" height=\"136\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-2.png 599w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-2-300x68.png 300w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/p>\n<p>I have created the file <b>file_should_remain.test<\/b> to check whether the partition did not lose its data<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21077 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-3.png\" alt=\"Resize Linux partition: Test file created to check whether the resized partition did not lose its data\" width=\"603\" height=\"92\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-3.png 603w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-3-300x46.png 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/p>\n<p>We need to unmount the volume before modifications - just run the <b>umount &lt;mounting point&gt;<\/b> command, where <b>mounting point<\/b> is a file system\u2019s representation of the device. And don\u2019t forget <b>sudo<\/b> to get appropriate permissions:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21078 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-4.png\" alt=\"Resize Linux partition: run the umount &lt;mounting point&gt; command\" width=\"599\" height=\"33\" 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-300x17.png 300w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/p>\n<p>Now run <b>fdisk<\/b> command with our test disk name as an argument and then type \u201cp\u201d to print the list:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21079 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-5.png\" alt=\"Resize Linux partition: run fdisk command\" width=\"610\" height=\"272\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-5.png 610w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-5-300x134.png 300w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>The last line contains important info about the current partition size and its bounds: \u201cStart\u201d and \u201cEnd\u201d. Remember \u201cStart\u201d value (2048 in this example). Now delete this partition by typing \u201cd\u201d and then type \u201cw\u201d to save these modifications:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21080 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-6.png\" alt=\"Resize Linux partition: delete partition by typing \u201cd\u201d and then type \u201cw\u201d to save modifications\" width=\"609\" height=\"173\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-6.png 609w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-6-300x85.png 300w\" sizes=\"auto, (max-width: 609px) 100vw, 609px\" \/><\/p>\n<p>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:<\/p>\n<ul>\n<li>You can extend the partition only to the space available at the \u201cright\u201d side. Simply saying, free space should be at the end of the resizing.<\/li>\n<li>You cannot shrink the current element to a size smaller than the actual data stored.<\/li>\n<li>It is a must to specify the same starting point as the previous partition while creating the new one. <b>Otherwise, you may lose your data!<\/b><\/li>\n<\/ul>\n<p>In our example, the new partition will be a smaller size so the <b>Shrink<\/b> operation will be performed. Let\u2019s run <b>fdisk<\/b> again and type \u201cn\u201d - creating the new one:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21081 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-7.png\" alt=\"Resize Linux partition: type \u201cn\u201d to create the new partition\" width=\"624\" height=\"475\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-7.png 624w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-7-300x228.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>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 <b>+&lt;size&gt;G<\/b> format to specify the desired partition size in Gigabytes (use \u201cM\u201d for Megabytes). Finish by typing \u201cw\u201d to save changes.<\/p>\n<p>Now we need to verify consistency by running <b>e2fsck<\/b>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21082 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-8.png\" alt=\"Resize Linux partition: verify partition consistency by running e2fsck\" width=\"609\" height=\"333\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-8.png 609w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-8-300x164.png 300w\" sizes=\"auto, (max-width: 609px) 100vw, 609px\" \/><\/p>\n<p>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 \u201cno\u201d to continue checking.<\/p>\n<p>Let\u2019s fix the error using <b>resize2fs<\/b> and then check the filesystem again:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21083 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-9.png\" alt=\"Linux partition: fix the mismatch in the file system configuration using resize2fs and then check the filesystem again\" width=\"603\" height=\"273\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-9.png 603w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-9-300x136.png 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/p>\n<p>Now the file system block size is the same as for partition configuration. Finally, let\u2019s mount the resized volume and check that our data is still here:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21084 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-10.png\" alt=\"Resize Linux partition: mount the resized volume and check that the data is still there\" width=\"602\" height=\"335\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-10.png 602w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/04\/Linux-partition-resize-10-300x167.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/p>\n<p>As you can see, our test file is still here and the partition has a new size.<\/p>\n<h2>Conclusion<\/h2>\n<p>That's it. Now you have fresh-new partitions.<\/p>\n<p>Keep reading on <a href=\"https:\/\/www.msp360.com\/resources\/blog\/how-to-find-your-aws-access-key-id-and-secret-access-key\/\">how to find your AWS access key ID and secret access key<\/a>, <a href=\"https:\/\/www.msp360.com\/resources\/blog\/amazon-ec2-vs-amazon-s3\/\">why Amazon's EC2 and S3 are fundamentally different types of service, <\/a><a href=\"https:\/\/www.msp360.com\/resources\/blog\/exchange-online-vs-exchange-on-premises\/\"><span data-sheets-root=\"1\">Exchange Online vs. Exchange On-Premises<\/span><\/a><span data-sheets-root=\"1\">,\u00a0<\/span><a href=\"https:\/\/www.msp360.com\/resources\/blog\/immutable-backups\/\">immutable backups<\/a>,\u00a0<a href=\"https:\/\/www.msp360.com\/resources\/blog\/what-is-rmm\/\">what is RMM<\/a>, <a href=\"https:\/\/www.msp360.com\/resources\/blog\/cloud-and-on-premises-backup-solutions-for-small-businesses\/\">cost-effective backup solutions<\/a>, <a href=\"https:\/\/www.msp360.com\/resources\/blog\/what-is-backup-software\/\">what is backup software<\/a>, and <a href=\"https:\/\/www.msp360.com\/resources\/blog\/sql-server-backup-and-restore\/\">an overview of SQL Server backup types<\/a>.\u00a0If you have any questions or comments regarding the article, let us know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will overview how to resize a partition in a Linux. We will use only built-in tools and commands.<\/p>\n","protected":false},"author":46,"featured_media":28440,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[877,885],"tags":[],"class_list":["post-28432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-articles","category-other"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/28432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/comments?post=28432"}],"version-history":[{"count":12,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/28432\/revisions"}],"predecessor-version":[{"id":60763,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/28432\/revisions\/60763"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/media\/28440"}],"wp:attachment":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/media?parent=28432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/categories?post=28432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/tags?post=28432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}