Customize Grub 2

December 17, 2011

When I install Ubuntu in my computer aside the other OS that I have, it’s always a pain to re-edit the files that control Grub because the way to edit it tend to change with some version of Ubuntu (although they’re small changes, but it’s always a tiresome task to surf the net and find out the little information you need in this vast internet environment) .

So in this article I collect the minimal knowledges about definitions and changes I need to do on this subject to obtain a satisfactory customized Grub.

Since the information I need are written in a perfect way from the sources from where I read them, instead of rearranging the information, I will just copy and paste them here always inside a quotation block. All the credits go to their creators.

GRUB 2 is the default boot loader and manager for Ubuntu since version 9.10 (Karmic Koala).

To determine the version installed in your computer, you can use the line command “grub-install -v” inside the shell of Ubuntu.

To modify GRUB 2, there are some files that need to be considered:

  1. /boot/grub/grub.cfg
  2. /etc/default/grub
  3. /etc/grub.d/  (directory)

/boot/grub/grub.cfg

This file contains the GRUB 2 menu information but the grub.cfg file is not meant to be edited.
Each section is clearly delineated with “(### BEGIN)” and references the script in the /etc/grub.d directory from which the information was generated.
grub.cfg is updated by running the update-grub command as root.

/etc/default/grub

The entries in this file can be edited by a user with administrator (root) privileges and are incorporated into grub.cfg when it is updated.

/etc/grub.d/  (directory)

The scripts in this directory are read during execution of the update-grub command and their instructions are incorporated into /boot/grub/grub.cfg.
The placement of the menu items in the grub.cfg menu is determined by the order in which the files in this directory are run. Files with a leading numeral are executed first, beginning with the lowest number.
Only executable files generate output to grub.cfg during execution of update-grub.
The major default files in this directory used by Ubuntu are:
00_header Sets initial appearance items such as the graphics mode, default selection, timeout, etc.
05_debian_theme The settings in this file set the GRUB 2 background image, text colors, selection highlighting and themes.
10_linux Identifies kernels on the root device for the operating system in use and creates menu entries.
20_memtest86+ Searches for /boot/memtest86+.bin and includes it as an option on the GRUB 2 boot menu.
30_os-prober This script uses os-prober to search for Linux and other operating systems and place the results in the GRUB 2 menu.
40_custom A template for adding custom menu entries which will be inserted into grub.cfg upon execution of the update-grub command.

After editing /etc/default/grub or the scripts in the /etc/grub.d folder the user should run sudo update-grub to incorporate the changes into the GRUB 2 menu.

To modify the aforementioned files you can use the command line “sudo gedit path_of_the_file_to_edit” inside the shell (example: sudo gedit /etc/default/grub). After you input the root password, it will open the software “text editor” with the privilege as root.

In the following lines I will describe only a small part of editing that is of interest to me. To have a more complete editing knowledges you can read the sources at the end of this article from which I collected these information.

First let’s see what’s inside /etc/default/grub (file)

After you opened this file, the entries that are of interest are :

GRUB_DEFAULT – Sets the default menu entry. Entries may be numeric, a complete menuentry quotation, or “saved”
GRUB_DEFAULT=0 Sets the default menu entry by menu position. Counting of entries is the same as in GRUB – the first “menuentry” in grub.cfg is 0, the second is 1, etc.
Note: Grub 1.99 introduces a submenu menu structure. For a menu item in a submenu, the entry becomes a two-digit entry. The first entry is the position of the submenu title in the main menu. The second entry is the position within the submenu. If the submenu is the 3rd entry in the main entry, and the user wishes to boot the first entry in the submenu, it would be designated as “2>0”

GRUB_TIMEOUT=10
Setting this value to -1 will cause the menu to display until the user makes a selection.
The GRUB 2 menu is hidden by default unless another OS is detected by the system. If there is no other OS, this line may be commented out unless the user changes it. To display the menu on each boot, uncomment the line and use a value of 1 or higher.

#GRUB_GFXMODE=640×480
You can remove the # symbol to make this line active. The entry sets the resolution of the graphical menu (the menu text size). It provides resolutions supported by the user’s graphics card (e.g. 640×480, 800×600, 1280×1024, etc). The setting applies only to the boot menu display, not the resolution of the operating system that boots.
Tip: Setting the same resolution in GRUB 2 and the operating system will decrease boot times slightly.
The user can also add multiple resolutions. If GRUB 2 cannot use the first entry, it will try the next setting. Settings are separated by a comma. Example: 1280x1024x16,800x600x24,640×480.
If using a splash image, the resolution setting and the splash image size should be compatible for best results.
Resolutions available to GRUB 2 can be displayed by typing vbeinfo in the GRUB 2 command line. The command line is accessed by typing “c” when the main GRUB 2 menu screen is displayed.

GRUB_DISABLE_LINUX_RECOVERY=true
Uncomment (remove the # symbol) to prevent the “Recovery” mode kernel options from appearing in the menu. If you want a “Recovery” option for only one kernel, make a special entry in /etc/grub/40_custom.

GRUB_BACKGROUND=/path_to_image/filename.   The GRUB 2 splash images are controlled by the GRUB_BACKGROUND variable in ‘/etc/default/grub‘. The image must be a .png, .tga, .jpeg, or .jpg image.

By changing the value about these variables you can create a more suitable menu list of your interest.

After turning up the computer I prefer to see a screen selection with only the lines about the different OS that is installed on my PC and in the order that is better to me.
The easiest way to obtain this result is to create a custom menu entries.

GRUB 2 allows users to create customized menu selections which will be automatically added to the main menu when sudo update-grub is executed. A 40_custom file is available in /etc/grub.d/ for use or to serve as an example to create other custom menus.

The file must be made executable: sudo chmod +x /etc/grub.d/filename. However if you are using the default file 40_custom and not the one you created then this is not necessary.

The easiest way to create the content of a custom menu is to copy a working entry from /boot/grub/grub.cfg. Once copied, the contents of 40_custom can be tailored to the user’s desires. The user can copy existing menuentries from the /boot/grub/grub.cfg file.

The part that is needed looks like this:

menuentry ‘Ubuntu 11.10 – Oneiric Ocelot’ –class ubuntu –class gnu-linux –class gnu –class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos3)’
search –no-floppy –fs-uuid –set=root cb201140-52f8-4449-9a95-749b27b58ce8
linux    /boot/vmlinuz-3.0.0-13-generic-pae root=UUID=cb201140-52f8-4449-9a95-749b27b58ce8 ro   quiet splash vt.handoff=7
initrd    /boot/initrd.img-3.0.0-13-generic-pae
}

