2

I have manually installed linux on a USB drive. It works and boots up when I plug the drive into the original computer.

The problem comes when the drive is on a different computer or there are other drives plugged in and my USB is NOT /dev/sdb. I then get an error that the root drive can not be mounted because etc/fstab says root is /dev/sdb1.

How can I make the /etc/fstab either change on bootup or make it automatically use the partition that the kernel is in (my root partition)?

3
  • Note that your kernel is not on your root partition, but instead on your /boot partition. Commented Feb 20, 2022 at 14:33
  • @mashuptwice That's true normally - I built an LFS system and put it all in the same partition for no real reason Commented Feb 20, 2022 at 16:26
  • Well, there is always an edgecase Commented Feb 20, 2022 at 16:30

1 Answer 1

5

You can also identify the partitions with their UUIDs

The Unique Universal IDentifier is, as the name implies, unique and never changes. It even stays the same when using the media on a different computer.

You can use UUIDs instead of /dev/sdx by editing /etc/fstab

Note that you need to run the following commands as root.

  1. Identify your partition with lsblk, e.g. /dev/sda1
  2. Get the partitions UUID via blkid
  3. Edit /etc/fstab and replace /dev/sda1 with the UUID as following

Before:

/dev/sda1          /boot           vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro   0 2

After:

UUID=5cd7485d-d22e-4860-bdb5-753d5456714a          /boot           vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro   0 2
1
  • Thanks, just what I needed Commented Feb 20, 2022 at 16:44

You must log in to answer this question.

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