Stupid Trick: Changing the UUID in /etc/fstab from an emergency shell with screen


So. I installed a new VM with /boot formatted as btrfs. Except pygrub apparently doesn’t like btrfs, so it refused to boot.

And I refused to reinstall. So it looked like an impasse – I didn’t want to mess around with chroots and installing grub2, but it couldn’t boot without said messing around.

And then I had a thought – pygrub doesn’t care that grub2 isn’t installed, it just cares about the location of the grub.cfg file. So it should be possible to move stuff off the btrfs partition onto an ext4 partition!

One lvcreate, mkfs.ext4, xm blk-attach 0 /dev/domU/rawhide-boot /dev/xvda, mount /dev/xvda1 /mnt/oldroot, mount /dev/domU/rawhide-boot2 /mnt/newroot, cp -r /mnt/oldroot/* /mnt/newroot, umount /mnt/*root, xm blk-detach 0 xvda later, I’ve got the VM at least showing the plymouth boot screen.

YAY! Except it dies partway through with a systemd error – a fsck failed, meaning it can’t continue. Uh oh.

First thought: Go poke at systemd, try to disable fsck. Nope, systemctl disable fsck…service refuses to work without the exact name. And the terminal actually clips the fsck service name because it’s using /dev/disk/by-uuid/36longcharacterstring. I’m not a happy guy, I can’t even see what I’ll need to type out!

So, second thought: Ok, why does it think the disk is still present then? Check /etc/fstab – /boot is listed there with UUID=olduuid. Ok… so, I should be able to replace it with the new uuid. But what is the new UUID? Looking at the header of /etc/fstab, it lists a few possibilities. findfs looks like the most likely. But… it wants a label or uuid. Trying label=/boot doesn’t work. Ok, how about blkid? Oh, hey, that’s looking good. It’s giving me a bunch of UUDs. But how to get it into /etc/fstab?

And this is the stupid trick: screen has a text buffer that you can copy stuff into. I recently used it to capture VM logs and save them to a file using the copy into buffer function (Ctrl+a, [), then printing them out into a open vim window that was in insert mode (with Ctrl+a, ]). So, it was a simple matter to jump into copy mode, select the new UUID, jump over to the vim window open to /etc/fstab, change to overwrite mode (because this was in place, and I didn’t want to have to delete the old UUID when I could just overwrite it), and empty the buffer.

A :wq and reboot later, the VM comes up fine.

(Of course, I had to do a ifup eth0 and  yum install screen vim to actually get screen and vim. Why those aren’t included in the default F16 is beyond me…)

  1. #1 by AC on April 20, 2014 - 3:42 pm

    Years later, this was useful.

    You can also do this:
    blkid >>/etc/fstab
    then cut, paste, edit /etc/fstab

    thanks

(will not be published)