workaround for parted bug using fdisk and resize2fs
Linux - NewbieThis 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!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 (bugzilla.redhat.com/bugzilla/show_bug.cgi?id=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?
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.
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.