Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: Shrinking an ext3 filesystem to add a new partition.
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 20 Jul 2005
Posts: 4
Location: Boston

PostPosted: Wed Jul 20, 2005 4:02 am    Post subject: HOWTO: Shrinking an ext3 filesystem to add a new partition. Reply with quote

Parted is a poor program for ext3 which (according to rumour) has an old version of the ext filesystem resizing programs which makes it unable to deal with ext3.

While this seems like a stupid bug, here's an easy way to do it manually.

Now, for this example, I'm using the case of my computer. I'm trying to create a new partition to use as an afs cache, but don't have any leftover space.

Here's the partition table beforehand:

Disk /dev/hda: 200.0 GB, 200049647616 bytes
255 heads, 63 sectors/track, 24321 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1       20182   162111883+  83  Linux
/dev/hda2   *       24198       24203       48195   83  Linux
/dev/hda3           20183       24197    32250487+   5  Extended
/dev/hda4           24204       24321      947835   82  Linux swap / Solaris
/dev/hda5           20183       20306      995998+  83  Linux
/dev/hda6           20307       22738    19535008+  83  Linux
/dev/hda7           22739       22981     1951866   83  Linux
/dev/hda8           22982       24197     9767457   83  Linux

You can ignore the fact that hda3 goes over the cylinders for hda5-8, it's because hda3 is an extended partition and 5-8 are it's logical partitions.

In any case, the goal is to shrink hda8 from 10 GB to 8 GB to make room for a 2 GB afs partition.

So, step one, for me, the filesystem was mounted on /var, so I needed to boot into single user mode. This should be doable by a number of methods, I prefer to leave a single user mode boot entry in grub, but you can also tell it at the grub menu to enter additional commands. You should include

Now then,

umount /dev/hda8
e2fsck -f /dev/hda8
resize2fs /dev/hda8 7000M

i.e. first unmount the filesystem (don't mess with mounted filesystems), then do an e2fsck -f in order to make sure it's in good working order, and then resize it to a size significantly smaller than the target size. The general idea here is to shrink it to a completely safe size, and then we'll resize it later to the size of the new, smaller, partition. You don't need a lot of leeway here, as long as the filesystem is smaller than the new partition.

I was going for a new 8 gig partition, so I gave it 7000M.

After this is done,

cfdisk /dev/hda

This is my preferred way to manipulate partitions. Sorry you prompt based weenies, I like ncurses =)

Delete the old hda8 partition.

Create a new hda8 partition of the new size.

Create the second new partition for afs (obviously not necessary if you plan to use it for windows or something).


REBOOT -- this is critical, or you will get weird cylinder matching errors (at least, my system did). I don't understand why, but it seems that linux in general, or perhaps the E2fsprogs in particular, do not reread the partition table correctly after it's been changed. I suspect that i never noticed this in the past because I was always creating a filesystem on a partition that had previously existed.

Boot again into single user mode.


unmount /dev/hda8
e2fsck -f /dev/hda8

This time, you want to expand the filesystem to the partition size. This is done with

resize2fs /dev/hda8

Giving it no size at the end defaults to expanding all the way.

I'd suggest rebooting again for good measure after all this and running e2fsck again, though you're fine booting into normal mode instead of single user.
Back to top
View user's profile Send private message

Joined: 05 Apr 2003
Posts: 339
Location: Farnborough, UK

PostPosted: Fri Jul 22, 2005 5:12 pm    Post subject: Instead of rebooting . . Reply with quote

Does hdparm -z /dev/hdX fix the problem? It may not, as fdisk and cfdisk do the same thing, but you never know.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum