1 (edited by soupcan 2010-06-20 07:50:21)

Topic: [Solved]Ubuntu10.04-Ext4-Gparted0.5.2-9-error after partition shrink

Ubuntu is installed on /dev/sda1, which I recently resized to make approximately 100gb of unallocated space. After the resize, Ubuntu will drop to an intramfs shell instead of booting. Attempting to mount /dev/sda1 fails, pointing me to dmesg. Dmesg outputs this:

EXT4-fs: bad geometry: block count (large number) exceeds size of device (another large number) blocks

fdisk -l -u output:

 Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders total 625142448 sectors
Units = sectors of 1*512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk Identifier: 0x00013224

     Device    Boot     Start              End               Blocks     Id  System
/dev/sda1      *       2048   391134554  195566253+    83     Linux
/dev/sda2     601751550   625141759        11695105      5  Extended
/dev/sda5     601751552   625141759        11695104     82 Linux swap/Solaris

parted /dev/sda unit s print output:

 Model: ATA WDC WD3200BEVT-6 (scsi)
Disk /dev/sda: 625142448s
Sector size (logical/physical) 512B/512B
Partition table: msdos
Number   Start              End                Size                 Type         File System     Flags
1             2048s            391134554s  391132507s    primary     ext4                boot
2             601751550s  625141759s  23390210s      extended
5             601751552s  625141759s  23390208s      logical       linux-swap(v1)

The megabyte of unused space before sda1 was present before partitioning. sda1 contained approximately 17gb of data at the start of the partition before the resize. The partition has not been moved, only resized. I do not believe that any data has been written to it.

This is not my computer, and the only backups (if any) would be on a external hard drive that broke a few months ago. Therefore, it would be best if the system could be restored to working order without reformatting/reinstalling. As GParted has left my data untouched in the past, I assumed that it would do so this time. Of course, it's my fault that I didn't make a backup first.
Any and all help is greatly appreciated.

2

Re: [Solved]Ubuntu10.04-Ext4-Gparted0.5.2-9-error after partition shrink

Problem solved through the following steps:
Backup of mbr through dd:

dd if=/dev/sda of=mnt/usb bs=512 count=1

Output of dmesg showed that ext4 expected a filesystem of 601747456 sectors in size. This was determined by multiplying the value given after "block count" by 8 to convert to sectors.
dmesg output:

[ 2805.943334] EXT4-fs (sda1): bad geometry: block count 75218432 exceeds size of device (48891563 blocks)

On to repairing. Creating backup of partition table with sfdisk:

sfdisk -d /dev/sda > PT.txt

Edit PT.txt with any editor. In PT.txt, the line referring to /dev/sda1 was changed to the following:

/dev/sda1 : start=     2048, size=601747456, Id=83, bootable

The value of "size=" was changed from its previous value to the value expected by ext4.

Then, with the corrected PT.txt, the partition table was changed to the new values:

sudo sfdisk -f /dev/sda -O PT.save < PT.txt

After this, /dev/sda1 mounted cleanly with

sudo mount -o ro /dev/sda1 /mnt/sda1

Filesystem check showed no errors, no data was lost, and the system rebooted properly. Thanks very much to thune3, who walked me through fixing this over IRC.

3 (edited by gedakc 2010-06-20 19:30:47)

Re: [Solved]Ubuntu10.04-Ext4-Gparted0.5.2-9-error after partition shrink

Thank you very much soupcan for posting the problem you experienced, and especially for following up with the steps used to resolve the situation.  smile

I will add a link to this post in the following post in the hope that this will help others resolve similar situations:
WARNING! Problem Resizing File Systems with GParted

EDIT:
With the knowledge you have gained, perhaps you might consider writing a tutorial on how to resolve the problem?

4 (edited by boukouvalas 2010-07-07 14:33:57)

Re: [Solved]Ubuntu10.04-Ext4-Gparted0.5.2-9-error after partition shrink

Also, this was very useful to me, I had the same problem today, after using a gparted live cd of 0.5.2-9 release.

I also made a notice to all friends at GreekLUG forums.

Also, just to inform you that even if you create a new partition to the free space, and then delete it, that does not effect the files or the filesystem of your non-free remaining mother partition.

5

Re: [Solved]Ubuntu10.04-Ext4-Gparted0.5.2-9-error after partition shrink

soupcan wrote:
sudo sfdisk -f /dev/sda -O PT.save < PT.txt

Be careful when you use the '-f' ("force") option; make sure you really know what you are doing.  This could cause trouble in case a partition is mounted or in use as swap, for example...

6

Re: [Solved]Ubuntu10.04-Ext4-Gparted0.5.2-9-error after partition shrink

quite possibly the most useful Linux post I have ever seen.  After a RAID 1 drive failed on me with the aforementioned bad geometry error, mdadm synced the bad drive on top of my good one.  AWESOME!! 

Using the tools here I was able to fully recover both drives.  And, even after I mistakenly overwrote the partition table on another drive in the process (I know, it takes a special kind of moron to do that) I was able to recover that as well after using testdisk to recover the -O PT.save file.

Awesome help.  Thanks you all.