Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I increase the size of the root partition of a system at runtime?

I have a partition that is not allocated after the root partition (which is also ext4), how can I add that unallocated space to the space allocated to the root partition without having to shutdown the server?

share|improve this question
2  
I hate to sound like a stick in the mud, but this entails a fair bit of risk? Why does this need to happen? Is uptime the main constraint? –  Dogbert Sep 30 '13 at 17:28
add comment

8 Answers

up vote 8 down vote accepted

It is not possible to extend an ext4 root partition at runtime, you must shutdown the system and extended using a live cd or booting from another partition.

share|improve this answer
16  
It should be noted that resizing an Ext4 partition while Linux is running is possible... just not the root partition. –  Nathan Osman Jan 30 '11 at 19:59
    
In fact, I had confirmation from other forum. For completeness, the following are the most appropriate livecd and backup your data before any change is always good: gparted.sourceforge.net/livecd.php or partedmagic.com/doku.php?id=start –  BonboBingo Jan 30 '11 at 21:59
8  
If you are using LVM it is not only possible but rather easy. –  psusi Jan 31 '11 at 14:20
15  
This answer is factually wrong. The Linux kernel supports resizing partitions online, including the root partition while mounted. –  Caleb Mar 18 '13 at 20:22
1  
Same here, I've done this plenty of times before... resize2fs /path/to/device –  tobias.mcnulty Sep 25 '13 at 20:32
show 1 more comment

It is possible to do a on-line resize of a ext4 filesystem, even if it's your root partition. Use the resize2fs command.

sudo resize2fs /dev/sda1

EDIT: On-line shrinking is not allowed:

root@brunojcm-htpc:/home# resize2fs /dev/sda5 2654693
resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/sda5 is mounted on /; on-line resizing required
resize2fs: On-line shrinking not supported
share|improve this answer
6  
From man resize2fs: The resize2fs program does not manipulate the size of partitions. If you wish to enlarge a filesystem, you must make sure you can expand the size of the underlying partition first. This can be done using fdisk(8) by deleting the partition and recreating it with a larger size or using lvextend(8),if you're using the logical volume manager lvm(8). This question is about resizing the partition, not the filesystem. The distinction is subtle but very important. –  Eliah Kagan Jun 3 '12 at 7:07
3  
You can use fdisk to delete the root partion and then recreate it at the same starting block. fdisk will write out the change, but it won't take effect till after a reboot. after the reboot you can use the resize2fs program to send the disk to fill the partion. –  Jbecwar Jun 14 '12 at 15:15
2  
I have just resized an ext4 root partition online. Therefore I can confirm it's possible. But instead of passing /dev/sda* as parameter to resize2fs, you need to pass the logical volume name. –  CDR Dec 4 '12 at 22:37
3  
I find the first paragraph of the resize2fs manpage most interesting for the initial question: The resize2fs program will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located on device. If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.). –  mo' Dec 23 '12 at 14:33
    
Worked for me :) –  StandDuPp Nov 28 '13 at 8:57
add comment

There are two steps to this: First, the partition must be resized. If you're using LVM, it's easy; if you're using classic partitions, it's a bit more complicated, and might require a reboot (though you never have to boot another system or live CD).

One fragile but feasible approach (worked for me) is to use fdisk by first deleting the partition, then carefully recreating it with a larger size at the same position. You can do this while the partition is mounted, but you will need to reboot for the kernel to notice the changed partition table.

Example:

$ sudo fdisk /dev/sda

Command (m for help): p

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     9437183     4717568   83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): p

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759

Command (m for help): p

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    10485759     5241856   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Again, it is critical that the new partition starts at the same block as the old. The Id should also match (83 for Linux systems). Be prepared to lose all your data at the slightest typo.

By now it should be apparent why people recommend using a live CD. ;-)

However, once the partition is resized (and the system rebooted, if necessary), it's a simple matter of running resize2fs on the file system, and you can do this even when it's mounted as the root partition.

Example:

$ sudo resize2fs /dev/sda1
share|improve this answer
4  
This worked perfectly for me. However I did additionally ensure that the boot flag kept is original state. –  Augustus Kling Aug 10 '12 at 20:56
1  
+1, Worked for me too, thanks :) –  Reddy Sep 13 '12 at 11:30
    
Very useful article on the same topic: underscore.at/underscore/newsshow.xml?id=69 cfdisk has helped me a lot. –  Frosty Z May 27 '13 at 14:53
    
The question asked how to do this without shutting down. You will need a program that can update the kernel entries for a partition table of a disk w/ mounted partition(s). I've read that running partprobe [<device>] should work, but I don't currently have a system where I can test it. –  jbo5112 Dec 2 '13 at 18:22
    
@jbo5112: As fdisk says, partprobe or kpartx may work instead of a reboot; see also this question. Even if you reboot, the solution is still preferable to using a live CD when it comes to downtime, where a simple reboot can be less than 10 s for a virtual machine. It's also faster in operator time, which is why I usually use this approach myself. :) –  Søren Løvborg Dec 3 '13 at 18:07
add comment

You could also just make use of GParted - as long as the partition you are resizing is not the one you booted from - else I suggest the live CD option is somewhat easier for newbies.

GParted basically does all of the steps - just based on a GUI fronted.

share|improve this answer
    
I booted my system with Ubuntu 12.04 Live CD and i resized ext4 partition with GParted. Worked good for me. Anyway, before this operation I backed up all my important data. –  StandDuPp May 28 '13 at 20:16
add comment

Just finished resizing an ext4 root partition on a live system while the root was mount.

[root@habib i686]# resize2fs /dev/vg_habib/lv_root
resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/vg_habib/lv_root is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 10
Performing an on-line resize of /dev/vg_habib/lv_root to 38427648 (4k) blocks.
The filesystem on /dev/vg_habib/lv_root is now 38427648 blocks long.

[root@habib i686]# 
share|improve this answer
add comment

only you need bootable or live cd like hiren's bootcd

and this is link http://www.hirensbootcd.org/download/

burn it on cd and restart your computer choose cdrom to boot from it and open cd from menu choose parted magic 6.7
enter image description here

share|improve this answer
add comment

As noted previously works fine just need to reset boot flag

run 'parted'

parted /dev/sda

verify partition number

(parted) print

reset boot flag on partition number '1' in this case

(parted) set 1 boot on
(parted) quit
share|improve this answer
add comment

As stated before: -exanding live from a root system is possible.(no difficulties, as the boot section ain't to be moved)

-shrinking a live root partition needs to be done from external boot device (boot from live system cd/usb-stick), as if theres any fault, mismatch ..whatever..your system hangs, nedds to be rebooted and will eventualy not be able to boot correctly. Any sort of "but I did it and it works" is pure luck.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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