Boot GRUB 2 on an emulator (2008)
Creating the Floppy
For creating a rescue floppy or CD-ROM image, use the grub-mkrescue command.
Running
Now you can test the image by running qemu -fda floppy.img
Boot GRUB 2 on a real system without installing
The core image of GRUB 2 is also a Multiboot kernel, so you can load GRUB 2 by GRUB Legacy:
grub> root (hd0,0) grub> kernel /boot/grub/core.img grub> boot
You can generate core.img with grub-install (GRUB 2) by following way:
grub-install --grub-setup=/bin/true /dev/sda
Change /dev/sda to match your device.
Note: This will not install GRUB 2 (core.img) to your MBR. Instead it executes /bin/true for installation which does not do the actual installation. It will prepare core.img and copy necessary files to /boot/grub folder.
After this you can use grub-mkconfig (or it's alias update-grub) to generate /boot/grub/grub.cfg.
grub-mkconfig -o /boot/grub/grub.cfg
Boot GRUB 2 via PXE
You can boot GRUB 2 via PXE by creating an image file in this way:
cat pxeboot.img core.img >pxegrub
Then, you can load this file as a boot image.
Installing GRUB 2 into a real system
WARNING: before installing it, make sure to backup your system!
You can also install GRUB 2 into a real system by grub-install. The usage is very similar to the grub-install in GRUB Legacy. But, beware GRUB 2 counts partitions from 1 and not from 0 like GRUB Legacy! So, increase the numbers. And, not like GRUB Legacy, it does not understand NTFS.
./configure --prefix=/boot/grub-1.95; \ make; \ make install; \ grub-install /dev/hda
installs surprisingly image files into /boot/grub, efficiently messing up with your possible previous instance of GRUB 1!!!
Sample disk layout:
Disk /dev/hda: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 13 104391 83 Linux /dev/hda2 14 136 987997+ 82 Linux swap / Solaris /dev/hda3 137 13510 107426655 83 Linux /dev/hda4 13511 19457 47769277+ 7 HPFS/NTFS
Sample grub.cfg file (alternatively, you can generate one with grub-mkconfig):
# Timeout for menu
set timeout=10
# Set default boot entry as Entry 0
set default=0
# Entry 0 - Load Linux kernel from very first partition of the first disk and mount as root filesystem the third partition
menuentry "Linux 2.6.20" {
set root=(hd0,1)
linux (hd0,1)/vmlinuz-2.6.20 root=/dev/hda3 console=ttyS0,57600n8 console=tty0
initrd /initrd
}
# Entry 1 - Chainload another bootloader, but does not work for NTFS here
# To boot the windows from that partition get Ultimate Boot CD, boot it,
# select F3 for Filesstem Tools, from the next list of options select
# Smart Boot Manager by pressing 3, after the boot manager comes up
# browse the NTFS partition and boot from it. Both grub-0.97 nor 1.95
# cannot do that, somehow.
menuentry "Chainload my OS" {
set root=(hd0,4)
chainloader +1
}
In the Linux kernel 2.6 the device name /dev/hda is changed to /dev/sda .
(The above is not true,... only some device types like SATA devices use the /dev/sdX scheme,... PATA devices still use /dev/hdX)
(If you use libata based pata drivers you get /dev/sdX devices)