Skip to content

Corrupted my partition table the other day

I just had to share my recent experience.

I managed to corrupt my partition table the other day by doing a hard reset in the middle of an update. I guess it was in the middle of updating systemd-boot or something.

Of course, this was my work computer and I had a deployment to do by the end of the day.

Booted up a quite old Arch USB and while I feel confident fixing most things like this, seeing the partition table broken was something I hadn't seen before and knew was likely the end of everything on the drive.

I dd'd the first 10 gigabytes of the drive, the idea being that it would contain the broken partition table and the headers to the boot and root parturition that I could put back if I screwed up restoring it. Of course I'd be relying on not screwing up the rest of the drive... didn't have anywhere close to enough space anywhere to copy the whole drive.

fdisk simply couldn't read the drive at all. As I found out later it has never been the best with GPT, so I gave parted a try. Amazingly, after a little fiddling with less intrusive options and trying to get as much information about the state of my drive as possible, I decided to just let parted try to restore the partition table, and it worked!!

I then connected to wifi, mounted and chrooted. I then ran fsck, which did nothing and exited. Had a look at the documentation and it reads /etc/fstab. So I had a look at fstab and it was completely blank. This really threw me for a loop because there were comments in it and I wouldn't expect corruption to only remove the non-comment lines in it.

I knew I would have tried to keep things super simple when installing, for exactly the reason that a few years later I wouldn't remember the shenanigans I had done during install, but a blank fstab was not something I thought was possible at the time.

So whatever, I completed the update in chroot, re-installed systemd-boot and restarted, and it worked!! It has always been blank. I now have a comment in it saying that it really is supposed to be blank.

The whole ordeal took one and a half hours in total, and I got back to work and got my stuff done.

I'm still a little confused about my blank fstab, but I've since found out (re-discovered I guess?) swap partitions on GPT are actually automatically used, systemd-boot has all the details on mounting root in kernel flags, and I guess boot is somehow automatically mounted how it should be by something.

I would like to hear input on the blank fstab. Is it normal? I want to say that it's something I've never heard of, and thought was impossible... but I did install this OS at some point. Maybe I forgot to create it and everything just magically worked.

Edited 8 Jan 2021. We only hold this version.

17 points6 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
17 · 86% up
Kind
Text
ID
kt8nil

Author

1
posts
49
comments
0
media
View profile

6 comments

Your initramfs handles mounting / according to the root= option. Arch directly mounts the rootfs read-write, not read-only, so it doesn't need an fstab entry to remount it rw later like e.g. Debian does.

systemd-gpt-auto-generator handles both /boot and swap. (Not that Linux needs /boot to work; the bootloader has already loaded the kernel into memory anyway.)

6 points

That's awesome, I've done some looking and it seems to make sense that it works.

Is there anything I might want to worry about or am I really just fine leaving it blank then?

fsck doesn't do anything unless I specifically give it a partition, and while minor, I'm wondering if other more important things may rely on fstab that could be an issue in future.

3 points

You will need fstab entries if you want additional partitions or network file systems mounted automatically during boot

5 points

Yeah, I'd like to know how you are running with a blank fstab myself.

Glad you got your system working again though.

4 points

I've been looking and systemd-boot seems to use an EFI variable to make the kernel mount /boot, systemd-gpt-auto-generator automatically finds swap partitions on the root GPT partition table, and kernel flags will mount the root partition as it should be.

I really don't know if this was intentional or not, I don't think it was to be honest. Super cool to see it work anyways.

8 points

Wow. I had no idea it could do that. I've always been a GRUB guy, myself; but that's some impressive functionality!

2 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.