4

First off, yes, I did, in fact, suspect that changing my filesystem from ext4 to btrfs would break GRUB and fstab.

Now, here's what happened. I converted the filesystem seamlessly to btrfs and that worked great. Now, I can't seem to boot, as I get a "GRUB error: unknown filesystem." How can I fix GRUB and fstab to be updated with the new filesystem?

2
  • You need to reinstall grub, which is covered by plenty of other questions this could be duped against.
    – psusi
    Dec 26, 2012 at 3:01
  • What grub version are you using? If you have room, it might be simpler to create a small boot partition using an ext filesystem and boot from that.
    – Paul
    Dec 26, 2012 at 3:50

1 Answer 1

5

This is a long and strange process, but it works.

Part One: Creating a BIOS Boot partition.

First problem was that I'm using a GPT partition table. Just because you can install Linux and boot to it somehow doesn't mean that GRUB is working fine. I would assume that if I could boot previously, then things are okay, but that's not exactly the case. Create an unformatted partition with the bios_boot flag set. The best way to do this is right from the get-go before you install anything on your hard disk, but it'll still work if you need to do it later, albeit you'll have a weird partition at the end of your disk. I like weird things to be at the start of the disk. In any case, here's what you need to do.

Due to the way that GPT is 1,000,000 times more efficient and intelligent (and yet still somehow so much less supported) than MBR, there is no space on the disk for the GRUB installation. Usually, GRUB installs itself at the beginning of the disk in-between partitions due to the fact that the MBR requires a gap after it. Weird? Totally, but that's just the way it is. Let's get started.

First, make sure you've got the right drive. Do not continue until you know that /dev/sdX is the drive you think it is. Now that you've done your due diligence, do it again. Three times, just to be sure. Ok, let's move on.

Now, install parted (# apt-get install parted) and start it up targeting your drive:

$ sudo parted /dev/sdX

If you haven't already, set the boot record label to GPT:

(parted) mklabel gpt

Next, create a partition for the BIOS boot stuff. I'm putting mine at the beginning of the disk, so here's what mine looks like:

(parted) mkpart primary 0MB 1MB

You should change the numbers above to tell parted where you want the partition to start and stop, respectively.

Now, let's set the flag on this partition. You may wish to run the print command in parted to get the partition number. In my case, it's 1 since it's going to be the first partition, so here's how we set the flag on it:

(parted) set 1 bios_grub on

Okay, now that you're created this partition, we're done with this part. If you'd like, you can create your actual filesystem partition by doing the following:

(parted) mkpart primary 1MB 1TB

Only run the above command if it's what you really want to do and you haven't installed anything yet. If you've got a borked system, don't create another partition.

Part Two: Fixing GRUB

Now, you'll need to fix GRUB and fstab. We'll tackle fstab first. Load up a Live CD and mount your filesystem at /mnt on the Live CD.

$ sudo mount /dev/sda /mnt

Now, get the UUID for your hard disk by using the blkid command:

$ sudo blkid /dev/sda1
UUID="abcdef-1231241241-12124124-12ae21331"

Grab the UUID and we'll update /etc/fstab with it. Open up /etc/fstab and update the UUID with the new one you just got from blkid. Make sure you also replace ext4 with btrfs, now that you've changed your filesystem type. Look for the line that has a / in it, this is your root partition, this is the one you want to tweak. Great.

Now, let's update grub.

$ sudo grub-install --root-directory=/mnt /dev/sda

Grub will update and install to the hard drive. Cool. Next step is to update your GRUB configuration files. Let's bind some system partitions into the /mnt dir:

$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /sys /mnt/sys
$ sudo mount --bind /proc /mnt/proc

Now, let's chroot into your filesystem.

$ sudo chroot /mnt

This will effectively log you into your filesystem as if your computer was running it. Next, update grub.

$ sudo update-grub2

Hopefully, it'll happily churn away and update everything. Cool. Now, get back to your life and backup your changes. Learn from your mistakes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .