Monday, December 08, 2008

fstab repair

Sometimes, bad things happen to good people. That's sorta unfortunate.

Sometimes, bad things happen to me, and that's really bad.

Today, I managed to make a typo in an entry in /etc/fstab. So, when I rebooted, the filesystem check failed (since I had spelled the path to the filesystem wrong and apparently the boot scripts aren't smart enough to recognize the difference between a non-existent device and a bad superblock). I needed to fix the typo in /etc/fstab, but the root filesystem was mounted read-only.

So, if you've got a busted /etc/fstab with a root filesystem that is an LVM partition, here's what you do.

First, you're going to need some sort of boot media, I use NimbleX-2008 for helping me through screwups like this. It's a 200 MB download from:

Boot to a command prompt or X and open a terminal window. If you don't use LVM for your root partition, you will probably already have your root partition mounted for you under /mnt/something-or-other. However, if you do use LVM, you need to know the name of your volume group. Mine is 'thump'.

Activate the volume group with (this is the step you won't remember if you're me):
lvchange -ay thump

Use lvscan to make sure it's now active:

Then create a mount point for it and mount it. For me, that looked like:
mkdir /mnt/thump.root
mount /dev/mapper/thump.root /mnt/thump.root

Next, fix the silly typo in the fstab -- making sure to fix the one on your real disk, not the NimbeX instance's.
vi /mnt/thump.root/etc/fstab

Reboot, and you have your computer back. And now, I don't have to hunt through google to remember to use vgchange -ay to be able to see my root partition the next time I make this goof.

We now return you to your regularly scheduled economics and policy musings. :)

No comments: