Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-29-2004, 10:54 PM   #1
LQ Newbie
Registered: May 2004
Posts: 6

Rep: Reputation: 0
workaround for parted bug using fdisk and resize2fs

I need to shrink my root partition-- I let anaconda partition my disk because I was tired and thought it would be harmless. Turns out, due to bug 90894 (
I am hosed. Here is an exerpt from bugzilla:
" Any ext2/ext3 filesystems created during the installation procedure
of recent RedHat/Fedora Linux versions, which use the e2fsprogs for
this task, cannot be resized, moved or copied anymore using parted.
In other words: Parted can basically not be appplied to those
partitions/filesystems anymore at all. Unfortunately, the utilities
fdisk, resize2fs, etc. are not really alternatives (i.e. inconvenient
to use) when you have to resize and move partitions and filesystems
on a densely packed hard drive."
In summary, I cannot use parted to shrink my root partition so I need to use fdisk and resize2fs to do it, but I need some help.

This is my df -h output:
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 18G 2.2G 15G 14% /
/dev/hda1 99M 9.0M 85M 10% /boot
none 251M 0 251M 0% /dev/shm

and fdisk -l:

Disk /dev/hda: 20.0 GB, 20003880960 bytes
255 heads, 63 sectors/track, 2432 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 2302 18386392+ 83 Linux
/dev/hda3 2303 2432 1044225 83 Linux

So I have a lot of unused space on root, a /boot partition, and swap. I only have one disk and no tape backup mechanism available. My online research has led me to believe that if I delete the root partition with fdisk I will no longer be able to access the data, but I will not lose it. What is the difference and why does the man page of resize2fs say:
If you wish to shrink an ext2 partition, first use resize2fs to shrink
the size of filesystem. Then you may use fdisk(8) to shrink the size
of the partition. When shrinking the size of the partition, make sure
you do not make it smaller than the new size of the ext2 filesystem!
as if there is no loss of data is about to occur.

I don't seem to have anywhere to store anything as virtually the whole disk is on /root so I cannot backup with dump/restore.

I have a shaky plan, but I need help with where I am wrong or missing a step. So please refer to the following:
1) log out and boot into rescue mode; become root
2)turn off swap, delete swap partition with fdisk
3) revert root filesystem to ext2
4) resize the root filesystem with resize2fs **how can I figure out how small I can make it?
?5)create a small partition where swap was and dump/restore there? with 251M it seems unlikely that this would work.
6)delete the root partition and recreate it with the exact same starting position, to include the new resized root fs
7) make new partitions as desired with free space
7) change fstab to reflect changes to table
?will I be able to reboot?

Old 07-30-2004, 12:00 AM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
The idea of deleting a partition is abit scary but really no harm should occur if you DO NOT FORMAT anything. Also, it's important to resize only on the ending side of a partition. The begining needs to be left alone.

The output of your fdisk shows /dev/hda3 as type 83 which is wrong, if that is your swap partition, it should be type 82. At any rate, that gets deleted for now.

Boot up with a rescue cd and proceed like this....
In this example, I show how to resize /dev/hda2 to an 8GB partition.

e2fsck -f /dev/hda2
resize2fs /dev/hda2 8000M

fdisk /dev/hda
delete the partitions /dev/hda3 and /dev/hda2
recreate the partition /dev/hda2 with the starting point at the default location and the ending point at +8000M
Save and exit fdisk for now.
Then run the resize utility withou any size arguments to make sure the file system fits the partition.
resize2fs /dev/hda2

If that gives you trouble, you could start out with a lower number when first using resize...
resize2fs /dev/hda2 7500M
Then when you create the partition at +8000M and re-run the resize utility with no size arguments, it should work.

If all goes well, you can recreate the swap partition with -t 82 and mkswap.
Then you can create the storage partition.

Last edited by homey; 07-30-2004 at 12:11 AM.
Old 10-05-2004, 01:52 AM   #3
LQ Newbie
Registered: May 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Talking thanks --it worked!

Thank you homey--this was indeed as simple as you said--and your advice helped.
Two more things to keep in mind:
1) I had an ext3 root filesystem and resize2fs does not work on ext3, so after I booted into rescue mode with nothing mounted(choose SKIP), I used tune2fs to revert to ext2:
#tune2fs -O ^has_journal /dev/hda2

2) resize2fs' size parameter is in blocks(4K blocks to be exact), not bytes. So I had to figure out how many blocks were
there(df -k) and then the number I wanted, divided by 4.

3) Don't forget to update fstab, which I did after I finished with fdisk, and reverted /dev/hda2 back to ext3:
#tune2fs -j /dev/hda2
I then mounted /dev/hda2 in a temporary directory and used joe to udpate the file.

Thanks--I hope this helps someone else as much as it helped me!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
partition resizing using parted...bad memories of fdisk rextor Linux - General 1 07-30-2005 11:34 AM
What app can REALLY delete a partition? (not fdisk, parted, etc...) kornerr Linux - General 4 05-28-2005 01:14 PM
fdisk/parted/cfdisk: command not found indole Linux - Software 2 02-17-2005 01:08 PM
fdisk, parted questions? darkleaf Linux - Software 2 10-14-2004 05:07 AM
working around PARTED bug 90894 using fdisk and resize2fs carneros Red Hat 0 07-29-2004 03:42 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration