Are you a spammer

Please note, that the first 3 posts you make, will need to be approved by a forum Administrator or Moderator before they are publicly viewable.
Each application to join this forum is checked at the Stop Forum Spam website. If the email or IP address appears there when checked, you will not be allowed to join this forum.
If you get past this check and post spam on this forum, your posts will be immediately deleted and your account inactivated.You will then be banned and your IP will be submitted to your ISP, notifying them of your spamming. So your spam links will only be seen for an hour or two at most. In other words, don't waste your time and ours.

This forum is for the use and enjoyment of the members and visitors looking to learn about and share information regarding the topics listed. It is not a free-for-all advertising venue. Your time would be better spent pursuing legitimate avenues of promoting your websites.

Grub Edits

Post your How to's here


Grub Edits

Postby LeadFingers » Sun Dec 07, 2008 5:13 am

Need to punch-up... cause this looks real bad, need caffiene cause this is real dry!
Before attempting this, it is highly recommended you have a copy of, and a firm understanding of Supergrub.
Bits & pieces copied from HermanZone (If you think this is long, go see their site) Good job Herman!




________________________________Introduction to Grub________________________________

Grub, (GRand Unified Bootloader) is much more than just an ordinary boot loader.

1) GRUB can load a wide variety of operating systems directly by loading their kernels into the computer's memory.

2) GRUB can load 'proprietary' operating systems (unsupported operating systems like Windows) by a process called 'chainloading'.

3) You will normally be booting from GRUB's Graphical User Interface .
There are a lot of options available in GRUB to help you if you ever have trouble booting.
a) GRUB's Command Line Interface (CLI),
b) Temporarily Edit the GRUB Menu 'on the fly'
c) GRUB shell in a terminal in a LiveCD or when another installed OS is booted.

4) When GRUB installs itself it can detect all operating systems in your computer and correctly configure itself automatically most times.
Occasionally it needs a small correction to an operating system's entry in the menu.lst file, but not very often. When IDE and SCSI (SATA) drives are used together it can mean some manual adjustments will need to be made.
Other boot loaders need to be set up manually every time.

5) The GRUB Menu is completely customizable to suit different computers and individual preferences. The GRUB menu and much of GRUB's behavior is controlled by our /boot/grub/menu.lst (menu list) text files.



____________________________First step Backing up your Grub menu_________________________


Code: Select all
sudo cp /boot/grub/menu.lst /boot/grub/menu.lst_backup

This copies your "menu.lst" to menu.lst_backup

To use the backup
Code: Select all
sudo cp /boot/grub/menu.lst_backup /boot/grub/menu.lst




__________________________Temporarily Edit the GRUB Menu________________________________

Here's another way to boot with GRUB when you're having a few issues and you can't just boot up the normal way.
Here's an example where some-one's monitor goes blank on them during booting and they can't see what's happening, it's just a blank screen and they wait but it doesn't boot.
This is how to get into the GRUB menu and add kernel options.
You can use a similar method to get into your GRUB menu and make non-persistent changes for any other reason as well, but I'll show you this one for an example.

When your computer is first booting, you'd be running in 'VGA' mode, which is a simple video mode from the BIOS.
Here is a link to an excellent howto which explains all we need to know about the vga= option, HOWTO: Change bootup resolution, by Indras
Then when Ubuntu boots it loads the operating system's video drivers and you get a much nicer display.

Normally, even if you had a blank screen during boot-up, there would be no harm in that. You just wouldn't see anything for a while and then when it gets to the part where the video driver kicks in and Ubuntu comes up, you'd get your display back.
You could first try simply waiting a while in case it's just doing a file system check.

The main concern is, it could be stopping at some error and you can't read the error message because you have no display at that stage.
Maybe try pressing 'Enter', followed by 'Ctrl'+ 'D', in case it's hanging at the file system check. That would get you over that.
You'd still need to wait a minute for it to finish booting.....
Okay, so you tried waiting for ages already and still nothing....

Try this then, when you reboot and you see your Grub menu,
Ubuntu, kernel 2.6.15-26-386
Ubuntu, kernel 2.6.15-26-386 (recovery mode)
Ubuntu, memtest86+
Other operating systems:
Microsoft Windows XP Home Edition

Use the up or down arrow keys to select which entry is highlighted.
Press enter to boot the selected OS, 'e' to edit the
commands before booting, or 'c' for a command-line.


The highlighted entry will be booted in 10 seconds.

This menu remains for ten seconds in most computers, before Linux (Ubuntu) begins to load by default.
Press any key to stop the timer when you're at the GRUB menu.
If you read the text underneath the GRUB menu it says you can press 'e' to edit the commands before booting.
You can make non-persistent changes to the GRUB menu by pressing your 'e' key, and editing commands and options in your GRUB menu.

So press your 'e' key.

Then you should see a different Grub menu,
root (hd0,5)
kernel /vmlinuz-2.6.22-14-generic root=UUID=51ba7905-7da5-4079-b8b6-->
initrd /initrd.img-2.6.22-14-generict
quiet


Use the up or down arrow keys to select which entry is highlighted.
Press 'b' to boot, 'e' to edit the selected command in the
boot sequence,'c' for the command-line 'o' to open a new line
after ('0' for before) the selected line, 'd' to remove the
selected line, 'd' or escape to go back to the main menu.

This gives you another sort of GRUB menu, it's sort of like your 'behind the scenes' GRUB menu.

You can move the highlight bar over any line you need to and press 'e' to edit it.
For example, to edit your kernel options, press your down arrow key to go down one line to the line beginning with the word 'kernel' and press 'e' again.
At the end of that line and it should say 'ro quiet splash_', those are kernel options that are passed to your kernel from GRUB during boot-up.
At the end of that line, make a space and then type 'vga=ask', (without the inverted commas).
Then press the 'Enter' key.
Press 'b' to boot.
On the next screen, it should say,
Starting up . . .
Press<RETURN> to see video modes available, <SPACE> to continue or wait 30 secs


{color]Press 'Enter'. !Don't press you space bar or you'll have to do it all again![color]

It should give you a choice of vga settings you can try in an effort to get some display during boot-up.
Video adapter: VESA VGA
Mode: COLSxROWS:
0 0F00 80x25
1 0F01 80x50
2 0F02 80x43
3 0F03 80x28
4 0F05 80x30
5 0F06 80x34
6 0F07 89x60

Enter mode number or 'scan': _

In my laptop I can type in 'scan', which doesn't do anything for me, but it might fix yours. I'd say try that first.
Then, there's a choice of numbers between 1 and 6 that correspond with different capabilities of your display.
Hopefully that will sooner or later let you to be able to see the text messages that normally run behind the boot splash screen during a regular boot-up, but show up to tell you what's wrong when there are errors. Then whatever the problem is that's holding up the booting procedure can be solved,depending on what the exact problem turn out to be.

That was just one example of how to use the 'e' for edit feature to temporarily edit the GRUB menu for one boot-up. It's possible to make any changes to the GRUB menu this way you need in order to boot your operating system.
Once the operating system is booted then it will be easy to edit the /boot/grub/menu.lst file and make more permanent changes.


___________________________Customizing your GRUB Menu ___________________________________


_____________Changing the default (operating system booted by the timer)_________________
# 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 change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default [color]0[color]

The number after the default command sets which operating boots by default when the countdown timer reaches 0 if no keys are pressed on the keyboard.

For dual booting with certain operating systems that seem to require rebooting very often, it can be a real pain in the neck after a while to have to be there and manually intervene every time the computer reboots.

There are three possible ways to set this, choose the one you like best,

1. Paste your Windows entry above the beginning of the debian automagic kernels list
2. edit the number for the operating system entry to be booted (by the timer)
3. edit the number and type 'saved' there instead.

1) Paste your Windows entry above the beginning of the debian automagic kernels list
You can cut the entire Windows entry from where it is under the end of the automagic kernels list and paste it above the beginning of the automagic kernels list.
Above this line: ### BEGIN AUTOMAGIC KERNELS LIST

What NOT to do- don't paste your Windows entry anywhere inside the automagic kernels list because it will be deleted when you have a kernel update in Ubuntu.

2) edit the number for the operating system entry to be booted (by the timer)

This little line controls which operating system boots by default, Ubuntu or some other operating system entry like another Linux, or Windows.
If you really want to have some other operating system booting first by default, you need to have a look at the bottom section of your menu.lst file at the operating system entries.
Ubuntu is entry number 0 because the GRUB numbering system begins counting from 0.
(From the top of the list,counting down).
Count down from the top, (from just below where it says '## End Default Options ##').
Begin counting with the number 0, the number of entries containing the word 'title'.
You don't count the entries the are 'hashed out' (with a # in front of them, skip those).
Stop counting when you reach the Windows entry, and that number you end up with will be the right number to replace the number 0 with after the word 'default'.

In this example, it will be the number 4 which you would use in place of the 0 after the word 'default' to cause Windows to boot by default.
That would most likely be true for the majority of standard dual boot installations.

Windows is behind the fifth appearance of the word 'title'. Don't forget, you start counting from the number 0. So it's not 1,2,3..., it's 0,1,2,3..., okay? Count each time the word 'title' appears and in this example you will see that Windows is number 4 (counting from 0).

Don't be afraid to experiment if you aren't sure, this won't hurt anything if you don't get it right. All this setting does is make the highlight rectangle in the GRUB menu appear on a different line, that's all. You can easily change that again if it turns out wrong. It's a safe line to edit.

3) Edit the number and type 'saved' there instead.
Use this method if you want to avoid having to re-edit menu.lst when you have a new kernel added to the list during an update. (Thus changing the number that your default operating system is on the list).

Rather than just replacing the number '0' in the line, 'default 0' with another number, you can type the word saved in place of the '0'.
For example:
default saved
That will cause GRUB to remember whatever menu entry you booted last time.
The highlight (selection) rectangle in your GRUB Menu will appear on that line again next time you reboot.

The way this works is by use of the command 'savedefault', included in most GRUB operating system boot entries at the bottom of menu.lst.
When we type 'saved' rather than a number here, after 'default', it causes GRUB to save that information to the /boot/grub/default file and refer to it next time we boot.

Most people would be content with that, however, if even this isn't good enough for you, it is possible to take the idea one step further and make GRUB boot only one operating system by default.
Here is how to trick GRUB to only remember one particular operating system entry.
Just place a # (hash mark) in front of the 'savedefault' command in the other operating system entries (at the bottom of your menu.lst), that you do not want GRUB to remember.
Then GRUB will only be able to remember (save) the operating system entry that does not have the # mark in front of the 'savedefault' command.



________________________Setting the timer for the boot loader ____________________________
default 0

splashimage=(hd0,1)/boot/Ubuntusplash.xpm.gz

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout [color]10[color]

Following the word timeout above, you'll see the number 10. This sets the timer for the boot loader to boot the default operating system if no-one presses any buttons on the keyboard.
We can delete the number 10, and in its place type in any number of seconds we'd prefer the timer to be set to.

***Warning*** DO NOT SET THIS TO 0, COULD MAKE YOUR SYSTEM UNBOOTABLE ***********************

If we want to turn off the timer, comment out the line, we insert a # mark before the commands and this will cause the program to ignore the whole line. Then the GRUB menu will theoretically wait forever until you make a decision, select an operating system, and press enter. (Or until there's a power failure).



_____________________________Hiding the GRUB menu during bootup_____________________________
timeout 10

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
[color]#[color] hiddenmenu

If we want the computer to pay attention to the hiddenmenu command and to hide the GRUB menu on start-up, we could 'uncomment' the line with the hiddenmenu command on it by deleting the # symbol.


_____________________________Add some color to your GRUB menu_______________________________
# hiddenmenu

# Pretty colours
# [color]color cyan/blue white/blue[color]

The line for color can be uncommented ( delete the # ) and that will cause the GRUB menu that we see when the computer is starting up to appear with colors, instead of just plain old black and white.

The colors cyan/blue white/blue the given defaults. There are quite a few other colors you can use, and you can make up your own combinations. To do that, just delete the colors given there as an example and type or paste in your own color combinations. Some of the color combinations I tried are listed below.

command font&border/panel hilited font/rectangle
color black/brown yellow/black
color black/green yellow/black
color black/magenta white/red
color white/red light-gray/black
color light-gray/blue black/light-gray

You can also cause the GRUB menu to have a blinking foreground color by inserting 'blink-' before the foreground color, for example,

color black/brown blink-yellow/black
color blink-white/red light-gray/black

An easy way to experiment with the different color combinations for your GRUB menu, instead of editing your menu.lst file and rebooting every time, is to use GRUB's Command Line.
Press 'c' from the GRUB menu when your computer is booting to get a GRUB Command Line.
Type the word color as a command, followed by some colors you want to try. For example,
Code: Select all
grub>  color white/red light-grey/black

Then press 'Enter', then press 'Esc' to see what your GRUB menu will look like with those colors. Press 'c' again and try some different colors, and so on until you decide on the colors you want. Then boot and edit your /boot/grub/menu.lst with your chosen colors.


___________________________Boot partition________________________________________________
## default grub root device
## e.g. groot=(hd0,0)
[color]# groot=(hd0,1)[color]

'groot' is short for 'grub root device'. That will be the partition you want your new Linux kernel to be installed in when you get a new one during an update. Your /boot partition is the partition you should specify here.
If you have a standard installation, with a /boot directory in your root partition, (/ ), then the number you will see here will be the same as the number you will see for kopt.
If you have a special installation with a separate /boot partition, the number you should see here will be the the partition number of your /boot partition.

It's unlikely you will need to change this unless you have just finished doing some work with your disk partitioning software and changed your partition numbers somehow, or added a new /boot partition that you might not have had before, or something like that.
In that case you should also check your operating system entry to make sure the GRUB 'root' option is pointing to the correct device as well.


___________________________defoptions_____________________________________________________
## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
[color]# defoptions=quiet splash[color]

This means every time a new kernel is added to the list, the new kernel's default entry ( the one we normally use for booting) in menu.lst will be accompanied automagically by the option '=quiet splash'.
quiet means we won't see a lot of white typing scrolling up a black monitor background to explain every step of the process of booting up the system, (unless something special is there we might want to see, like a file system check).
splash means we will see a nice picture in our monitor while our computer is booting. Some people customize these splash screens too. It's a different sort of splash screen than the one behind the grub menu.


_____________________________howmany=all__________________________________________________
## 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
[color]# howmany=all[color]


This controls how many kernels can be listed in the kernels list. Each time a kernel is updated it is added at the top of the list and the old kernel remains in the list, but is moved down.
If you don't like having a big long kernels list and having to hash out or delete kernels, then unhash 'howmany=all', and replace 'all' with a number of your choosing. I like to set mine to 1. That keeps my GRUB menu much tidier. If I ever decide I need to revert to an older kernel I can always do that by booting manually with Grub's Command Line Interface.



____________________________memtest86=true________________________________________________
## should update-grub create memtest86 boot option
## e.g. memtest86=true
## memtest86=false
[color]# memtest86=true[color]

I like having memtest86+ always available in my GRUB menu. It isn't compulsory and some people prefer to keep their GRUB menu brief for appearances sake. Perhaps you have a nice splashimage and want to see more of your pretty picture or something like that. You may have a copy of memtest86+ on a live cd they can run if you need to. Okay then, if that's your preference, just alter this option to 'false' and GRUB won't put it there anymore.


__________________________________________________________________________________________
Below here are our operating system entries, the list we see and can select from each time our computer boots up. A mistake in any of these entire can cause problems for us when booting. So this is where most of the editing takes place after installing a new operating system or changing our hard disks and/or partitions around.
__________________________________________________________________________________________



_______________________________Operating System Entry____________________________________
title Ubuntu, kernel 2.6.20-15-generic
root (hd0,1)
kernel /boot/vmlinuz-2.6.20-15-generic root=UUID=fe7bf845-7ce9-4733-b6de-f70f2b62076d ro quiet splash
initrd /boot/initrd.img-2.6.20-15-generic
quiet
savedefault

Each group of five of six lines beginning with a GRUB command is called an operating system entry.
In the left-hand column are GRUB commands like title, root, kernel, initrd, savedefault and boot.
The command , 'title' means the words on the line after it will be displayed as a boot option in your GRUB menu. You can replace the words on that line with anything you like and your computer will still boot up the same way. You'll just see a different message in your GRUB menu. Some people like to edit out 'kernel 2.6.20-15-generic' and replace it with the host name of the operating system instead. A nice host name has more meaning to most people and it's a nice way to customize your GRUB menu with a personal touch.



___________________Add your system's hostname to the GRUB Menu___________________________
title [color]Ultimate Edition 1.7[color]
root (hd0,1)
kernel /boot/vmlinuz-2.6.15-25-386 root=/dev/hda2 ro quiet splash
initrd /boot/initrd.img-2.6.15-25-386
savedefault
boot

Edit your title
Another thing that is okay to change, are the words after the word 'title', for example where it says 'Ubuntu', or 'Windows'. I changed those words in my computer to the host-name for each operating system. It makes it easier when I have a lot of operating systems running, to tell them apart. You can even type some other message there if you like.
If you edit your line for title, you can also make that persistent during kernel updates, see Edit /usr/sbin/update-grub

You will notice that the commands you type into GRUB's CLI (command Line), are exactly the same as the ones found on the bottom section of /boot/grub/menu.lst
You may need to alter some of these commands for various reasons, that's okay as long as you are sure there's a back-up made for your menu.lst file in case you get in trouble.



_______________________A Quick Guide to GRUB's Numbering System__________________________
floppy disk drive = (fd0)
First hard drive = (hd0)
second hard drive = (hd1)
third hard drive= (hd2) ... and so on.

First partition = 0
second partition = 1
third partition = 2 ... and so on
To combine these now:
first partition on first hard drive = (hd0,0) = /dev/hda1 in Linux
2nd partition on first hard drive = (hd0,1) = /dev/hda2 in Linux
3rd partition on first hard drive = (hd0,2) = /dev/hda3 in Linux
4th partition on first hard drive = (hd0,3) = /dev/hda4 in Linux

5th partition on first hard drive = (hd0,4) = /dev/hda5 in Linux
6th partition on first hard drive = (hd0,5) = /dev/hda6 in Linux
7th partition on first hard drive = (hd0,6) = /dev/hda7 in Linux
8th partition on first hard drive = (hd0,7) = /dev/hda8 in Linux
9th partition on first hard drive = (hd0,8) = /dev/hda9 in Linux
10th partition on first hard drive = (hd0,9) = /dev/hda10in Linux


first partition on second hard drive= (hd1,0) = /dev/hdb1 in Linux
2nd partition on second hard drive= (hd1,1) = /dev/hdb2 in Linux
3rd partition on second hard drive= (hd1,2) = /dev/hdb3 in Linux
4th partition on second hard drive= (hd1,3) = /dev/hdb4 in Linux
GRUB makes no distinction between sda and hda drives




____________________How to make a dedicated GRUB Partition_______________________________

A dedicated GRUB partition is a special partition just for GRUB, it just has GRUB files in it.
This will mean GRUB will be 'operating system independant'.
In other words, even if you delete your operating system, or systems if you have more than one, you'll still have your GRUB bootloader.
A dedicated GRUB partition can serve any number of operating systems.
A dedicated GRUB partition is great for people who muti boot.
If you have a complex multi-boot set-up, with several hard disks, it might even be a good idea to have several dedicated GRUB partitions, one for each hard disk.
Each hard disk's GRUB can list the operating systems in that disk, and chainload the MBR of each of the other hard disks. It would be kind of like going up and down in an elevator.
That would be a nice way to break down the number of operating system entries into managable numbers in each GRUB menu .

A separate /boot partition is not the same things as a dedicated GRUB partition.
A separate /boot partition can cure GRUB error 18, but a dedicated GRUB partition won't.
A separate /boot partition contains the operating system's kernel as well as the bootloader files. A separate /boot might not necessarily have GRUB files in it, it could have LiLo instead.
A separate /boot partition means a partition that belongs to an operating system and is mounted as /boot in the operating system's /etc/fstab file.
It not usual for more than one operating system to be able to share the same separate /boot partition, it can be done but it requires a clever work around.
The only reason anyone would want a separate /boot partition is to cure GRUB error 18 problems. How to make a separate /boot partition.
A dedicated GRUB partition will be a lot better than a separate /boot partition for most people.

The rest of this article is about how to make a dedicated GRUB partition.

1) Just make a small partition anywhere on your hard drive with any partition editor you like. I use and recommend GParted -- LiveCD.
GRUB by itself doesn't take up very much room on your hard drive. Probably 100 MiB would be way more than enough.
Format it with a file system. An ext2 filesystem will be fine, and ext3 would be even better. FAT 32 should work too, probably any file system GRUB supports will do.
The ext2 file system is the earlier version of the ext3 file system, they are the same except the ext3 file system features 'journalling'. I normally just use ext3, but many Linux experts suggest ext2 for bootloader partitions for some reason. I haven't seen an explanation for that yet.
Journalling is supposed to makes the file system more reliable, but slows it down a wee bit and needs more administrative blocks, taking up just a tiny wee bit more hard drive space. Unless you are setting up in a USB flash disk you probably won't notice the extra disk space needed for ext3. The speed difference also seems negligible to me, I can't tell the difference, it's too small to be measured.


2) Reboot your computer, make a mount point and mount the new GRUB partition.
Let's pretend for this example we are making a new GRUB partition in /dev/hda8,
herman@red:~$ ls /media/
cdrom cdrom0 floppy floppy0 hda1 hda2 hda4 hda6 hda7 hda8 hdb1 hdb2 hdb4
herman@red:~$ sudo mkdir /media/GRUB
Password:
herman@red:~$ sudo mount -t ext2 /dev/hda8 /media/GRUB/

3) For the sake of uniformity, make a directory named /boot in your new GRUB partition.
herman@red:~$ sudo mkdir /media/GRUB/boot
(Where /media/Grub is the path and name of the directory I mounted my new GRUB partition in).

4) Copy a /boot/grub directory to the new partition,
herman@red:~$ sudo cp -r /boot/grub /media/GRUB/boot/

5) Get the new GRUB partition's menu.lst file with,
herman@red:~$ sudo gedit /media/GRUB/boot/grub/menu.lst

6) Delete all the old operating system boot entries in the new GRUB partition's menu.lst file and replace them with configfile boot entries instead.
Any Windows operating systems and any Linuxes that don't boot with GRUB will still need chainloader boot entries of course.
You can use direct kernel boot entries if you want, but you'll need to update those manually after each operating system has a kernel update.

7) Re-install Grub from your new GRUB partition to MBR.
herman@red:~$ sudo grub

[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]

grub> find /boot/grub/stage1
(hd0,1)
(hd0,5)
(hd0,6)
(hd0,7)
(hd1,1)

grub> root (hd0,7)

grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p (hd0,7)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded
Done.

grub> quit


8) Give all your operating systems a test boot-up to make sure everything's working fine and dandy.
If everything's good, you can (when you are ready) delete or hash out your extra operating systrem entries in your other menu.lst files if you won't use them any more. (Or just leave them there if they look neat and tidy enough and they don't bother you).




_______________________________MBR Backup and Restore______________________________________

If you are thinking of re-installing Windows, and leave your Ubuntu install in place, normally Windows will automatically over-write GRUB's 'IPL' in your MBR, and you will need to re-install GRUB. If you want to take a shortcut, you can easily back up your MBR in Ubuntu using some 'dd' commands.
Code: Select all
sudo dd if=/dev/hda of=/home/herman/GRUBMBR.img bs=446 count=1
**********************

Where: herman is my username (you must substitute your own username in place of 'herman' unless your name is herman too),
You may substitute anything you like for a name for the file. I don't always call mine 'GRUBMBR', I recommend something descriptive, possibly including a date in the file name. It might also be an idea to make your own 'readme' text file to remain in a folder where the MBR back up is stored to explain what the file is. For example, whether it has GRUB or LiLo on it, or Windows IPL. This may come in handy if you end up with several similar files.
1+0 records in
1+0 records out
446 bytes copied, 4.3e-05 seconds, 10.4 MB/s


When I open /home/herman directory, I should find a file named GRUBMBR.img there somewhere, and I can then copy it anywhere I like to store it until it need to be used.

Notice:
The command shown here does not back up the entire 512 bytes of the MBR, just the first 446 bytes.
That is to deliberately exclude the partition table.

Some people may prefer to include the partition table. That may be useful for some purposes, but be sure you destroy that copy of your MBR if you decide to re-partition your disk later. If you accidentally restore your MBR backup with an out of date partition table, it will not match your new filesystems. It will cause your disk to be unreadable. Unless it is very important data you will probably have to give it up and reformat and repartition your disk and loose all your data and have to start again.

If you only want the to make a backup copy of the bootloader code, you only need the first 466 bytes of the MBR, so it will not include the partition table. That is much safer. That is what I do, and what is shown here.

Restore command:
Code: Select all
sudo dd if=/home/herman/GRUBMBR.img of=/dev/hda bs=446 count=1
*********************
Where: herman is my username (you must substitute your own username in place of 'herman' unless your name is herman too),
and where: GRUBMBR.img is the name of your MBR backup file.
Of course, you would need to plan in advance how you will access this MBR back-up on your hard-disk when you can't (automatically) boot Ubuntu. You could still boot from GRUB's Command Line, or from a GAG Boot Manager CD, or just use a Live CD to mount your Ubuntu partition and issue the command to restore your MBR that way. (Mainly for experienced users).



____________________________Edit /usr/sbin/update-grub__________________________________

The reason for editing /usr/sbin/update-grub in this example is just to make a customized title for Ubuntu persistent through kernel updates.

Since I multi boot all the time, I like to have the right names for my operating systems listed in my GRUB menu when I'm booting up.
I want to see if I'm going to boot 'Ubuntu', Kubuntu, 'Xubuntu' or 'Edubuntu', as the case may be, not have them all just listed as 'Ubuntu'.
I also want to see if I'm going to boot, 'Feisty Fawn', 'Gutsy Gibbon', or 'Hardy Herron'.
I want to know exactly which operating system I'm going to boot.
herman@badboy~:$ grep --color -n 'title' /usr/sbin/update-grub
299:title="Ubuntu"
415:# title Windows 95/98/NT/2000
420:# title Linux *****************all "title" in red************
648: echo -n "title " >> $buffer
654: echo -n "$title" >> $buffer
1057: defaultEntry=$(grep "^[[:blank:]]*title" $menu | sed -ne "${defaultEntryNumberPlusOne}p" | sed -ne ";s/^[[:blank:]]*title[[:blank:]]*//p")
1195:title Chainload into GRUB 2
1255: newDefaultNumberPlusOne=$(grep "^[[:blank:]]*title[[:blank:]]*" $menu | grep -n "${defaultEntry}" | cut -f1 -d ":" | sed -ne "1p")
1289: newDefaultNumberPlusOne=$(grep "^[[:blank:]]*title[[:blank:]]*" $menu | grep -n "${defaultEntry}" | cut -f1 -d ":" | sed -ne "1p")

This is how I use grep with the --color and -n parameters to show me where to start looking in my update-grub script for all lines that contain the word 'title'. Line number 299 will be the line I'll be looking for. This make it a little quicker to find what I'm looking for because update-grub is a very large file, I could get lost. (Like a little kid in a big department store). :)

Code: Select all
gksudo gedit /usr/sbin/update-grub

When I open Gedit, it's easy to find the right line now. All you have to do is click 'Edit'-->'Preferences', and under the 'View' tab, mark the checkbox for 'display line numbers'.

# the device for the /boot filesystem
boot_device=$(find_device "/boot")

# Full path to the device.map
device_map=$grub_dir/device.map

# Enable crashdump menu alternative
crashdump="0"

# Default kernel options, overidden by the kopt statement in the menufile.
kopt="root=$(awk '$2 == "/" {print $1}' /etc/fstab) ro"

# Title
title=[color]"Ubuntu Feisty"[color]

# should update-grub remember the default entry
updatedefaultentry="false"

# Drive(in GRUB terms) where the kernel is located. Overridden by the
# kopt statement in menufile.
# if we don't have a device.map then we can't use the convert function.
check_removable=""
if test -f "$device_map" ; then
if test -z "$boot_device" ; then
grub_root_device=$(convert_default "$root_device")
check_removable="$(is_removable "$root_device")"
else
grub_root_device=$(convert_default "$boot_device")
check_removable="$(is_removable "$boot_device")"
fi

This line used to just say "Ubuntu", but I have edited mine with my own title the way I want it to remain, and remain persistent even after every kernel update.
Some people might like to add their system's host name there instead, or in addition to that.

_____________________________NEW In Gutsy Gibbon_________________________________
The title line has changed a little, it now includes the lsb_release command.
(type:~$ man lsb_release in a terminal, if you want to find out more about that command).

Here's another way to open a file and find the right place in it pretty quickly. Use the text editor nano for that. It's easy to find the right line to edit using nano.
Code: Select all
sudo nano /usr/sbin/update-grub

That will open update-grub in nano for you.

Then in nano, press 'Ctrl'+'W' and type the word: Title
and press your 'Enter' key.

That will get to the right line in your /usr/sbin/update-grub file. It looks like this,
# the device for the /boot filesystem
boot_device=$(find_device "/boot")

# Full path to the device.map
device_map=$grub_dir/device.map

# Enable crashdump menu alternative
crashdump="0"

# Default kernel options, overidden by the kopt statement in the menufile.
kopt="root=$(awk '$2 == "/" {print $1}' /etc/fstab) ro"

# Title
[color]title=$(lsb_release --short --description 2>/dev/null) || title="Ubuntu"[color] *********

# should update-grub remember the default entry
updatedefaultentry="false"

# Drive(in GRUB terms) where the kernel is located. Overridden by the
# kopt statement in menufile.
# if we don't have a device.map then we can't use the convert function.
check_removable=""
if test -f "$device_map" ; then
if test -z "$boot_device" ; then
grub_root_device=$(convert_default "$root_device")
check_removable="$(is_removable "$root_device")"
else
grub_root_device=$(convert_default "$boot_device")
check_removable="$(is_removable "$boot_device")"
fi
else
grub_root_device="(hd0,0)"
fi

You can still make changes if you want, and when you are finished, press 'Ctrl'+'O' to write them out, followed by 'Ctrl'+'X' to quit.


The 5 minute version
____________________________________________________________________________________________
The following is copied from [url=http://www.tuxmachines.org/node/16701]tuxmachines.org[/url
Thanks to srlinuxx
_________________________________How-to Edit Grub___________________________________________




The first thing I do is copy and paste an existing entry. No sense in retyping all of that and chances are you will probably want to use the same kernel parameters for the new install that you've used for previous. So:

1. Copy and paste your favorite existing entry either where you think you'd like it or at the end of the list.

2. Start the edit. The first thing one might need to consider is the title. This is easy, just change it to a meaningful name for your new install. In "Tryst's" case, he needed a new entry for PCLinuxOS 2007. So, he could have used PCLOS2007. Unlike Lilo, with Grub you can use names with spaces, so he could have used PCLOS 2007 if he chose.

3. Now the bit more tricky part, the root. This is the component that specifies where the boot kernel is. Is it in a shared /boot partition or is it in the /boot directory of the new install?

* First case scenario: Let's say you told the installer about your seperate /boot partition and it installed the boot kernel into it. The root component must then point to your shared /boot partition.

The format might look scary at first, but it isn't. In the true Unix fashion, it begins its numbering with 0 (zero). The first number indicates the harddrive number. So, hda is 0, hdb is 1, hdc is 2, and so on. So, more than likely your boot partition is located on hda and in which case 0 is the number you want there. Just remember it's N - 1.

The second number is the partition number. Again, hda1 is 0, hda2 is 1, and so on. So, say your /boot partition is located at sda5 you'd want to put a 4 there. So, your root entry might look like so:

root (hd0,4)

* Second scenario: You told the installer to install Grub onto the / (root) partition of the new install or you chose to skip installing Grub altogether. In this case the root component needs to point to the install partition. So, for example, say your new system is installed on hdb8, your root parameter should read:

root (hd1,7)

4. The next component is the kernel. This entry can contain lots of boot parameters but the most important is the correct name of the boot kernel. So, ls the /boot partition or directory to get that name.

* If it's in a shared /boot partition you will need to just specify the name of the kernel as if in the working directory, like so:

/vmlinuz-2.6.18.8.tex5
* If it's on the install partition, then it will need to list the directory on that partition in which the boot kernel is found, like so:

/boot/vmlinuz-2.6.18.8.tex5
o Another necessary component of the kernel line is the root partition. This is in the more tradition partitioning scheme and points to the install partition. So, in our example, it should point to hdb8 like so:

root=/dev/hdb8 (or root=/dev/sdb8)
o Next is the resume. If you wish to use some advanced powersaving features such as suspend to disk, then you'll want a resume parameter listed. This is your swap partition where the disk image is stored. Again, the format is the more commonly used /dev/hdxX pattern. In my case, my swap is /dev/sda6, so it should look like:

resume=/dev/sda6
o You may also have other kernel parameters set here, such as splash=silent, vga=788, or noapic, whatever. These are system specific and usually already in place if you just copied an original working entry as in step 1.

5. The final necessary component is the initrd. Not all boot kernels use or require an initrd, but most larger modern systems like openSUSE, Mandriva, and PCLOS do. This usually contains filesystem modules you might need to mount the system partition or the purdy boot splashes we like so much. You can tell if you need one by issuing ls -t in /boot directory of the new system or in the shared /boot partition. -t tells it to list by time, so you can see your newest files first. If one doesn't exist in the /boot directory, or you can't find one that matches the boot kernel, then you can assume you don't need one.

If there is one listed, then you'll need to tell Grub about it. In "Tryst's" case, he does. So:
* First case scenario: initrd /initrd-2.6.18.8.tex5.img
* Second case: initrd /boot/initrd-2.6.18.8.tex5.img

That's it, that should get you in. If you need to, you can temporarily edit any grub entry at boot time, usually by hitting the "e" key. You will probably have to hit "e" again when the edit the entry screen appears to edit the particular component. Then you can hit "b" to boot it. You'll need to edit the grub.conf (or menu.lst) to make it permanent.

As stated this is how I do it and there is a lot more to Grub than discussed here. But hopefully this will help one edit their grub.conf or menu.lst file to boot their new Linux partitions.

PS. Windows and Unix (bsd) use entries like so:

title windows
root (hd0,0)
makeactive
chainloader +1
1st Box: Ultimate Edition 2.0 x64/ 1.8 x64
2nd Box: XP (dusty)
3rd Box: Stable Media box Ultimate Edition 1.8 x64 with XBMC

The Oxen are slow but the Earth is patient ~Chuen~
User avatar
LeadFingers
U.E. God
U.E. God
 
Posts: 1303
Joined: Fri Nov 23, 2007 1:46 am
Location: Salem Oregon
Age: 63
Operating System: Ultimate Edition 3.1 64 BIT

Return to How To's (Do not post questions please)

Who is online

Users browsing this forum: No registered users and 8 guests