1、fdisk /dev/sdb给U盘分区,其中sdb1为vfat,用于平时的文件存放;sdb2为linux,格式化为ext2,存放启动的grub的模块与相关配置。 设置sdb2为active(可启动)。
2、用lsblk -f或blkid /dev/sdb2获得/dev/sdb2的uuid。
3、挂载/dev/sdb2到/mnt/disk0,执行grub-install --no-floppy --root-directory=/mnt/disk0 /dev/sdb
4、配置文件copy:
# cp /boot/grub/grub.cfg /mnt/disk0/boot/grub/grub.cfg
# mkdir -p /mnt/disk0/etc/default
# cp /etc/default/grub /mnt/disk0/etc/default # cp -a /etc/grub.d /mnt/disk0/etc5、修改grub.cfg中的menuentry,例如:
menuentry 'TinyCore' {
recordfail load_video gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos2' search --no-floppy --fs-uuid --set=root 96810d5f-6a43-4c40-821c-58443477953f linux /tce/boot/vmlinuz quiet waitusb=5:UUID="96810d5f-6a43-4c40-821c-58443477953f" tce=UUID="96810d5f-6a43-4c40-821c-58443477953f" initrd /tce/boot/core.gz } menuentry 'Ubuntu 16.04.1 livecd amd64' class iso{ insmod part_msdos insmod ext2 set isofile="/iso/lubuntu-16.04.1-desktop-amd64.iso" set root='hd0,msdos2' loopback loop (hd0,msdos2)$isofile linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=${isofile} quiet splash initrd (loop)/casper/initrd.lz }####memdisk (from syslinux)
menuentry "Boot WinPE ISO" --class windows {
set root=(hd0,msdos2) echo 'Loading Memdisk...' linux16 /memdisk iso raw echo 'Loading ISO...' initrd16 /WINPE.iso }menuentry "Windows XP" {
set root=(hd0,x) ntldr /ntldr boot }
----------------------------------------------------
其它:
操作系统中update-grub的脚本在/usr/sbin下,相当于:
set -e
exec grub-mkconfig -o /boot/grub/grub.cfg "$@"