首先,要使用ISO文件,当然,硬盘上得有,所以先下载好ISO文件存放在某个分区,比如/HOME目录(最好不要发那个在根分区,如果根分区空间不够的话,同样也别放在/boot分区,因为你给/boot分区的指定的空间也可能是不大的)。
接着我们的GRUB2要建立 menuentry , 但是我们需要操作系统ISO里的两个文件,即 内核和文件系统镜像(kernel, initrd image)。
内核的链接文件是 vmlinuz ,镜像文件的链接是initrd.img
On other bootable Linux ISOs and utility CDs, these files may be located in other folders and may be named differently (vmlinuz0, initramfs, etc). Note that some non-Ubuntu ISOs contain an initrd image with a.gz extension rather than the .lz extension now used by Ubuntu.
在linux的图形界面中查看ISO文件的内容
你在linux中使用 解压缩工具(Archive Manager)查看ISO文件里的内容。
如果你要在终端中查看的话(输入命令,回车之后会弹出图形界面),可以使用 “file-roller ”或者“ gksu file-roller ” 这两个命令。
如果要在LINUX命令行终端直接查看的话:
可以把ISO镜像挂载到系统,通过通常查看文件的方式来查看ISO中的内容。
sudo mount -o loop /home/username/Downloads/ubuntu-desktop-amd64.iso /mnt/iso/
示例:
sudo mkdir /mnt/iso # Optional - the ISO file can be mounted on an existing mount point if desired. sudo mount -o loop // .iso /mnt/iso gksu nautilus /mnt/iso sudo umount /mnt/iso # When finished inspecting the contents.
ls |
显示grub已知的分区; Display partitions known to GRUB. |
ls (hdX,Y)/ |
显示X硬盘上Y分区中的的某个文件夹; Display the contents of the / folder on /dev/sdXY |
To mount an ISO via the GRUB terminal, determine the location/path of the ISO file, then:
通过GRUB终端的命令挂载 ISO镜像 :
loopback loop (hdX,Y)/ |
Example: loopback loop (hd0,5)/my_isos/ubuntu-12.04-desktop-amd64.iso |
Once mounted via the above command, the ISO can be inspected using thels command. The ISO will be mounted on "(loop)".
挂载之后,可以使用ls命令查看:
ls (loop)/ |
||
ls (loop)/casper |
casper是ISO镜像当中存放vmlinuz 和 initrd.lz 两个文件的文件夹; On an Ubuntu ISO, this should display vmlinuz and initrd.img, among other files. |
$ ll -h /mnt/mt_iso/casper/
总用量 1.3G
dr-xr-xr-x 2 root root 2.0K 2011-04-27 18:57 ./
dr-xr-xr-x 12 root root 4.0K 2011-04-27 18:57 ../
-r--r--r-- 2 root root 73K 2011-04-26 10:35 filesystem.manifest
-r--r--r-- 2 root root 39K 2011-04-26 10:15 filesystem.manifest-desktop
-r--r--r-- 2 root root 10 2011-04-26 10:38 filesystem.size
-r--r--r-- 2 root root 1.2G 2011-04-26 10:42 filesystem.squashfs
-r--r--r-- 2 root root 13M 2011-04-26 10:36 initrd.lz
-r--r--r-- 2 root root 4.4M 2011-04-11 17:15 vmlinuz
An easy way to create a GRUB menuentry is to add it to the /etc/grub.d/40_custom file. Add the menuentry below the existing lines in the file.
gksu gedit /etc/grub.d/40_custom
sudo update-grub
The following is an example GRUB menuentry for Ubuntu 12.04's 64-bit ISO, located in the user'sDownloads folder of sda5.
menuentry "Ubuntu 12.04 ISO" { |
set isofile="/home/ |
loopback loop (hd0,5)$isofile |
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject |
initrd (loop)/casper/initrd.lz |
} |
构造: The menuentry constructed above is built with the following considerations.
标题 ; The menuentry title (between the quotations) is determined by the user. Any title can be used. The line must end with{
The set isofile line should reflect the exact name of the ISO file
The loopback line must reflect the actual location of the ISO file.In the example, the ISO file is stored in the user'sDownloads folder.
(hd0,5)/boot/$isofile |
Located in the system's normal /boot partition on sda5 |
(hd0,6)/$isofile |
Located in a separate boot partition on sda6 |
(hd0,7)/username/Downloads/$isofile |
Located in a separate home partition on sda7 |
(hd1,2)/iso/$isofile |
Located in the /iso folder of the sdb2 data partition |
指定内核镜像和相关参数;每个linux发行版的内核镜像文件名可能是不一样的;
This line is specific to the Ubuntu family of ISOs. Other Linux distributions and system ISOs may use different filenames, folders and switches to boot their ISOs. Check theGrub2/ISOBoot/Examples page to see if an example exists. The user can alsomount the ISO and explore its contents to ensure the menuentry contains the correct filenames and paths.
指定文件系统镜像;ubuntu的是 initrd.lz
See the linux line notes. Additionally, some other systems useinitrd.gz rather than initrd.lz on their ISOs.
If the ISO is stored on a partition formatted differently than your main operating system, it may be necessary to load the module for the specific format before GRUB can access it. In this case,add the following line immediately after the menuentry line for the desired format (ntfs, reiserfs, etc). It should not be necessary, but if GRUB cannot read the ISO theiso9660 module can also be loaded:
如果硬盘的分区是GRUB不认识的文件系统格式,那么需要在 menuentry 这行之后 加入需要的文件系统的格式,如下:
insmod ntfs |
insmod iso9660 |
For more information on creating a custom menuentry, please visitGrub2/CustomMenus.
A sample entry copied from the grub.cfg and altered by the user might look like this *:
menuentry "My Default Precise" { |
recordfail |
gfxmode $linux_gfx_mode |
insmod gzio |
insmod part_msdos |
insmod ext2 |
set root='(hd0,msdos9)' |
search --no-floppy --fs-uuid --set=root dbd69ed2-530c-4409-8f5a-a3f1ea41fc67 |
linux /boot/vmlinuz-3.2.0-24-generic root=UUID=dbd69ed2-530c-4409-8f5a-a3f1ea41fc67 ro quiet splash $vt_handoff |
initrd /boot/initrd.img-3.2.0-24-generic |
} |
search --no-floppy --fs-uuid --set=root dbd69ed2-530c-4409-8f5a-a3f1ea41fc67 ##注释:这个UUID是/boot分区的uuid,如果/boot属于根分区,没有单独分区,那这里的UUID跟下行的UUID是一模一样的。 |
linux /boot/vmlinuz-3.2.0-24-generic root=UUID=dbd69ed2-530c-4409-8f5a-a3f1ea41fc67 ##注释:这个UUID是根分区的UUID,即/ 所代表的分区,如果/boot有单独分区,那么这个UUID与上行的UUID是不一样的,在我的系统中显示的是/dev/sda5; ro quiet splash $vt_handoff |