grub2下启动ISO

Over the past couple of years, I've grown to love using USB sticks to boot Linux installers. Booting from USB is much faster than booting from CD, preparing the USB stick is quicker than burning a CD, and you don't have to throw away the USB stick when you're done with it. This is wonderful for playing with new alpha releases of Ubuntu, for quickly getting started at installfests, and generally makes life much easier.

However (I said to myself one morning), could the process be even better? There have been a few times now where people have wanted different variants (Kubuntu, Xubuntu, Netbook Remixes, etc.) of Ubuntu, and with the standard USB Creator (which is an awesome tool, by the way) method, you can only have one on there at once. Is there some way I could put all of my images on one stick, and preferably have them on there as .iso files so I can also use the stick as a source for burning CDs for people? It turns out that -- thanks to the magic of GRUB2 -- there is!

(Warning: this entry gets a little technical, and involves terminal-fu. One day, maybe, there will be a way of doing this that is normal-person-friendly. Unfortunately, today is not that day.)

  1. Format a partition on the USB stick to some filesystem that's supported by GRUB 2 in the way you prefer to do that. I personally used FAT32, with the command sudo mkfs.vfat /dev/sdc1. You could also use gparted, if you prefer GUI tools.

  2. Mount the partition and write down the mountpoint.

  3. Install GRUB 2 onto the USB stick. The command I used for that was grub-install --no-floppy --root-directory=/mnt /dev/sdc (note: the last parameter is the device, not the partition). You'd put your mountpoint instead of /mnt, and your device instead of /dev/sdc.

  4. GRUB will automatically make a boot/ folder on the partition. Make a folder to put your ISO files in (I made boot/iso/).

  5. Edit boot/grub/grub.cfg to point to the ISO files. You can do this manually, by copypasting this gibberish once for each ISO (replacing the menu name and both references to example.iso):

    menuentry "Menu Name in GRUB boot menu goes here" {
    loopback loop /boot/iso/example.iso
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/example.iso noeject noprompt --
    initrd (loop)/casper/initrd.lz
    }

    I think the above magic only works for *buntu Live CDs. If you're using ISOs of something else, you'll likely have to experiment to find the right settings (feel free to leave a comment so others don't have to ;).

  6. You're done! Restart and boot from USB to try it out!

If editing grub.cfg manually for each ISO file feels like a chore, you feel the same way as me. I wrote a small script to do it for me just now that seems to work well, so you might want to try that out. It's at http://rww.name/scripts/create-menu.sh.txt. Open it up and edit the variables at the top to point to the right mountpoint and directories, and note that it will remove any existing grub.cfg on the USB stick, so be careful. If you have any improvements or comments, I'd be happy to hear them; my shell scripting skills are terrible, so it could probably be a lot better.

Now, when I boot from the USB stick, I get a menu with all of the ISOs I have listed in it, and I can boot whichever combination of 32-bit or 64-bit Ubuntu/Kubuntu/Xubuntu/UNE/KNE 9.10/10.04 I want! Phew! The only caveat I've found is that it skips the usual Live CD screen and boots straight into Live mode. If you know a way to get it to not skip it, I'd be interested to hear about it :)

Sources: I got the basic instructions for this from panticz.de, which appears to have gotten the grub.cfg stuff from Michael Prokop.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值