Skip to main content

Using GRUB2 as your boot-loader

By April 13, 2013September 12th, 2022No Comments

For a while now, GRUB2 has been in distributions but it is now proving its reliability and worth and starting to make its appearance in Enterprise Servers as the boot-loader of choice. In this video we look at GRUB2 on Ubuntu Server 12.04 but you will find similarity with it in openSUSE and other distros. While the name be similar to GRUB the grand unified boot-loader, some may find it more akin to LILO the Linux Loader in the fact that changes need to be updated into the main configuration. Whilst that is true, it is only the case as the new file, grub.cfg is more complex than the previous menu.lst and changes are aggregated from modular files that we edit.

On Ubuntu 12.04

The grub file is located in /boot/grub/grub.cfg

On openSUSE 12.3

The grub file is located in /boot/grub2/grub.cfg

The first setting to view is the menu timeout, this is located in /etc/default/grub. We can change the GRUB_TIMEOUT value to be something more than 2 seconds which is the Ubuntu default. Once we make a change to this file we must update the grub.cfg:

On Ubuntu 12.04

update-grub or grub-mkconfig -o /boot/grub/grub.cfg

On openSUSE 12.04

grub2-mkconfig -o /boot/grub2/grub.cfg

If we want to add our own settings or boot entries these would be in /etc/grub.d/. The file 40_custom is specifically for our own entries. These entries need to be executed by grub-mkconfig and populate the main grub.cfg. There are two ways to do this. The way we are expected to add entries now is to us the exiting line in to 40_custom file:

exec tail -n +3 $0 , I know this does not read well but it really says send content of the files to std-output from line 3 onwards. Traditionally, I would build this using the cat command and comment out the exec tail line , but either way is valid. Using their way the bottom of the file would read:

menuentry "Single User Mode" {
	insmod gzio
	insmod part_msdos
	insmod ext2
	set root=(hd0,1)
        linux /boot/vmlinuz root=/dev/sda1 ro 1
        initrd /boot/initrd

Here we also see that we load the required drivers to access the /boot directory and this means that we can place the /boot directory in software RAID and LVM now if we require. Once completed don’t forget to update grub.cfg again and then reboot to test the option. Grub2 uses partition numbering from 1 not 0.