| GNU GRUB is a work in progress and the information in this website is incomplete and may be wrong and/or out of date. Please consult the official GNU GRUB 1.98-r2692 manual. |
Page Index
grub-install - usr/sbin/grub-install The grub-install command runs a script called usr/sbin/grub-install and is mainly used for writing GRUB to a device such as a hard disk drive, SSD or flash memory drive. The grub-install command
Run 'man grub-install' in a terminal in any Ubuntu operating system for more information. NOTE: You need to have the operating system booted to run this command because it will only work from inside the running operating system. If you can't get your operating system to boot the regular way, but you can get at least get GRUB, then you should be able to get it to boot by using GRUB2 CLI Mode Commands. If you still can't get the operating system to boot up at all you probably need to boot a Live CD and chroot into your operating system to run this command. How to chroot - use a Live CD or another Ubuntu installed in a hard disk or USB to fix your GRUB EXAMPLES BELOW How To Check Installed GRUB Version Number
How to install or refresh GRUB
Normally, most people will want to install GRUB to MBR in the first hard disk if Ubuntu is installed in a so-called 'internal' disk inside a computer. By an 'internal' disk I mean a disk that is more or less 'permanently' connected to the motherboard by IDE ribbon cables or SATA cables. If your computer has more than one hard disk and you're not sure which hard disk's MBR you want to install GRUB2 to, it might be best to install GRUB to all of your disks, just to make sure. If you have Ubuntu installed in a so-called 'removable' disk, such as a USB 'external' drive, or any disk that you intend to remove from the computer, you should probably install GRUB to the MBR of the same disk you have Ubuntu installed in only, meaning your USB external drive. If you want to install GRUB2 to the boot sector of a partition for some strange reason, you may use something like /dev/sda1 or /dev/sda2 for writing GRUB's boot.img to a partition boot sector. The practice of installing GRUB2 to partition boot sectors is not encouraged. It reduces GRUB's reliability and it could be dangerous to other operating systems if users use the grub-install command carelessly or ill-informed and write GRUB to the wrong boot sector. You need to have the operating system booted first, before you can use the command. If the operating system you're trying to fix won't boot you need to chroot into it from another operating system such as a Live CD operating system before you can run grub-install. In that situation it might be easier to use grub-setup instead, please refer to How To Re-install GRUB from Live CD - with grub-setup. The grub-install command doesn't run grub-mkconfig (or update-grub), so the user still needs to run one of those commands if a new grub.cfg is wanted. See grub -mkconfig - make a new grub.cfg file. How to make a Dedicated GRUB Partition Why would anyone want a 'Dedicated GRUB 2 Partition? When GRUB 2 is in its own dedicated partition it is 'operating system independant', so we can add or remove one or two operating systems without the inconvenience of losing the boot of the remaining operating systems. Those of us who are multi-booting with more that two operating systems in their computer like to be able to set their own user friendly names for their operating systems. It's okay to edit the grub.cfg directly when GRUB 2 isn't part of an operating system, making it easier to do what we like with GRUB and have fun with it and learn more GRUB commands and tricks.
Where: I want to make a new /boot/grub directory and fill it with GRUB files. Where: '/dev/sda' is the hard disk in which I want to write the stage1 code to MBR in That command creates a new /boot and /boot/grub/ directory if one doesn't already exist, and creates or refreshes GRUB files in /boot/grub, all except for grub.cfg. If you don't make a grub.cfg then there will be no GRUB Menu and your computer will boot to a GRUB Command Line Interface, see GRUB2 How To Boot From CLI Mode If you want a GRUB Menu you need to make a grub.cfg file and copy it to /boot/grub. You can make your own grub.cfg file and customize it in any way you like. The proper way to do it would be to use the grub-mkconfig command, and alter the file path to make it point to the 'Dedicated' /boot/grub/'. See How to Update the GRUB Menu . Another way would be to make your own grub.cfg, if you need an example to help you get started, look here, grub.cfg - Grub Wiki. Or, copy and paste this one, grub.cfg, to a blank text file, name it grub.cfg, edit it to your needs and paste it in your Dedicated /boot/grub. Later, you can also make and add other files such as background images. I had trouble getting my 'Dedicated GRUB 2' to display any background image at first. I was getting 'error: No video mode activated', after trying the background_image command in CLI Mode. I needed make a fonts folder in my 'Dedicated GRUB 2 Partition and copy the fonts from /usr/share/grub/unicode.pff and /usr/share/grub/ascii.pff into it. Then I had to correct the fonts path in my grub.cfg header area,
After that I was able to display my splashimage in my 'Dedicated GRUB 2 Partition'. to do (Herman) ... revise and this how-to more user freindly. How to make a GRUB_II USB GRUB 2 could be very handy in a USB. You can use it for an emergency boot disk. You can play with it and use it for doing interesting experiments with to learn more about GRUB without compromising your real GRUB. It's okay to edit the grub.cfg directly when GRUB 2 isn't part of an operating system. 1. Choose an USB drive with at least about 60 MiB of space in the partition for grub 2 files, but a little more room than that might be advisable. It can be formated with any file system, it doesn't mattter if there are already some files in it. 2. Plug in your USB drive while Ubuntu is running, it should be automatically mounted in a few seconds and an icon should appear for it on your desktop. 3. Find out what is the real mount point name, (if you don't already know), this step is important because the actual mount point in /media can have another name than the name you see for the icon on your Desktop. Code:
example output
If yours comes up as a file system UUID number, I recommend you set your own user freindly file system label to make things easier for yourself now and in the future. How To Set File System Labels With GParted. 5. Find out what is the /dev/number for the file system (or partition),
example output
6. Run grub-install ,
Where: The MBR to install GRUB to is /dev/sdb (the USB drive). NOTE: I didn't install GRUB to /dev/sdb1, because that's the partition boot sector. I need GRUB in the USB disk's MBR, which is called /dev/sdb in this case, since the partition is /dev/sdb1. Watch the thumb drive's LED blink for a few seconds. Now you have a bootable GRUB 2 USB Rescue disk. But it has no grub.cfg 7. Run grub-mkconfig
8. Relax the file permissions to make it easily editable from GUI mode, (user freindly). Let's make it editable so we can play with it.
Now we can open it in GUI mode even if we want and edit the grub.cfg file to our heart's content. Links: Use cases - Ubuntu 8.10 on USB device - GRUB Wiki How to add GRUB to your USB thumb drive - (GRUB Legacy) update-grub The update-grub command runs a script called /usr/sbin/update-grub ,which just runs another script called /usr/sbin/grub-mkconfig, see grub-mkconfig, (the next item, below). Here's what /usr/sbin/update-grub looks like,
The only reason this command still exists is because it's easy for new users to remember and it's simple. I think running a command that doesn't have any options is boring. My advice is to skip this command and start getting used to using the grub-mkconfig command instead. It's not a big step and only requires a wee bit more intelligence, you can do it if you try! grub-mkconfig The grub-mkconfig command runs a script called /usr/sbin/grub-mkconfig, which runs other scripts and programs such as grub-mkdevice.map and grub-probe and then generates a new grub.cfg file. As far as I know this command was supposed to replace update-grub in Karmic Koala and later versions of Ubuntu. This command is more versatile than update-grub because we can use the -o option to have the results printed to a any filename and file path we like. That's a useful feature. Examples,
You need to use the -o option and specify a filepath and file for grub-mkconfig to write to if you want grub-mkconfig to do something useful,
You can make up any file path and file name here, but most of the time people will probably want to write to their /boot/grub/grub.cfg if they are serious about actually updating the file. We could use the -o option to direct the output of grub-mkconfig to some other file if we want to do something interesting with GRUB. We could have more grub.cfg files by making new ones with names other than 'grub.cfg'. For example, we could have /boot/grub/grub.cfg and /boot/grub/grub.cfg2 and /boot/grub/grub.cfg3 and so on if we wanted to. We might want to do that and use the 'configfile' command to change from one GRUB menu to another at boot time. The configfile commands can be added as a custom command in 40_custom, or any other script we like. For another example, we might want to direct our /boot/grub/grub.cfg to some other mounted partition, such as a 'Dedicated GRUB Partition', or GRUB in a USB drive. We can do that just by changing the file path after the -o option. grub-set-default - Script to set a default boot entry for GRUB. The grub-set-default command runs a script in /usr/sbin called grub-set-default. That script sets the boot entry in the grub menu to be selected by default and to be booted automatically if no keys are pressed and the timer is allowed to run out. Before that will work, the top line in the /etc/default/grub file that looks like 'GRUB_DEFAULT=0' needs to be changed to 'GRUB_DEFAULT=saved'. See Editing /etc/default/grub. Make sure you remember to run 'sudo grub-mkconfig -o /boot/grub/grub.cfg after editing yout /etc/default/grub file, for the changes to take effect. From now on you can run 'sudo grub-set-default' any time you like,
grub-mkrescue The grub-mkrescue command runs a script called usr/bin/grub-mkrescue. This can make either a bootable floppy disc image or run genisoimage to make an .iso file for burning to disc to make a bootable rescue CD. Bootable cdrom images use cdboot.img loader, which are capable of accessing the ISO9990 cdrom to load extra modules (see the (8) genisoimage -b option). How To Make Your Own GRUB2RESCUE CD-ROM 1st example for grub-mkrescue, (Karmic Koala and earlier),
Where: I want the program to name the file 'GRUB2CD.iso'
Expected Results -
How To Make Your Own GRUB2 Floppy Disc The grub-mkrescue command for making a floppy disc is the same as the command for making the .iso file but you need to add the option: --image-type=floppy. Probably it would be best to use a different filename extension too.
example thread: Installing grub2 bootloader in fd0 The old fashioned way to make a GRUB CD was to copy GRUB files to a folder and then run the genisoimage command on your folder to create and .iso image. After that you can burn the .iso image to disc. Link: How to make your own personalized GRUB CD-RW - (GRUB Legacy) Link: How to make your own personalized GRUB Floppy Disk.- (GRUB Legacy) We can still probably use the old method with GRUB 2 if we want to, but the grub-mkrescue command does it a lot easier and faster and with far fewer commands than the old way of doing things. The grub-mkimage command gets the thumbs up from me. GRUB2 How To Boot From CLI Mode - NEW! Rescue your System grub-setup - usr/sbin/grub-setup.exe (writes images to device, used by grub-install) grub-setup [device] Either install the boot.img file to a MBR plus the core.img install just to the sectors after the MBR, or the boot.img file to a partition boot sector. NAME grub-setup - manual page for grub-setup (GRUB) 1.96 SYNOPSIS grub-setup [OPTION]... DEVICE DESCRIPTION Set up images to boot from DEVICE. DEVICE must be a GRUB device (e.g. ‘‘(hd0,1)’’). -b, --boot-image=FILE use FILE as the boot image [default=boot.img] -c, --core-image=FILE use FILE as the core image [default=core.img] -d, --directory=DIR use GRUB files in the directory DIR [default=/boot/grub] -m, --device-map=FILE use FILE as the device map [default=/boot/grub/device.map] -r, --root-device=DEV use DEV as the root device [default=guessed] -h, --help display this message and exit -V, --version print version information and exit -v, --verbose print verbose messages (8)grub-setup Examples, How To Re-install GRUB The following two commands will work from withing a running Ubuntu operating system
How To Install GRUB to a Partition Boot Sector
(The GRUB from the operating system you're working in will be installed to /dev/sda2). NOTE: GRUB 1.96 didn't seem to like having it's IPL installed to a partition boot sector, it complained and required the use of --force to get it to work. TIP: If you can't boot Ubuntu in the normal way you can use your GRUB2RESCUE CD and see the following link, GRUB2 How To Boot From CLI Mode - NEW! Rescue your System. Alternatively, you could use your Ubuntu Live CD and mount the operating system concerned and chroot into it to run these commands. How To Re-install GRUB 2 From A Live CD without the need to chroot. 1) Boot your Ubuntu Karmic Koala or later 'Desktop' Live CD, or another Karmic installation such as an operating system in a USB device or whatever you have to use as a as a rescue disk. Tip: It will make your Ubuntu life a lot easier if you take a few minutes to set a nice user-freindly file system label in your linux file systems, How To Set File System Labels With GParted. 2) The operating system you want to fix needs to be mounted. Just go 'Places'-->'Removable Media' or just 'Places' and look under 'Computer' for the disk or partition you want to mount and click on it. - also see Click-Icon Mounting. You should see an icon for it on your desktop, but what you may not see is the 'mount point', which will normally be located in your /media directory. We will need to know the file path and name of the mount point. 3) Find the name of the mount point,
4) Run the grub-setup command, inserting the -d option and specifying the path to the /boot/grub directory of the operating system you're trying to fix,
Please substitute the word 'disk' with the name of your own mount point as found in step 3) The '/dev/sda' part tells grub-setup to install GRUB to MBR in the first hard disk, which is called '/dev/sda'. You may use the same command to install GRUB in any other disks in your computer by replacing the /dev/sda part of the command with /dev/sdb or /dev/sdc and so on. - If the command fails with feedback about not being able to access a device.map file, you might need to try again and specify the exact device.map file to use with the -m option.
example thread: Computer won't boot to 9.10; No Grub Menu ============= More to do with the grub-setup command,
With the -c option you can also specify the file path and file name for a specific core image you want to install to an new partition. I wasn't able to get these two working the last time I tried. grub-mkfont - /usr/bin/grub-mkfont - a program for changing fonts to make then suitable for use by GRUB. For working with graphical GRUB menus. I don't know much about this subject yet ... sorry for any inconvenience. See the GNU GRUB Wiki: gfxterm: Help for graphical terminal. grub-mkdevicemap - usr/sbin/grub-mkdevicemap.exe (generates a new device.map file) Users would rarely need to concern themselves with this command, it's for use by other programs or scripts. grub-mkdevicemap automatically generates a new device.map file for grub (the file containing the mapping between the GRUB device names, and the system device names. That file is used at installation time but not at boot time. NAME grub-mkdevicemap - manual page for grub-mkdevicemap (GRUB) 1.96 SYNOPSIS grub-mkdevicemap [OPTION]... DESCRIPTION Generate a device map file automatically. -n, --no-floppy do not probe any floppy drive -s, --probe-second-floppy probe the second floppy drive -m, --device-map=FILE use FILE as the device map [default=/boot/grub/device.map] -h, --help display this message and exit -V, --version print version information and exit -v, --verbose print verbose messages (8)grub-mkdevicemap, - (5)grub_device.map. grub-mkimage - usr/bin/grub-mkimage.exe (Makes a new boot image, used by grub-install/mkrescue) Makes a new core.img (boot image), that's the image is typically copied on the first sectors of a hard disk after the MBR. grub mkimage isn't a script that users need to concern themselves with, it's just supplied to be used by grub-install. and grub-mkrescue. grub-mkimage makes a bootable image of GRUB, compressed with lzo [usually named core.img]. NAME grub-mkimage - manual page for grub-mkimage (GRUB) 1.96 SYNOPSIS grub-mkimage [OPTION]... [MODULES] DESCRIPTION Make a bootable image of GRUB. -d, --directory=DIR use images and modules under DIR [default=/usr/lib/grub/i386-pc] -p, --prefix=DIR set grub_prefix directory [default=/boot/grub] -m, --memdisk=FILE embed FILE as a memdisk image -o, --output=FILE output a generated image to FILE [default=stdout] -h, --help display this message and exit -V, --version print version information and exit -v, --verbose print verbose messages grub mkimage - (8)grub-mkimage grub-probe - usr/sbin/grub-probe.exe (Probes for device info, used by scripts) grub-probe isn't a script that users need to concern themselves with, it's just supplied to be used by other programs. grub_probe detects the required partmap (pc partition table, disklabel...) and abstraction (lvm, raid) modules. The program that invoked grub-probe can gather the information. Normally, grub-probe is automatically invoked by grub-install or grub-mkconfig or update-grub. NAME grub-probe - manual page for grub-probe (GRUB) 1.98-1ubuntu7 SYNOPSIS grub-probe [OPTION]... [PATH|DEVICE] DESCRIPTION Probe device information for a given path (or device, if the -d option is given). -d, --device given argument is a system device, not a path -m, --device-map=FILE use FILE as the device map [default=/boot/grub/device.map] -t, --target=(fs|fs_uuid|drive|device|partmap|abstraction) print filesystem module, GRUB drive, system device, partition map module or abstraction module [default=fs] -h, --help display this message and exit -V, --version print version information and exit -v, --verbose print verbose messages REPORTING BUGS Report bugs to <bug-grub@gnu.org>. (8)grub-probe |
| chroot from a Linux LiveCD This is useful an emergency method for working on a Linux operating system , even when your Linux system is unbootable, and even if there is no boot loader at all installed in the operating system. 1) Boot a Ubuntu Live CD, Ubuntu in a USB, or another installed Ubuntu. NOTE: If you have a PC with a dual core processor, you could have either an i386 or amd64 (dual core) Ubuntu installation. You will need the Live CD or other Ubuntu installation with the same architecture as your installed Ubuntu (the one you want to operate on), in order to chroot successfully. 2) Mount your Ubuntu File System You can use just go 'Places'-->'Removable Media', and click on the icon representing your desired partition for mounting now in all modern versions of Ubuntu. TIP: If your icon appears with a name something like 'XY GB Filesystem', then you might want to take a little time out right now to go and set yourself some nice user friendly file system labels on all of your file systems. See How To Set File System Labels With GParted - recommended. For example, my Ubuntu Lucid Lynx file system is simply labelled as: LYNX 3) Open a terminal - 'Applications' --> 'Accessories' -->'Terminal', Check to see what the name of the mount point for your Ubuntu file system is in /media,
If you haven't set a user friendly file system label, the mountpoint folder in /media will be named after the file system's UUID number instead, which is not so user friendly. For me, my mountpoint will be named LYNX, because that's what I set for the file system label. From now on, please replace the word 'LYNX' with whatever the actual name of your own mount point is. (Yours might be different than mine). For LVM encrypted installations, your mount point may be arbitrarily called: luksvolume You need to install lvm2 cryptsetup and run sudo modprobe dm-crypt and then you should be able to mount and chroot the same as everyone else. 4) chroot into the Ubuntu install New: chroot method now updated based on the following Ubuntu Web Forums thread: how to chroot, simple and fast, by taavikko
Now you can run whatever commands you need inside your chrooted file system to fix your Ubuntu installation. NOTE: You don't need to type 'sudo' in front of your commands because you have a root shell, so be careful ! Some commands I have found useful are grub-install and grub-mkconfig, apt-get update and apt-get upgrade. You should be able to apt-get install software packages and run any other commands you think might be helpful. When you're through, type 'exit',
It's considered good practice to umount, (at least I think it's probably a good idea),
|