Resizing a partition in Linux - Bad magic number in super-block error
First, I'd like to be very clear on an important distinction:
- Partitions are simply pointers to where filesystems begin and end. On modern disks, these start and end points are expressed as sector values.
- Filesystems are complex data structures that reside within partitions (or other containers). Typically, filesystems are defined relative to the start point of the containing partition.
Your /dev/sda2
used to begin at sector 40,962,048. You changed it so that it now begins at sector 80,078,848. Thus, the critical early parts of the filesystem now begin outside the partition. An analogy might be if you somehow moved the front cover of a reference book, sitting flat on a table, a centimeter or so down without moving any of the pages of the book. When you opened the book, you'd find that the table of contents was missing, along with the first chapter or two. Those pages would now be floating freely, extracted from the book. You'd therefore be unable to find anything in the book except by reading the whole thing -- and even then, parts of it would be missing.
Generally speaking, any partitioning operation that involves moving or resizing the start of a partition is best done using GParted, which knows the proper order of operations for moving and resizing partition and filesystem data structures to keep everything working properly. Even GParted is not without its risks when resizing partitions, though -- especially not when the start point is involved, since this requires moving significant amounts of data, so a bug, power failure, hardware fault, or other problem can end up trashing the whole partition. If you must do it without GParted, you can, but you have to fully understand the distinction between a partition and a filesystem that I've outlined, and understand the implications of this distinction for the order in which you perform various operations (resize filesystem, move filesystem, change partition boundaries).
In your specific case, what I recommend is:
- Delete your new
/dev/sda2
. - Re-create your
/dev/sda2
using its original start and end sector values. Be sure these are exactly the same as they were before. - Check that the re-created
/dev/sda2
is accessible. - Back up your important data from
/dev/sda2
. - Re-evaluate whether you really need to move the start of the partition. I don't know what your ultimate goal is, so I can't do this for you. Perhaps moving the end point would work as well (and that would be safer); or maybe adding another disk would be a better option; or maybe you don't really need to repartition at all.
- If you must repartition the disk, use GParted to do the job.
Related videos on Youtube
![Joel G Mathew](https://i.stack.imgur.com/iV3u1.jpg?s=256&g=1)
Joel G Mathew
Full Stack Developer with skills in Python, Vue, Flutter/Dart, Perl, PHP, C, Javascript, Bash shell cripting. Android enthusiast. Oh.. I'm a Doctor and an ENT specialist in the real world.
Updated on September 18, 2022Comments
-
Joel G Mathew almost 2 years
I was trying to resize my partition with parted and resize2fs.
I tried the following:
#parted Partition Table: msdos Number Start End Size Type File system Flags 1 2097kB 21.0GB 21.0GB primary ext4 boot 2 21.0GB 500GB 479GB primary ext4 3 500GB 500GB 536MB primary linux-swap(v1) (parted) rm 2 (parted) mkpart Partition type? primary/extended? primary File system type? [ext2]? ext4 Start? 41GB End? 500GB (parted) q Information: You may need to update /etc/fstab. #resize2fs /dev/sda2 resize2fs 1.42.5 (29-Jul-2012) resize2fs: Bad magic number in super-block while trying to open /dev/sda2 Couldn't find valid filesystem superblock.
Unfortunately I can't understand why this doesn't work. It was an ext4 partition. I would like to resize the partition without loss of data.
fdisk list before operation: Device Boot Start End Blocks Id System /dev/sda1 * 4096 40962047 20478976 83 Linux /dev/sda2 40962048 975718399 467378176 83 Linux /dev/sda3 975718400 976764927 523264 82 Linux swap / Solaris Now fdisk shows: Device Boot Start End Blocks Id System /dev/sda1 * 4096 40962047 20478976 83 Linux /dev/sda2 80078848 975718399 447819776 83 Linux /dev/sda3 975718400 976764927 523264 82 Linux swap / Solaris
-
Joel G Mathew about 9 yearsThe problem is that this is a lowend dedicated server, and running gparted gui is not possible (I wouldnt want to have to install Gnome and VNC just for the sake of partitioning.). Isn't "resizing" possible from the command line rescue mode?
-
Rod Smith about 9 yearsAs I said, it is possible, but it's risky and requires expertise. If you're currently booted from the partition you want to move and resize, forget it; AFAIK, it can't be done safely. Since you pretty much must boot something else, then, you might as well boot a utility with a GUI and run GParted. If you're not booted from the partition you want to move, see this. In the future, LVM is much more flexible if you need to do such things.
-
twicejr over 7 yearsHow about mounting the root read-only, dd'ing the whole disk over the network and then practice using loopback device using ` sudo losetup -Pf [imagefile]`? Then you could even try running the image as a virtual machine harddrive to see if all went well