TransWikia.com

Booting from GRUB command line, says partion doesn't exist

Unix & Linux Asked by Hidden on January 13, 2021

I have found some related questions but none has solve my problem.

I have a laptop with a hard disk with Windows. I wanted to install Debian in a second hard disk so I attached it with a caddy and removed the Windows hard disk (just in case, you know). I then successfully installed Debian with GRUB installed in the same disk as it was the only one at that moment. Then I put back the Windows hard disk.

Now from the BIOS I can choose which drive I want to boot. The Windows drive boots perfectly, but when I choose to boot from the Debian drive it shows the GRUB menu and then a black screen with a blinking dash.

If I remove the Windows hard disk I can successfully boot Debian, so the problem must be with the GRUB configuration.

Thus, I go for the GRUB console. I detect linux is in the (hd0,5) partion and vmlinuz and initrd are reachable from the root, so I go for the usual:

grub> set root=(hd0,5)
grub> linux /vmlinuz root=/dev/sda5
grub> initrd /initrd.img
grub> boot

Then I can see a lot of initrd output which then goes for a bunch of Begin: Running /scripts/local-block ... done. messages and finally fails with a sda5 doesn't exists. Dropping to a shell like message. But well… you know… it does exist, so I’m blocked.

One Answer

You have two problems: identifying the drive, and identifying the partition.

Grub counts partitions from 0, Linux counts partitions from 1. So if Grub's hd0 is Linux's sda then Grub's (hd0,5) is Linux's sda6.

The partition you choose as “root” in Grub is not necessarily Linux's root partition. In Grub, “root” is just a shortcut for not having to type the partition designation in front of file names. If you have a separate /boot partition then you'd typically set that as the Grub root, because Grub only cares about what's in /boot (the kernel image and the initial ramdisk image). Linux doesn't care about what's in /boot except to upgrade it.

The drive numbering may not match between Grub and Linux. Grub relies on the computer's BIOS to enumerate drives. Linux has its own drivers. When disks are connected through a different interface, it's difficult to predict in which order they'll be enumerated; it can be up to which disk controller replies faster. So Grub's hd0 is not necessarily Linux's sda.

To make your computer boot reliably no matter how the disks are connected and what the timing of the controller's responses are, use labels or UUIDs instead of a letter/number designation. Once you've booted, run update-grub — it should normally generate a file /boot/grub/grub.cfg using UUIDs. Both Grub and Linux will enumerate available partitions when they start up and remember their UUIDs. In grub.cfg, you should see lines like

search --no-floppy --fs-uuid --set=root 82aecd65-6423-4d95-9319-3034263ee747

and

linux /vmlinux root=UUID=82aecd65-6423-4d95-9319-3034263ee747 ro

Answered by Gilles 'SO- stop being evil' on January 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP