0

I have a emmc memory containing a working Ubuntu system. I want to connect it to my Ubuntu PC and shrink the rootfs partition in order to create a new partition in the resulting free space. I tried both with gparted (using the resize GUI and clicking on Apply) and fdisk but the filesystem gets corrupted. This is the commands I used with fdisk (the rootfs partition is in /dev/sdb5):

  • fdisk /dev/sdb
  • d 5
  • n
  • partition number: 5
  • first sector: as default
  • last sector: +12G
  • w

Then running e2fsck /dev/sdb5:

The filesystem size (according to the superblock) is 3784187 blocks The physical size of the device is 3145728 blocks Either the superblock or the partition table is likely to be corrupt! Abort?

These operations used to work with a microSD card instead of the emmc memory. What could be the reason?

  • So what have you done with gparted so far, and when? Before or after running fdisk? – mook765 May 27 at 13:59
  • I used the GUI to resize the partition. I did it after a new flash, with a clean Ubuntu installation – firion May 28 at 10:09
1

fdisk can be used to manipulate partition tables. But fdisk does not manipulate what's in the partition. A partition usually contains a file-system, the size of the file-system needs to be reduced before you reduce the size of the partition with fdisk.

  • increase partition size: use fdisk first and then resize2fs
  • reduce partition size: use resize2fs first and then fdisk

If you already created a new formatted partition in the new unallocated space, your file-system will be damaged, probably beyond repair. A part of your file-system would be overwritten.

If you didn't create a new formatted partition yet, you can attempt to repair the damage:

Increase the size of the partition with fdisk, at least to it's former size, so that the file-system fits properly in it, then run e2fsck on that partition again to check the consistency of the file-system. If it's ok, you can start over with resizing the file-system with resize2fs first and reducing the size of the partition with fdisk in the second step.


Maybe better to use GParted to manage your partitions, Gparted takes care of all the necessary steps and adapts the file-system size to the new partition size automatically.

  • I used gparted first, but I got the same problem. That's why I tried with fdisk – firion May 28 at 8:04
  • @firion Your file-system might be corrupted before your first attempt with GParted, try the solution I described. I can't guarantee that it solves the problem, but worth to try. How full with data was the partition before? You can't make the partition smaller than the data it has to hold. – mook765 May 28 at 8:08
  • It was a clean Ubuntu that I had just flashed. I am getting the same problem even when I try to grow the partition. For example, if I have a 2GB partition with the rootfs and some unallocated space, if I grow it with gparted and then run e2fsck, I get the error and the filesystem is corrupted. – firion May 28 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.