当前位置: 首页 > 工具软件 > GRUB2 Editor > 使用案例 >

ISO Booting with Grub 2

商池暝
2023-12-01


ISO Booting with Grub 2

This thread will detail how to place a menu entry in Grub 2 to allow booting an ISO file stored on your computer without a CD/DVD. Not all ISOs will work with Grub 2. The ISO must be constructed in a manner to allow this method of booting. Currently the Ubuntu family ISOs (9.10 and later), Gparted CD, Parted Live CD, and SystemRescue CD, among others, support this feature. 

I have received a report from YorYor in  Grub 2 Basics Post #642 that at least some image files (.img) can also be booted by Grub 2. An example  menuentry is included below.

Note: I have written a guide on booting the Ubuntu ISO from the Grub  rescue prompt in order to repair a previously-working installation. The guide also includes instructions on how to install Ubuntu from the rescue prompt via the Live CD ISO or via the Internet.
HOWTO: Boot & Install Ubuntu from the Grub Rescue Prompt


Being able to mount an Ubuntu ISO via the Grub menu has the following advantages:
  • There is no need to insert a CD/DVD.
  • Boot times of the CD/DVD's ISO is normally faster than booting from an actual CD/DVD.

Downloading ISOs:

Note: Users should consider using torrents to download the ISOs, especially after a new release when servers are likely to be very busy.

Here are a few sites from which users can download bootable ISO images:
Where to place the ISOs:

I prefer storing the ISO files on a non-system partition but for simplicity's sake in this post I will make a new folder in the system's /boot folder called " iso". The ISO files will reside in the sda1 partition in the  /boot/iso folder. In this example, the address of the ISO, translated so Grub2 understands, is: 
(hd0,1)/boot/iso/<iso_filename>

Since 'rescue CDs' such as Gparted are loaded into memory and use a self-contained version of linux, the format of the partition does not matter as long as it is one that Grub 2 can recognize. Additionally, the ISOs like Gparted's can be located on a system partition since the partition is not mounted. This allows the real partition to be resized even if the ISO is located in the same partition.

The user will need to adjust the Grub menu entries to properly point to the correct partition and folder for their own situation.

Note on placing ISO's in a separate /home folder: Many Ubuntu users have a separate HOME partition. If the ISO folder or file is placed in your HOME folder, be sure to use the correct path in the menuentry - do not include "/home" in the path. Since a separate /home partition is only mounted by fstab later in the boot process, Grub 2 will not find the file if the path is designated (hdX,Y)/home/ username/iso/isofilename. 
  • The correct Grub 2 path for an ISO file normally found in /home/username/iso/isofilename would be (hdX,Y)/username/iso/isofilename, with (hdX,Y) being the partition of the separate HOME files and username being the user's login name.
  • Example: / is on sda5, /home/drs305 is on sda10. The iso file is in folder "iso" and the filename is "maverick-desktop-i386.iso". When running Ubuntu, the file can be found at /home/drs305/iso/maverick-desktop-i386.iso.
    In Grub 2, the address would be: (hd0,10)/drs305/iso/maverick-desktop-i386

To make the new folder in which to store the ISOs:
Code:
sudo mkdir /boot/iso
Then copy the ISO file(s) as root to this new folder. 
Note: If you will have your ISO's stored on another partition, be sure the partition is mounted before copying files to the mount point.

To summarize, I have downloaded the ISOs, placed them in the  /boot/iso folder of the  sda1 partition. If I did a search for the Ubuntu Lucid ISO, it would be shown in:
Quote:
/boot/iso/ubuntu-10.04-desktop-i386.iso

Customizing the menuentries:

In the following examples, the user can change the title (between the quotation marks) on the  menuentry line to whatever title is desired.

The filenames reflect the current release version of the ISOs mentioned previously. As newer versions are released the filenames will need to adjusted to reflect the newer filename.


Making the Grub 2 entry:

The following line is not necessary but provides feedback during the execution of "update-grub". It generates a line in the terminal when updating Grub to indicate that the 40_custom file contents are being added to the Grub2 menu:
Quote:
echo "Adding 40_custom." >&2
Sample /etc/grub.d/40_custom file:

The simple way to add entries. The easiest way to incorporate ISOs into the Grub2 menu is to add them to the  /etc/grub.d/40_custom file. Leave the  existing lines in 40_custom as they are, and add the new entries below. The menu items will appear at the bottom of the Grub 2 menu. If you wish the items to appear first, name the menu "06_custom" and make the file executable. Items in "06_custom" will appear before linux and other OS menu items.

Manually creating the menuentry. If you create the entry manually, I recommend a slightly different format for the  menuentry. Incorporating the  set isofile= line to set the path and filename of the ISO file allows for easier troubleshooting and less confusion. It also allows the user to change only one entry if a file's name changes (e.g. version update). I thank forum user  oldfred, who showed me this method. For entries not copied directly from the  grub.cfg file:
Quote:
menuentry "Lucid ISO" {
set isofile="/boot/iso/ubuntu-10.04-desktop-i386.iso"
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject
initrd (loop)/casper/initrd.lz
}

Quote:
#!/bin/sh
echo "Adding 40_custom." >&2
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.


menuentry "Lucid ISO" {
loopback loop (hd0,1)/boot/iso/ubuntu-10.04-desktop-i386.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/ubuntu-10.04-desktop-i386.iso noprompt noeject
initrd (loop)/casper/initrd.lz
}

menuentry "Karmic 64-bit ISO" {
loopback loop (hd0,1)/boot/iso/ubuntu-9.10-desktop-amd64.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/ubuntu-9.10-desktop-amd64.iso noprompt quiet splash
initrd (loop)/casper/initrd.lz
}

menuentry "Gparted Live ISO" {
set isofile="/boot/iso/gparted-live-0.6.1-2.iso"
loopback loop (hd0,1)$isofile
linux (loop)/live/vmlinuz boot=live union=aufs noswap noprompt ip=frommedia findiso=$isofile toram=filesystem.squashfs 
initrd (loop)/live/initrd.img
}


menuentry "SystemRescue CD ISO" {
set isofile="/boot/iso/systemrescuecd-x86-1.5.8.iso"
loopback loop (hd0,1)$isofile
linux (loop)/isolinux/rescue64 setkmap=us isoloop=/systemrescuecd-x86-1.5.8.iso
initrd (loop)/isolinux/initram.igz
}

menuentry "Parted Magic ISO" {
set isofile="/boot/iso/pmagic-5.2.iso"
loopback loop (hd0,1)$isofile
linux (loop)/pmagic/bzImage iso_filename=$isofile boot=live load_ramdisk=1 prompt_ramdisk=0 noeject noprompt 
initrd (loop)/pmagic/initramfs
}

menuentry "Boot IMG - Seagate Tools" {
linux16 /memdisk bigraw
initrd16 /SeaTools.img
}
  • Run "sudo update-grub" after saving /etc/grub.d/40_custom to include the new entries into the Grub 2 menu.

Troubleshooting

If you need to inspect the contents of an ISO for troubleshooting purposes, you can mount it while running a Linux OS with the following commands. You will make a mount point in /mnt and then mount the ISO to  /mnt/temp. After mounting, you can use a file browser to inspect the contents of  /mnt/temp.
  • One example of using the mount command to inspect the contents is to check the initrd file. In bootable Ubuntu ISOs (Karmic & later) the file is initrd.lz In some other third-party ISOs, the file may be initrd.gz rather than initrd.lz.


Code:
sudo mkdir /mnt/temp
sudo mount -o loop /boot/iso/<filename.iso> /mnt/temp
When you are finished:
sudo umount /mnt/temp

This thread is an update of a closed Karmic Testing thread which was created during the early testing of Karmic and Grub 2:
http://ubuntuforums.org/showthread.php?t=1295506


More ISO Menuentries:

If you would like to add examples of other ISO menuentries, please start the post with the OS or Utility Name and place the menu entry within "code" tags.
__________________
GRUB2 :  G2-Tweaks :  G2-Basics :  G2-Tasks :  G2-ISO :  Remove Kernels :  G2-PW :  G2-Chroot :  G2-ISO-Install :  SUM

Last edited by drs305; October 19th, 2010 at 10:38 AM.. Reason: Incorporated "set isofile" for entries not copied from grub.cfg

 类似资料:

相关阅读

相关文章

相关问答