28

What's the easiest way to resize an ext4 partition (or any type partition depending on the method) from the command line (potentially with the fewest commands, but also the easiest to understand)?

Using a tool like Gparted is obviously easy in a GUI, but what about in the command line? I guess text-based GUIs can count for the answer too since it's technically still in the command line. It just needs to be easy.

By partition I mean a simple partition on a single disk of a personal computer (e.g. on a laptop). For example, I want to resize /dev/sda4. There's no RAIDs, there's not more than one disk drive, there's not anything complicated here. Just a simple partition on a single disk (/dev/sdaX on /dev/sda).

  • 1
    You probably know this, but Gparted is a GUI front-end to GNU Parted. Previous to Parted 2.4, you could resize, but this has since been removed. I suspect the only way is do it manually, resizing partition table, creating device maps, then resizing the file system. – Sparhawk Jun 17 '14 at 12:08
  • Have you seen this article about resizing partitions? – psimon Jun 24 '14 at 15:01
  • I haven't seen that specific one, but the gist of it is that you delete the partition then make a new one of the size you want. But what I'm inherently doing is not "deleting" anything, just resizing. The best answer to this question would likely be a way to "resize" a partition, not delete one and create a new one, and the resize2fs steps would be entirely unnecessary and happen in the background (because naturally and obviously the user also wants to use all the space in the partition so it shouldn't be an extra step). – trusktr Jun 25 '14 at 3:03
10

You can use fdisk to change your partition table while running.Refer this link http://codesilence.wordpress.com/2013/03/14/live-resizing-of-an-ext4-filesytem-on-linux/

  • 13
    You should put the relevant information from the link, into your answer, because of link rot. Also, wordpress.com is currently blocked where I live (China), so I can't even see the "answer". – WormFood Oct 11 '16 at 13:32
  • 1
    @Thushi, output of fdisk -l paste.ubuntu.com/24757891. I want to merge sda5 and sda6 as sda6. Does it damage my data? – alhelal Jun 3 '17 at 8:42
6

gparted uses resize2fs to change the partition's size. It doesn't take many arguments. Below are the ones I've found useful.

-M shrinks to the file system's minimum size.

-p shows a percentage indicator.

-P prints the file system's minimum size and exits.

  • resize2fs doesn't alter the partition table at all, it changes the size of a filesystem. After using it you'll have to resize the partition that the filesystem was on accordingly. – bool3max Apr 14 at 19:10
5

If you're going to be increasing the size of both the partition and the filesystem, then first run fdisk to increase the size of the partition, and then run resize2fs to increase the size of the filesystem.

If you're going to be shrinking the size of both, run resize2fs first and then run fdisk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.