How can I tell if grub is installed on a disk, and if it is what settings it has (noteably, what it has for the root parameter)
I need to check a lot of disks in software RAID1 arrays to make sure both disks have grub installed, with the grub on each disk having the appropriate root value.
Alternate Method
file -s
didn't work for me in Ubuntu Lucid because my file command's magic files were out of date. Another way to do this if your magic files haven't caught up with GRUB changes is to examine the first 512 bytes of the device using thedd
command like this:This sends the output of the
dd
command through thestrings
command thus stripping out unprintable characters (transfer statistics get discarded to/dev/null
).If you see any messages that GRUB would display when it encounters failure then you've got grub installed.
Hat tip to louib on ubuntuforums.org for answering in this password protected post: http://ubuntuforums.org/showthread.php?t=363372
For the curious this is what I got from
file -s
:There's nothing about GRUB in there specifically.
This is a simple way to tell if GRUB is installed. If it doesn't work your
file
command's database is likely out of date and you can either update the its database or use an alternate method from another answer.You can use
file
to identify GRUB in an MBR. e.g.The
root=
paramater is not stored in the MBR, that's stored in GRUB'smenu.lst
file which is stored on a file-system (typically in the /boot/grub directory of the root fs or the grub directory of the /boot filesystem - but not always, it could be anywhere).You'll have to parse the output of file above, determine which disk/partition the
menu.lst
file is on, mount it, read it in and parse it. You'll also want to read in the grub/default file to figure out which grub menu entry is the default, because that's probably the one that has the root= parameter that you're most interested in.You can use
grub-emu
to see the menu that grub will show when the machine next reboots.On my desktop machine the menu was displayed as expected, although if I actually pretended to boot a kernel I got a "no such device" error. I think that is expected behaviour.
On my DigitalOcean VPS no entries were displayed in the grub menu, although the server did actually reboot fine. (This is a 2013 VPS, so your mileage may vary.)
Some notes when running
grub-emu
:c
then typingexit
.reset
. (Don't worry it won't restart your machine. It will just clean up your terminal.)