or

menuentry “Windows 7 Professional” –class windows –class os {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)’
search –no-floppy –fs-uuid –set=root C406C64E37C181E7
chainloader +1
}

NB: make sure to change the old entry “gfxmode $linux_gfx_mode” in this new one “set gfxpayload=$linux_gfx_mode” otherwise it will give you an error like grub2 – Error: unknown command ‘gfxmode’  on the startup.
 

After you finished modifying the file 40_custom, you just need to remove all but the following files from the /etc/grub.d folder:

  • 00_header,
  • 05_debian_theme,
  • 40_custom
  • and README.

The unnecessary files are:

  • 10_linux
  • 20_linux_xen
  • 20_memtest86+
  • 30_os-prober
  • 41_custom

Alternatively, you may keep other files in the /etc/grub.d folder if you make them unexecutable (which is the way I prefer).

In this case the command needed is sudo chmod -x /etc/grub.d/filename.

Then you just need to run the command update-grub as root to apply the changes!

This is the basic you need to know to modify the list of the boot loader. In the next post I will describe some way to improve the graphic impact of the boot loader

Source: https://help.ubuntu.com/community/Grub2


Bootable USB drive of Windows

September 3, 2011

In the case where you can’t use the DVD drive to read your copy of Windows Vista or Windows 7 in order to install this OS into your computer, an alternative solution is to create a bootable USB drive of these OS.

