Boot from ISO using GRUB2

Goal is to install new OS from an ISO image without creating a boot CD.

Step 1:  Format hard disk to be used with a boot partition.  (set boot flag)

Step 2:  Mount partition, create new directory named ‘boot’ (in this case the partition automatically mounted as /media/brian/boot, so new directory is /media/brian/boot/boot).  Copy the ISO file(s) you want to use to a  subdirectory named grml.  (or anywhere else)

Step 3:  Use ‘fdisk -l’ or ‘parted -l’ to figure out what the drive is (in this case it is /dev/sdj)

Step 4:  Install grub2 to the disk and specify a boot directory (if you don’t specify the boot directory, it will assume /boot — which is your current system. (assume grub2 is already installed)

$ sudo grub-install –boot-directory=/media/brian/boot/boot /dev/sdj

Step 5:  Unmount hard drive and physically install it in new computer, boot up, should get grub> prompt.

Step 6:  Use ‘ls’ command to determine location of partition and folder.  In GRUB2, disks start with 0 and partitions start with 1.  In this case, (hd0,msdos1) is the first partition of the first drive.

grub> ls (hd0,msdos1)/boot/grml

The names of the ISO files I had copied step 2 are shown after this command.

Step 7:  Issue the following commands from the grub prompt to boot from the desired ISO file:  (tab key works as auto-complete in grub shell) (this is for Ubuntu-style OS)

grub> loopback loop (hd0,msdos1)/boot/grml/xxxx.iso

grub> linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/grml/xxxx.iso noprompt noeject

grub> initrd (loop)/casper/initrd.lz

grub> boot

Step 8: Now computer should boot up just as if you are booting from a CD/DVD.  Install OS as normal.  The Ubuntu installer requires the /isodevice to be unmounted, but it can’t do it on its own.  So before running the installer:

$ sudo umount -l -r -f /isodevice
This entry was posted in How-To and tagged , , , , , , , , , . Bookmark the permalink.

One Response to Boot from ISO using GRUB2

  1. Brian Gallimore says:

    Step 1: setting boot partition flag is mostly pointless with GRUB
    Step 2: wound up needing to move contents of /boot director into /

    Crunchbang:
    I couldn’t get Debian/Crunchbang to run from an ISO, no matter how hard I tried. I could boot to the live environment by copying the contents of the ISO to the hdd using a dd command, but then I lost the install menu on bootup. I wound up using a USB stick, using this command to copy the contents of the ISO file:
    sudo dd if=/path/to/iso/crunchbang-10-20101205-openbox-i686.iso of=/dev/sdX bs=4M;sync

Comments are closed.