Hi all,
I had made a tutorial for GRUB2 when it was in its infancy.The rest of this post would be an update of that tutorial. It would also have a few questions which I still need to figure out answers to.
The tutorial was for the 1.95 series. Things have moved quite a lot in the Ubuntu Universe since then. One of the things has been the move to using UUID’s which has been pretty well documented here.
A single instruction though, make sure to backup each file before making any changes to the file. This is so in case we bungle something.
It would be something like :-
$ sudo cp /boot/grub/grub.cfg /boot/grub/grub.cfg.original
$ sudo chmod a-w grub.cfg.original
This is the way my system is setup at the present.
The target platform is an 80 GB IDE HDD (Samsung)
I have four partitions :-
Sr. No. | Partition | Size |
01. | /boot | 1.9 GB |
02. | / | 20 GB |
03. | /home | 53 GB |
04. | swap | 1.5 GB |
Although the only thing this time around I had to do was just
$ sudo aptitude install grub2
which did the following :-
Removing grub …
Processing triggers for man-db …
Selecting previously deselected package os-prober.
(Reading database … 181018 files and directories currently installed.)
Unpacking os-prober (from …/os-prober_1.26ubuntu2_i386.deb) …
Selecting previously deselected package grub-common.
Unpacking grub-common (from …/grub-common_1.96+20080724-12ubuntu1_i386.deb) …
Selecting previously deselected package grub-pc.
Unpacking grub-pc (from …/grub-pc_1.96+20080724-12ubuntu1_i386.deb) …
Selecting previously deselected package grub2.
Unpacking grub2 (from …/grub2_1.96+20080724-12ubuntu1_i386.deb) …
Processing triggers for man-db …
Setting up os-prober (1.26ubuntu2) …
Setting up grub-common (1.96+20080724-12ubuntu1) …
Setting up grub-pc (1.96+20080724-12ubuntu1) …
Generating core.img
Saving menu.lst backup in /boot/grub/menu.lst_backup_by_grub2_postinst
Running update-grub Legacy to hook our core.img in it
Searching for GRUB installation directory … found: /boot/grub
Searching for default file … found: /boot/grub/default
Testing for an existing GRUB menu.lst file … found: /boot/grub/menu.lst
Searching for splash image … none found, skipping …
Found GRUB 2: /grub/core.img
Found kernel: /vmlinuz-2.6.27-7-generic
Found kernel: /memtest86+.bin
Updating /boot/grub/menu.lst … done
Updating /boot/grub/grub.cfg …
Found linux image: /boot/vmlinuz-2.6.27-7-generic
Found initrd image: /boot/initrd.img-2.6.27-7-generic
Found memtest86+ image: /boot/memtest86+.bin
done
Setting up grub2 (1.96+20080724-12ubuntu1) …
While GRUB legacy used menu.lst , grub2 uses grub.cfg
This is how grub.cfg looks on my system.
# # DO NOT EDIT THIS FILE # # It is automatically generated by /usr/sbin/update-grub using templates # from /etc/grub.d and settings from /etc/default/grub # ### BEGIN /etc/grub.d/00_header ### set default=0 set timeout=5 set root=(hd0,2) search --fs-uuid --set fc24631b-c156-4beb-bf61-be84e24bc946 if font /usr/share/grub/ascii.pff ; then set gfxmode=640x480 insmod gfxterm insmod vbe terminal gfxterm fi ### END /etc/grub.d/00_header ### ### BEGIN /etc/grub.d/05_debian_theme ### set menu_color_normal=cyan/blue set menu_color_highlight=white/blue ### END /etc/grub.d/05_debian_theme ### ### BEGIN /etc/grub.d/10_hurd ### ### END /etc/grub.d/10_hurd ### <strong>### BEGIN /etc/grub.d/10_linux ### set root=(hd0,1) search --fs-uuid --set 083eb71a-610b-45fe-b843-2acc97b088ac menuentry "Ubuntu, linux 2.6.27-7-generic" { linux /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro quiet splash initrd /initrd.img-2.6.27-7-generic } menuentry "Ubuntu, linux 2.6.27-7-generic (single-user mode)" { linux /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro single initrd /initrd.img-2.6.27-7-generic } ### END /etc/grub.d/10_linux ###</strong> ### BEGIN /etc/grub.d/20_memtest86+ ### menuentry "Memory test (memtest86+)" { linux /memtest86+.bin } ### END /etc/grub.d/20_memtest86+ ### ### BEGIN /etc/grub.d/30_os-prober ### ### END /etc/grub.d/30_os-prober ### ### BEGIN /etc/grub.d/40_custom ### # This file is an example on how to add custom entries ### END /etc/grub.d/40_custom ###
While this is how grub.cfg looks at my system. The interesting part is the one between
BEGIN /etc/grub.d/10_linux
and END /etc/grub.d/10_linux
which I have explicitly highlighted for people to know.
This is so much smaller and cleaner then the GRUB legacy menu.lst
# menu.lst - See: grub(8), info grub, update-grub(8) # grub-install(8), grub-floppy(8), # grub-md5-crypt, /usr/share/doc/grub # and /usr/share/doc/grub-doc/. ## default num # Set the default entry to the entry number NUM. Numbering starts from 0, and # the entry number 0 is the default if the command is not used. # # You can specify 'saved' instead of a number. In this case, the default entry # is the entry saved with the command 'savedefault'. # WARNING: If you are using dmraid do not use 'savedefault' or your # array will desync and will not let you boot your system. default 0 ## timeout sec # Set a timeout, in SEC seconds, before automatically booting the default entry # (normally the first entry defined). timeout 600 ## hiddenmenu # Hides the menu by default (press ESC to see the menu) #hiddenmenu # Pretty colours color cyan/blue white/blue ## password ['--md5'] passwd # If used in the first section of a menu file, disable all interactive editing # control (menu entry editor and command-line) and entries protected by the # command 'lock' # e.g. password topsecret # password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/ # password topsecret # # examples # # title Windows 95/98/NT/2000 # root (hd0,0) # makeactive # chainloader +1 # # title Linux # root (hd0,1) # kernel /vmlinuz root=/dev/hda2 ro # # # Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST ### BEGIN AUTOMAGIC KERNELS LIST ## lines between the AUTOMAGIC KERNELS LIST markers will be modified ## by the debian update-grub script except for the default options below ## DO NOT UNCOMMENT THEM, Just edit them to your needs ## ## Start Default Options ## ## default kernel options ## default kernel options for automagic boot options ## If you want special options for specific kernels use kopt_x_y_z ## where x.y.z is kernel version. Minor versions can be omitted. ## e.g. kopt=root=/dev/hda1 ro ## kopt_2_6_8=root=/dev/hdc1 ro ## kopt_2_6_8_2_686=root=/dev/hdc2 ro # kopt=root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro ## default grub root device ## e.g. groot=(hd0,0) # groot=(hd0,0) ## should update-grub create alternative automagic boot options ## e.g. alternative=true ## alternative=false # alternative=true ## should update-grub lock alternative automagic boot options ## e.g. lockalternative=true ## lockalternative=false # lockalternative=false ## additional options to use with the default boot option, but not with the ## alternatives ## e.g. defoptions=vga=791 resume=/dev/hda5 # defoptions= ## should update-grub lock old automagic boot options ## e.g. lockold=false ## lockold=true # lockold=false ## Xen hypervisor options to use with the default Xen boot option # xenhopt= ## Xen Linux kernel options to use with the default Xen boot option # xenkopt=console=tty0 ## altoption boot targets option ## multiple altoptions lines are allowed ## e.g. altoptions=(extra menu suffix) extra boot options ## altoptions=(single-user) single # altoptions=(recovery mode) single ## controls how many kernels should be put into the menu.lst ## only counts the first occurence of a kernel, not the ## alternative kernel options ## e.g. howmany=all ## howmany=7 # howmany=all ## should update-grub create memtest86 boot option ## e.g. memtest86=true ## memtest86=false # memtest86=true ## should update-grub adjust the value of the default booted system ## can be true or false # updatedefaultentry=false ## should update-grub add savedefault to the default options ## can be true or false # savedefault=false ## ## End Default Options ## title Chainload into GRUB 2 root (hd0,0) kernel /grub/core.img title ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ root title When you have verified GRUB 2 works, you can use this command to root title complete the upgrade: upgrade-from-grub-legacy root title ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ root title Debian GNU/Linux, kernel 2.6.27-7-generic root (hd0,0) kernel /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro initrd /initrd.img-2.6.27-7-generic title Debian GNU/Linux, kernel 2.6.27-7-generic (recovery mode) root (hd0,0) kernel /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro single initrd /initrd.img-2.6.27-7-generic title Debian GNU/Linux, kernel memtest86+ root (hd0,0) kernel /memtest86+.bin ### END DEBIAN AUTOMAGIC KERNELS LIST
Now let’s try to understand that block given in grub.cfg
### BEGIN /etc/grub.d/10_linux ### set root=(hd0,1) search --fs-uuid --set 083eb71a-610b-45fe-b843-2acc97b088ac menuentry "Ubuntu, linux 2.6.27-7-generic" { linux /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro quiet splash initrd /initrd.img-2.6.27-7-generic } menuentry "Ubuntu, linux 2.6.27-7-generic (single-user mode)" { linux /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro single initrd /initrd.img-2.6.27-7-generic } ### END /etc/grub.d/10_linux ###
The interesting part for me was getting from where this UUID
083eb71a-610b-45fe-b843-2acc97b088ac was coming from?
Finally realized this was the UUID of /boot.
~$ blkid
/dev/sda1: UUID="083eb71a-610b-45fe-b843-2acc97b088ac" TYPE="ext3"
/dev/sda2: UUID="fc24631b-c156-4beb-bf61-be84e24bc946" TYPE="ext3"
/dev/sda3: UUID="7c003381-39d7-4126-8b9b-dbdbf3955eea" TYPE="ext3"
/dev/sda4: UUID="baa0d92f-3112-42ab-aaf7-b2e416dea782" TYPE="swap"
/dev/loop0: TYPE="squashfs"
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 19G 4.1G 14G 23% /
tmpfs 501M 0 501M 0% /lib/init/rw
varrun 501M 128K 501M 1% /var/run
varlock 501M 4.0K 501M 1% /var/lock
udev 501M 2.8M 498M 1% /dev
tmpfs 501M 264K 501M 1% /dev/shm
lrm 501M 2.0M 499M 1% /lib/modules/2.6.27-7-generic/volatile
/dev/sda1 1.9G 48M 1.8G 3% /boot
/dev/sda3 53G 25G 25G 50% /home
as can be seen /dev/sda1 1.9G 48M 1.8G 3% /boot
and blkid shows /dev/sda1 having the blkid
/dev/sda1: UUID="083eb71a-610b-45fe-b843-2acc97b088ac" TYPE="ext3"
Now one has to remember that your UUID would be different than others. As the name itself says UUID or Universally Unique Identifier Label it will be unique to your system although the logic should be same.
The other unique thing I found is the naming convention, while in GRUB legacy it uses
root (hd0,0) in GRUB2 it uses set root=(hd0,1)
What is more interesting is that all the manuals have been updated . For e.g. the update-grub manual.
UPDATE-GRUB(8) System Administration Utilities UPDATE-GRUB(8)
NAME
update-grub – manual page for update-grub (GNU GRUB )
SYNOPSIS
update-grub [OPTION]
DESCRIPTION
Generate /boot/grub/grub.cfg
-h, –help
print this message and exit
-v, –version
print the version information and exit
-y ignored for compatibility
REPORTING BUGS
Report bugs to .
FSF November 2008 UPDATE-GRUB(8)
What’s interesting is the date November 2008
Another thing, they have moved update-grub to grub legacy and there is now a update-grub2 but it doesn’t have any documentation (as in manpage and stuff_
/usr/lib/grub-legacy/update-grub
/usr/sbin/update-grub
/usr/sbin/update-grub2
/usr/share/man/man8/update-grub.8.gz
Looking for version information via update-grub2 results in updating grub2
$ sudo update-grub2 --version
[sudo] password for shirish:
Updating /boot/grub/grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.27-7-generic
Found initrd image: /boot/initrd.img-2.6.27-7-generic
Found memtest86+ image: /boot/memtest86+.bin
done
Now wanted to make that usplash doesn’t run while booting .
Go to /etc/default/grub and edit line 6 from
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT=" "
Save the file.
Then run
$ sudo update-grub
The change would be apparent in /boot/grub/grub.cfg . Specifically this part :-
### BEGIN /etc/grub.d/10_linux ### set root=(hd0,1) search --fs-uuid --set 083eb71a-610b-45fe-b843-2acc97b088ac menuentry "Ubuntu, linux 2.6.27-7-generic" { linux /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro <strong>quiet splash</strong> initrd /initrd.img-2.6.27-7-generic } menuentry "Ubuntu, linux 2.6.27-7-generic (single-user mode)" { linux /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro single initrd /initrd.img-2.6.27-7-generic } ### END /etc/grub.d/10_linux ###
To
### BEGIN /etc/grub.d/10_linux ### set root=(hd0,1) search --fs-uuid --set 083eb71a-610b-45fe-b843-2acc97b088ac menuentry "Ubuntu, linux 2.6.27-7-generic" { linux /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro initrd /initrd.img-2.6.27-7-generic } menuentry "Ubuntu, linux 2.6.27-7-generic (single-user mode)" { linux /vmlinuz-2.6.27-7-generic root=UUID=fc24631b-c156-4beb-bf61-be84e24bc946 ro single initrd /initrd.img-2.6.27-7-generic } ### END /etc/grub.d/10_linux ###
One can see the absence of ‘splash’ on line 5 .
The next thing we are going to do is make update to grub2 as we are getting the hang of things a bit. It will be just doing
$ sudo upgrade-from-grub-legacy
which gives
$ sudo upgrade-from-grub-legacy [sudo] password for plun: Installing GRUB to Master Boot Record of your first hard drive ... Installation finished. No error reported. This is the contents of the device map /boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. (hd0) /dev/sda GRUB Legacy has been removed, but its configuration files have been preserved, since this script cannot determine if they contain valuable information. If you would like to remove the configuration files as well, use the following command: rm -f /boot/grub/menu.lst*
Now to get some nice images for beautifying the boot screen. First install the grub2-splashimages
$ sudo aptitude install grub2-splashimages
There is a bug though with the /etc/grub.d/05_debian_theme .
This is the way the file looks .
#!/bin/bash -e source /usr/lib/grub/update-grub_lib set_blue_theme() { cat < < EOF set menu_color_normal=cyan/blue set menu_color_highlight=white/blue EOF } # check for usable backgrounds use_bg=false if [ "$GRUB_TERMINAL" = "gfxterm" ] ; then for i in {/boot/grub,/usr/share/images/desktop-base}/moreblue-orbit-grub.{png,tga} ; do if is_path_readable_by_grub $i ; then bg=$i case ${bg} in *.png) reader=png ;; *.tga) reader=tga ;; *.jpg|*.jpeg) reader=jpeg ;; esac if test -e /boot/grub/${reader}.mod ; then echo "Found Debian background: `basename ${bg}`" >&2 use_bg=true break fi fi done fi # set the background if possible if ${use_bg} ; then prepare_grub_to_access_device `${grub_probe} --target=device ${bg}` cat < < EOF insmod ${reader} if background_image `make_system_path_relative_to_its_root ${bg}` ; then set color_normal=black/black set color_highlight=magenta/black else EOF fi # otherwise, set the traditional Debian blue theme if ${use_bg} ; then set_blue_theme | sed -e "s/^/ /g" echo "fi" else set_blue_theme fi [/sourcecode] What we are interested is line 16 which should be changed from <code>for i in {/boot/grub,/usr/share/images/desktop-base}/moreblue-orbit-grub.{png,tga} ; do to <code>for i in {/boot/grub,/usr/share/images/desktop-base,/usr/share/images/grub}/WhateverSplashImageYouWant.{png,tga} ; do</code> By 'WhateverSplashImageYouWant' I mean any of the images which are installed in the /usr/share/images/grub file. For this e.g. I am taking Lake_mapourika_NZ (one of the images I liked) so enter this there so it reads <code>for i in {/boot/grub,/usr/share/images/desktop-base,/usr/share/images/grub}/Lake_mapourika_NZ.{png,tga} ; do</code> run sudo update-grub again :- <code>$ sudo update-grub [sudo] password for shirish: Updating /boot/grub/grub.cfg ... <strong>Found Debian background: Lake_mapourika_NZ.tga</strong> Found linux image: /boot/vmlinuz-2.6.27-7-generic Found initrd image: /boot/initrd.img-2.6.27-7-generic Found memtest86+ image: /boot/memtest86+.bin done</code> Yay! it found the background. Now to check the same in /boot/grub/grub.cfg It should show ### BEGIN /etc/grub.d/05_debian_theme ### set root=(hd0,2) search --fs-uuid --set fc24631b-c156-4beb-bf61-be84e24bc946 insmod tga if background_image /usr/share/images/grub/<strong>Lake_mapourika_NZ</strong>.tga ; then set color_normal=black/black set color_highlight=magenta/black else set menu_color_normal=cyan/blue set menu_color_highlight=white/blue fi ### END /etc/grub.d/05_debian_theme ###
If you get this then you are home 🙂 The name of the file you may have maybe
different but the logic followed is the same.
Shutdown the system and do a cold boot. See if it works !
But Seriously THIS is not how it should be configured. There should be GUI-based tools to do the same. The end-user shouldn’t have to edit the files in order to get GRUB2 working.
The only issue I have is what is the new os-prober package, that needs to be documented. In fact the three packages which make up grub2 that is grub-pc, grub-common and os-prober need to know what they individually have and do.
Would be retouching the same story as I get more info. on the same.
Bob,
Dunno which version of Ubuntu you are using Gutsy, Hardy, Intrepid, Jaunty or Karmic
as implementation of UUID started from Hardy onwards and there have been some slight differences as it peforms important functions with udev, ubiquity, the kernel etc.
It has been some time since I last played with UUID’s but hence here goes nothing as I’m not near to my GNU/Linux box atm.
Karmic is supposed to clear lot of these UUID issues (hopefully so)
One of the ways you could do it is :-
1. Chroot into mount your hard disk
2. Then go to /etc/default/grub
3. Then make changes there .
IIRC there are some options to deal with UUID therein.
4. Comment stuff which you do don’t want.
5. And then run update-grub again.
Then close the connection.
Shut down your live CD and reboot.
You may have to make changes to /etc/fstab as well.
Although its a nice idea to first study what /etc/default/grub actually does before doing anything.
Lemme know if the above helps.
I’ve run into the same “unknown device” for the UUID. I have to delete the entire “search” line, and convert the UUID to /dev/hda1 and then it boots.
I’m hoping that it’s just that the UUID is somehow wrong, but I don’t know how to fix it, or get rid of it for that matter.
Well, I ended up trying it, and failed miserably. Also, the Grub2 community seems none too responsive to my questions, at least at the moment. So I’m back to grub legacy and /boot on 3xRAID1 while / is on RAID6.
boostpro,
Unfortunately, I don’t have access to that kind of setup. If I had there are tons of stuff I would have played with. There is just so much one can play with using RAID and filesystems 😉