In this way you can install Windows using a USB and at the same time you also gain the advantage of a better speed because of the velocity of reading and writing of USB.

So to start you need:

  • a USB at least of 4GB
  • a DVD installation of your OS (Windows Vista or 7) or in alternative a copy image of your OS that you will need to mount later to access to its files

The first operations are:

  • Connect your USB to your pc and then Format your USB in FAT32 file system with also the option quick activated;
  • Now open Command Prompt Window as the administrator in order to gain high privilege to the operations. To open it you can click Start->All Programs->Accessories->Command Prompt(right click on this and select run as the administrator). Or you can just open Start and then type “cmd” then right click on cmd.exe and select run as the administrator.
  • In the Command Prompt Window you have to type the command “diskpart” to launch this program;
  • Again type “list volume” and it will show a list of all drives in your system. From this list you should verify what number and letter is assigned to your USB because these will be needed later. In my case the number is 5 and the letter is H.

  • Now you need to type “select volume #” (where # is the number of your USB drive);
  • And after type “active“;
  • Now you can exit from this program by typing the command “exit“. Don’t close the Command Prompt Window because you will need it again soon.

Now we need to make the USB bootable. In order to do this we will use the bootsect utility inside the DVD installation. To do this:

  • You will need to insert your DVD installation of your OS in your DVD drive or if you have an image copy then you should mount it. Also you need to find which letter is assigned to it. In my case it’s the letter G.
  • Now in the Command Prompt Window you must change the directory to that of the DVD installation. To do this you simply type “G:” or in your case the letter you have obtained;
  • And after type “cd boot“;
  • Then you need to type the last command that is “bootsect /nt60 H:” where the letter H should be changed according to the letter you have obtained before that indicate your USB drive. If there isn’t any problem you should see a message of successful operation.

The last part is really simple. You just need to copy all the files inside the DVD installation to your USB. At the end of this operation you have now a bootable USB with the copy of your OS inside it.

UPDATE:

1) I noticed that if you have Windows Vista retail ( meaning without SP1 installed) then the USB that you created will not work or you can’t even complete all the tutorial because there is some small bug that is needed to be patched with SP1.

2) for lazy people or, better, for those that encountered the aforementioned problem, you can try using some free tools that will create for you your bootable USB:

UNetbootin (Universal Netboot Installer)

Windows 7 USB/DVD download tool (official tool provided by Microsoft)

 

Sources:


Ubuntu USB Boot problem

September 2, 2011

I don’t know why but it seems that in some release of Ubuntu, the software incorporated in it called “Startup Disk Creator”, a software used to create ONLY bootable version of Ubuntu, is not quite perfect.

Because when the operation of the software is finished, after rebooting the pc to load the Live version of Ubuntu installed in the USB, the operation will stop at the beginning of the loading of some file more precisely it will show the message:

SYSLINUX 3.63 Debian-2008-07-15 EBIOS Copyright (C) 1994-2008 H. Peter Anvin
Unknown keyword in configuration file.
boot:
_

At first I thought that it was some very complicated problem to solve but in reality it only require a few minutes, most likely less than 5 min to solve everything.

  1. First you need a pc to connect your just created USB drive with Ubuntu installed in it;
  2. Then you open the folder called syslinux which is in the root of the USB;
  3. Inside of it there is a file called syslinux.cfg. You need to open it (with a text editor) to edit some line of text inside of that file;
  4. Find the line “ui gfxboot bootlogo” and simply remove the “ui”;
  5. Save the file and repeat the operation of booting from USB;
  6. This time the USB drive should not create any problem.

The edited file of syslinux.cfg should look like this:

# D-I config version 2.0
include menu.cfg
default vesamenu.c32
prompt 0
timeout 50
gfxboot bootlogo

 

Source: how to fix unknown keyword in configuration file ubuntu usb boot