Q: What is the safe way to change partition size?

My root partition is too small, and my home partition is too big. I do not want to delete and start again, but to resize the root and home without reinstalling the data. Any software?

A: There is no way of resizing ext2 partitions under Linux. (I think Partition Magic claims to do so, but there have been report of problems.) [2004/12 addition: It now is reported to work well.] What I'd do is:

Assuming this is your partition table:

Dev Type Mount Size
sda1 nt40 nt40 1992M
sda2 linux / 1498M
sda3 swap 117M
sda4 extended 5036M
sda5 swap 117M
sda6 home /home 4910M


-backup your /home on to your tape drive.

-check and make sure the backup worked

-use fdisk to delete the home partition and create several smaller partitions:(make /dev/sda6 about 800 megs)

fdisk /dev/sda

-create a file system on /dev/sda6:

mke2fs /dev/sda6

-mount it and copy all files in /usr to sda6:

mount /dev/sda6 /mnt
cd /usr
ls (sanity check)
cp -a * /mnt
cd /mnt
ls (sanity check)

-change fstab to mount /usr/ as /dev/sda6:

/dev/sda6 /usr ext2 defaults 1 2

Don't leave this one there:

/dev/sda6 /home ext2 defaults 1 2

-reboot and check that everything is okay

mount (Did sda6 appear mounted on /usr?)
startx (Did X start up?)

-reboot into single user mode, umount /usr, and erase the /usr file on sda2:

init 1
cd /
umount /usr (if this doesn't work "fuser -k /usr" and then try again.)
mount (sanity check)
cd /usr
ls (sanity check)
rm -rf *

-reboot and check that disk space
df (or df -h)

Now you have plenty of space in /. You decide that there is enough space on sda2 for all the files in /home. In that case, just restore them into /home. Otherwise, create a new partition in the empty space on your disk via fdisk. Do a mke2fs, and edit the fstab to add an entry for its partition.)

Update a/o December 1999: In addition to Partition Magic, there are now several projects to non-destructively resize Linux-native ext2 filesystems. Using any of these should be presumed risky, but they are listed in the name of completeness:

Lennert Buytenhek has written "GNU ext2resize" http://ext2resize.sourceforge.net/). Ted T'so has produced "resize2fs" (ftp://ftp.powerquest.com/pub/utilities/resize2fs.rpm as part of his work on ext2 code for Partition Magic. (You can unpack the .rpm file for use on non-RPM-based systems using rpm2cpio, http://linuxmafia.com/pub/linux/utilities-general/rpm2cpio.) Andreas Dilgar is developing "online ext2" (which allows resizing ext2 partitions while they're in use (http://www-mddsp.enel.ucalgary.ca/People/adilger/online-ext2/), and Mike Field is working on "ext2end" http://linux.msede.com/ext2/ext2end.html). MandrakeSoft's DiskDrake (http://www.linux-mandrake.com/diskdrake/) is a graphical, menued utility that requires X and Perl/GTK. Last, there is Andrew Clausen's "GNU Parted" (http://www.gnu.org/software/parted/).