| WARNING: GRUB2 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 2 Manual. |
Page Index
grub-install - usr/sbin/grub-install - a script to install GRUB on a device grub-install installs Grub bootloader on the specified INSTALL_DEVICE drive (which can be a GRUB device name or a system device filename). grub-install copies GRUB images into the DIR/boot directory specified by --root-directory (default is "/"), and uses grub-setup to install grub into the boot sector. --modules=MODULES - Pre-load specified modules MODULES --root-directory=DIR - Install GRUB images under the directory DIR instead of the root directory --grub-setup=FILE - Use FILE as grub-setup --grub-mkimage=FILE - Use FILE as grub-mkimage --grub-mkdevicemap=FILE - Use FILE as grub-mkdevicemap --grub-probe=FILE - Use FILE as grub-probe --no-floppy - Do not probe any floppy drive. --recheck - Probe a device map even if it already exists (8)grub-install This command is probably the most important command on this page, it runs four of the other commands. This command should be able to automatically fix most problems with GRUB 2. This command creates a /boot/grub directory if there isn't already one in the root partition. Then it copies GRUB *.mod, *.lst and *.img files files from /usr/lib/grub/i386-pc/ into the /boot/grub/ directory. It runs grub-probe to scan the computer and gather disc and partition information. It makes a new device.map with grub-mkdevicemap. It runs grub-mkimage which builds a new core.img, and calls grub_setup to install the grub boot.img and the core.img to the device (disk or partition). 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. Recover Grub 2 via LiveCD - Ubuntu Wiki EXAMPLES BELOW How To Check Installed GRUB Version Number
How to install, update and repair GRUB This should fix almost any ordinary GRUB 2 problem and will be the most often used command for GRUB 2. For most ordinary people it will be about the only command they'll need to use.
If you're not sure which hard disk's MBR you want to install GRUB2 to, it's possibly best to install GRUB to all of your disks, just to make sure. If you want to install GRUB2 to the boot sector of a partition, you may use something like /dev/sda1 or /dev/sda2 for installing GRUB's boot.img to a partition boot sector. The practice of installing GRUB2 to partition boot sectors is not encouraged, it is better to install GRUB2 to a MBR. If you insist on installing GRUB to a partition boot sector, please be careful and make sure you only install GRUB to a Linux partition! Don't blame GRUB if you are silly enough to make a mistake and install to the wrong partition boot sector! Good things about the grub-install command are that this command runs several other commands at the same time, including grub-probe, grub-mkdevice.map, grub-mkimage, grub which saves the user some work. Also, grub-install refreshes all your important GRUB files in /boot/grub as well. Run grub-install may be run as often as you like and especially when trying to fix a GRUB2 problem. Non-good things about the grub-install command are 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 - Karmic Koala and later. 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 GRUN 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 - /usr/sbin/update-grub - script - generates a new /boot/grub/grub.cfg file This script runs other scripts and programs such as grub-mkdevice.map and grub-probe and then generates a new grub.cfg file. update-grub - automatically generate a new /boot/grub.grub.cfg file 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 (8)update-grub, (8)update-grub2 Example,
The output can be expected to look something like this,
grub-mkconfig - /usr/sbin/grub-mkconfig - a script for making a new /boot/grub/grub.cfg file. As far as I know this command is supposed to be used in preference to update-grub in Karmic Koala and later versions of Ubuntu. Earlier version of Ubuntu didn't seem to contain this script. 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. This script also runs other scripts and programs such as grub-mkdevice.map and grub-probe and then generates a new grub.cfg file. NAME grub-mkconfig - manual page for grub-mkconfig (GNU GRUB ) SYNOPSIS grub-mkconfig [OPTION] DESCRIPTION Generate a grub config file -o, --output=FILE output generated config to FILE [default=stdout] -h, --help print this message and exit -v, --version print the version information and exit examples,
The output that appears in the terminal looks the same as the output for the ' update-grub' command, 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 special or tricky 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 - /usr/sbin/grub-set-default - Script to set a default boot entry for GRUB. grub-set-default sets a boot entry in the menu.lst to be booted by default if no keys are pressed and the timer is allowed to run out. It does that by writing to a file called /boot/grub/default This is the same file that the grub.cfg command 'savedefault' writes to.
No manual entry for grub-set-default See 'man 7 undocumented' for help when manual pages are not available. (8)grub-set-default grub-mkrescue - usr/bin/grub-mkrescue - a script to make a bootable floppy disc image or run genisoimage to make an .iso file for burning to disc to make a bootable rescue CD. By default, the image will contains all the modules available in the current grub distribution, thus the name rescue. 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). NAME grub-mkrescue - manual page for grub-mkrescue (GNU GRUB 1.96) SYNOPSIS grub-mkrescue [OPTION] output_image DESCRIPTION Make GRUB rescue image. -h, --help print this message and exit -v, --version print the version information and exit --modules=MODULES pre-load specified modules MODULES --overlay=DIR overlay directory DIR in the memdisk image The content of the directory DIR will be added (overlaid) to the rescue image content. This is especially useful if you want to include your grub.cfg, and any additional files such as splashimages and themes and so on. DIR is the root folder, which will be known as (memdisk)/ at boot time. It will contain /boot/grub. --pkglibdir=DIR use images from directory DIR instead of /usr/lib/grub/i386-pc --grub-mkimage=FILE use FILE as grub-mkimage --image-type=TYPE select floppy or cdrom (default) --emulation=TYPE select El Torito boot emulation type floppy or none (default) (cdrom only) grub-mkimage generates a bootable rescue image of the specified type. (8)grub-mkrescue How To Make Your Own GRUB2RESCUE CD-ROM 1st example for grub-mkrescue,
Where: I want the program to name the file 'GRUB2CD.iso'
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. No manual entry for grub-probe See 'man 7 undocumented' for help when manual pages are not available. (8)grub-probe |