Jump to content


Photo
- - - - -

Slackware with GRUB2 + UUID root


  • Please log in to reply
No replies to this topic

#1 systems_glitch

systems_glitch

    Dangerous free thinker

  • Moderating Team
  • 1,669 posts
  • Gender:Male

Posted 20 February 2014 - 09:52 AM

My utility box dual boots Slackware 14 and MS-DOS 6.22. Between the two, I have a really complete set of disk imaging and archiving utilities. I recently added a SCSI card to the box to read a bunch of old SyQuest cartridges, only to end up with a kernel panick over a missing root partition. The addition of the SyQuest drive had shuffled the primary hard disk up to /dev/sdb

 

The answer to this is pretty standard, you want to use UUIDs or partition labels to refer to devices in a globally unique way. Unfortunately, Slackware 14 doesn't come equipped for that as-is out of the box. It's fine for most setups, where you won't be adding drives before boot time, or controller initialization order is controlled, as in a server environment.

 

Booting with a UUID specification for root requires messing with the bootloader. Slackware ships with LILO by default. I'm willing to tolerate LILO as long as I don't have to actually change anything with it, but I prefer GRUB2. Grab the latest source, unpack it, andcompile -- don't worry about the mentioned GNU font dependencies, they're optional unless you want to change your bootloader font.

$ ./configure && make

... output from compile process ...

# make install
# grub-install --target=i386-pc --recheck --debug /dev/sda

Note that `make install` and the `grub-install` commands are run as root.

 

By default, the configure script will put all of GRUB2's configuration files in /usr/local/etc/grub.d/ -- these files get concatenated in filename order to build /boot/grub/grub.cfg. It is recommended to work with the individual files rather than editing grub.cfg. For my situation, I left 00_header in place and deleted the other "number files" (iirc, 10_linux 20_linux_xen 30_os-prober 41_custom) using 40_custom as my main GRUB configuratoin:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

set menu_color_normal='light-blue/black'
set menu_color_highlight='light-cyan/blue'

menuentry "Slackware Linux 14.0" {
	set root=(hd0,2)
	insmod xfs
	search --no-floppy --fs-uuid --set 8ed88d94-8c00-4074-a0d4-53a56e083ef1
	linux /boot/vmlinuz-huge-3.2.29 root=UUID=8ed88d94-8c00-4074-a0d4-53a56e083ef1
	initrd /boot/initrd.gz
}

menuentry "MS-DOS 6.22" {
	set root=(hd0,0)
	search --no-floppy --label DOS622 --set=root
	insmod fat
	insmod chain
	chainloader (${root})+1
}

Couple of things to note about it. First, `search` is used to override the default `set root=` statement above. Second, you need to insert the module of the filesystem you want to boot to. Third, chainloader now comes in its own module. Finally, I found it impossible to use the short UUID provided by `blkid` for the MS-DOS partition, so I used the partition label. This works fine, and it's not too likely that I'll have something else plugged into the system using "DOS622" as a partition label.

 

With the default Slackware kernel, you'll need to generate an initrd to use UUIDs. This process will not work without an initrd! Fortunately, since we're using GRUB2 instead of LILO, we don't need to embed an initrd in the kernel, which is too big with the generic Slackware kernel anyway. The following will generate it with the default drivers and place it at /boot/initrd.gz, then install the configuration to /boot/grub/grub.cfg

# mkinitrd -c
# grub-mkconfig -o /boot/grub/grub.cfg

And that's it! For testing, you may want to leave the 30_os-prober config in for GRUB -- it will find the default Slackware kernel and generate a usable menu entry. Don't forget to switch to UUIDs in /etc/fstab if you haven't already, otherwise your partitions might fail to mount if their /dev/sdX designation changes.






BinRev is hosted by the great people at Lunarpages!