Tim's Web Home

Install grub2 in USB disk

Install grub2 in USB disk:

安装GRUB2到USB硬盘并配置启动

  • 对 USB 硬盘进行分区
      tim $ sudo parted -a optimal /dev/sdc
      # 查看分区情况
      (parted)print
      # 使用parted移除全部分区
      (parted)rm num
      # 设置GPT标签
      (parted)mklabel gpt
      # 创建分区,首先,要告诉parted我们工作要使用的容量单位是megabytes
      (parted)unit mib
      # 创建一个256MB的分区给GRUB2引导器使用,兼容 legacy BIOS 启动
      (parted)mkpart primary 1 257
      (parted)name 1 grub
      (parted)set 1 bios_grub on
      (parted)print
      # 创建 UEFI 引导分区
      (parted)mkpart primary 257 20737
      (parted)name 2 boot
      # 将引导分区标识为EFI系统分区
      (parted)set 2 boot on
      # 创建根分区
      (parted)mkpart primary 20737 102657
      (parted)name 3 rootfs
      # 创建mac数据分区
      (parted)mkpart primary 102657 205057
      (parted)name 4 macdatafs
      # 创建win数据分区
      (parted)mkpart primary 205057 409857
      (parted)name 5 windatafs
      # 创建 win to go 分区
      (parted)mkpart primary 409857 461057
      (parted)name 6 wintogo
      # 创建osxpe分区
      (parted)mkpart primary 461057 466177
      (parted)name 7 osxpe
      # 使用 quit 命令退出parted
      (parted)quit
    
  • 格式化分区
      tim $ sudo mkfs.vfat -F 32 /dev/sdc2
      tim $ sudo mkfs.ext4 -L ROOT /dev/sdc3
      tim $ sudo fatlabel /dev/sdc2 EFI
    
  • 安装GRUB2
      # 挂载引导分区,加上uid和gid参数只是为了编辑文件不需要sudo而已
      tim $ sudo mount /dev/sdc2 /mnt/usbdisk -o uid=$USER,gid=$USER  
      # 先把grub安装到EFI,特别注意--removable参数,安装到移动设备上一定要用这个参数
      tim $ sudo grub-install --target x86_64-efi --efi-directory /mnt/usbdisk --boot-directory=/mnt/usbdisk --removable
      #如果某个target报错,错误信息类似于 grub-install: error: /usr/lib/grub/x86_64-efi/modinfo.sh doesn't exist. 这样的话,就需要先安装grub-efi-modules之类的
      # 安装成功会有以下提示
      #Installing for x86_64-efi platform.
      #Installation finished. No error reported.
      # 再把 grub 安装到 MBR,兼容 legacy BIOS
      tim $ sudo grub-install --target=i386-pc --recheck --boot-directory=/mnt/usbdisk /dev/sdc
      # 安装成功会有以下提示
      #Installing for i386-pc platform.
      #Installation finished. No error reported.
    
  • 复制相关配置文件
      #复制 grub2 的 gentoo 主题
      tim $ sudo cp -rv /boot/grub/themes/GenGrub /mnt/usbdisk/grub/themes/
      # 复制 syslinux 的 memdisk 
      tim $ sudo cp -rv /usr/share/syslinux/memdisk /mnt/usbdisk/grub/
      # 复制中文字体
      tim $ sudo cp -rv /boot/grub/fonts/WenQuanYiMicroHeiMono1* /mnt/usbdisk/grub/fonts/
      # 复制 EFI shell 
      tim $ sudo cp -rv /boot/efi/EFI/Boot/{Shell.efi,shellx64_v1.efi} /mnt/usbdisk/EFI/BOOT/
      # 编写grub2启动配置文件
      tim $ vim /mnt/usbdisk/grub/grub.cfg
    
     file     /mnt/usbdisk/grub/grub.cfg     参考金步国的 GRUB2配置文件"grub.cfg"详解
      #由于"$prefix"的值是在"grub-install"安装时确定的,并且嵌入'core.img'中的模块也是随硬件变化的
      #所以不要只是简单的复制'grub'目录到处使用,而应该在每一个介质上都使用"grub-install"进行安装
      #因为传统BIOS只能识别磁盘前137GB范围,所以GRUB2的安装分区最好完全位于前137GB范围内
      #建议将VFAT文件系统的卷标设为纯大写字母,以确保最大程度的兼容性。
      #[bug]在GRUB2-SHELL中,会以纯小写字母形式显示VFAT文件系统上的纯大写字母文件名(导致视觉上的混淆)
      #可以在 Linux 中使用如下命令格式化VFAT文件系统{卷标="ESP",单元(族)大小=64K[128扇区(最大值)]}
      # mkfs.vfat -v --codepage=437 -nESP -s128  /dev/sdc2
      
      #################
      ## (1)特殊变量 ##
      #################
      #默认启动第一个菜单项
      set default=0
      #如果第一个菜单项启动失败,转而启动第二个菜单项
      set fallback=3
      #优先使用最常规的1024x768分辨率,以保证在不同的屏幕上拥有一致的菜单效果,如果失败再自动匹配分辨率
      #set gfxmode=1024x768
      #可以使用自己制作的24px的大号字体以避免默认字体太小看不清
      #set gfxterm_font=$prefix/fonts/WenQuanYiMicroHeiMono18px.pf2
      #将GRUB2设置为简体中文界面
      set lang=zh_CN
      #指定翻译文件(*.mo)的目录,若未明确设置此目录,则无法显示中文界面。
      #set locale_dir=$prefix/locale
      #每一满屏后暂停输出,以免信息太多一闪而过看不清
      set pager=1
      #开启密码验证功能,并设置一个名为'tim'的超级用户
      set superusers=tim
      #设置菜单的超时时间为30秒
      set timeout=30
      
      #################
      ## (2)公共模块 ##
      #################
      #设置视频模块
      function load_video {
        insmod efi_gop
        insmod efi_uga
        insmod video_bochs
        insmod video_cirrus
        insmod all_video
      }
      #两种最流行的磁盘分区格式
      insmod part_gpt
      insmod part_msdos
      #常见文件系统驱动
      insmod btrfs
      insmod exfat
      insmod ext2
      insmod fat
      insmod iso9660
      insmod jfs
      insmod ntfs
      insmod reiserfs
      insmod udf
      insmod xfs
      insmod zfs
      
      #########################################
      ## (3)公共命令(必须放在模块和变量之后) ##
      #########################################
      #加载中文环境
      if loadfont $prefix/fonts/unicode.pf2 ; then
         set gfxmode=1920x1080,1600x900,1400x900,1366x768,1024x768,auto
         load_video
         insmod gfxterm
         set locale_dir=$prefix/locale
         terminal_output gfxterm
         insmod gettext
      fi
      #图形模式终端
      #insmod gfxterm
      #激活图形模式的输出终端,以允许使用中文和背景图
      terminal_output  gfxterm
      #可用于提供主题支持
      insmod gfxmenu
      #支持GNU国际化与本地化(i18n)函数库
      #insmod gettext
      #一次性加载所有可用的视频驱动
      #insmod all_video
      #背景图片支持
      insmod png
      #设置背景图片
      #background_image $prefix/themes/XXX/XXX.png
      #可以加载自己制作的24px的大号字体文件($prefix/fonts/WenQuanYiMicroHeiMono18px.pf2)
      #loadfont $prefix/fonts/unicode.pf2
      loadfont $prefix/fonts/WenQuanYiMicroHeiMono10px.pf2
      loadfont $prefix/fonts/WenQuanYiMicroHeiMono12px.pf2
      loadfont $prefix/fonts/WenQuanYiMicroHeiMono14px.pf2
      #设置主题
      set theme=$prefix/themes/GenGrub/theme.txt
      export theme
      #让嗡鸣器播放音频
      #play 60 800 1
      #设置'tim'用户的哈希密码[通过"grub-mkpasswd-pbkdf2"工具生成]
      password_pbkdf2 tim grub.pbkdf2.sha512.10000.601AACD16D89299A95EFCEF8B59C5A20CF9994C2F7E932A23028BB81FE197402299BFF6200DE766D76D53ABFB7812B0B13D4AE0BFDAC9D6015E61A18026E7440.7EBDCE68A42A6BE27DB207AFE803C8DF2EB7F957A165416E1C9D78844AC911E8B2CA12979312338771B4A8C296828D6750541F9ECEB9C2B3758960DE7D01E33C
      
      #################
      ## (4)菜单项   ##
      #################
      
      menuentry '正常启动(Windows)' --class windows --class os --users=tim {
        if [ 'pc' == $grub_platform ] ; then
          if search --file --set --no-floppy /bootmgr ; then
      #      drivemap -s (hd0) ${root}
            chainloader +1
          elif search --file --set --no-floppy /ntldr ; then
      #      drivemap -s (hd0) ${root}
            chainloader +1
          else
            echo '没有找到Windows'
            sleep --verbose 5
          fi
        fi
      
        if [ 'efi' == $grub_platform ] ; then
          if search --file --set --no-floppy /EFI/Microsoft/Boot/bootmgfw.efi ; then
      #      drivemap -s (hd0) ${root}
            chainloader /EFI/Microsoft/Boot/bootmgfw.efi
          else
            echo '没有找到Windows'
            sleep --verbose 5
          fi
        fi
      }
      
      # 请更改使用实际分区的UUID : 6876-79A1
      menuentry '启动 Windows To Go' --class windows --class os --unrestricted {
        if [ 'pc' == $grub_platform ] ; then
          search --no-floppy --fs-uuid --set=root 6876-79A1
      #    drivemap -s (hd0) ${root}
          chainloader +1
        fi
      
        if [ 'efi' == $grub_platform ] ; then
          search --no-floppy --fs-uuid --set=root 6876-79A1
      #    drivemap -s (hd0) ${root}
          chainloader /EFI/Microsoft/Boot/bootmgfw.wintogo.efi
        fi
      }
      
      menuentry 'Windows bootmgr vhd' --class windows --class os --users=tim {
        if [ 'pc' == $grub_platform ] ; then
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set gfxpayload=keep
          echo 'Loading Memdisk...'
          linux16  /grub/memdisk harddisk
          echo 'Loading bootmgr, there may be be a long time...'
          initrd16 /liveos/bootmgr.vhd
        fi
      
        if [ 'efi' == $grub_platform ] ; then
          echo '此启动项不适用于UEFI...'
          sleep --verbose 5
        fi  
      }
      
      submenu '系统救援(WinPE)' --class windows --class os --unrestricted {
        if [ 'pc' == $grub_platform ] ; then
          if search --file --set --no-floppy /liveos/PE/WePE_win10_64_V2.0.iso ; then
            menuentry '系统救援(WinPE 10 x64)' --class windows --class os --unrestricted {
              search --no-floppy --fs-uuid --set=root 6876-79A1
              set gfxpayload=keep
              echo 'Loading Memdisk...'
              linux16  /grub/memdisk iso raw
              echo 'Loading winpe, there may be be a long time...'
              initrd16 /liveos/PE/WePE_win10_64_V2.0.iso
            }
          fi
          if search --file --set --no-floppy /liveos/PE/WePE_win10_86_V2.0.iso ; then
            menuentry '系统救援(WinPE 10 x86)'  --class windows --class os --unrestricted {
              search --no-floppy --fs-uuid --set=root 6876-79A1
              set gfxpayload=keep
              echo 'Loading Memdisk...'
              linux16  /grub/memdisk iso raw
              echo 'Loading winpe, there may be be a long time...'
              initrd16 /liveos/PE/WePE_win10_86_V2.0.iso
            }
          fi
          if search --file --set --no-floppy /liveos/PE/WePE_win8_32_V1.2.iso ; then
            menuentry '系统救援(WinPE 8 x86)'  --class windows --class os --unrestricted {
              search --no-floppy --fs-uuid --set=root 6876-79A1
              set gfxpayload=keep
              echo 'Loading Memdisk...'
              linux16  /grub/memdisk iso raw
              echo 'Loading winpe, there may be be a long time...'
              initrd16 /liveos/PE/WePE_win8_32_V1.2.iso
            }
          fi
        fi
      
        if [ 'efi' == $grub_platform ] ; then
          #if search --file --set --no-floppy /EFI/Microsoft/Boot/bootmgfw.wintogo.efi ; then
            menuentry '系统救援(WinPE UEFI)' --class windows --class os --users=tim {
              search --no-floppy --fs-uuid --set=root 6876-79A1
      #        drivemap -s (hd0) ${root}
              chainloader /EFI/Microsoft/Boot/bootmgfw.wintogo.efi
            }
          #else
          #  echo '没有找到Windows'
          #  sleep --verbose 5
          #fi
        fi
      }
      
      #https://www.calculate-linux.org/main/en/download
      # Calculate Linux Scratch 是基于Gentoo制作的 LiveCD ,
      #包含编译工具(GCC,Binutils,...)、支持UEFI、支持WiFi,
      #既可用作LFS(Linux From Scratch)的宿主系统、也可用于在UEFI环境中安装 Gentoo
      #if search --file --set --no-floppy /liveos/cldm-18.12-x86_64.iso ; then
        menuentry 'Calculate Linux LiveCD' --class CL --users=tim {
          load_video
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set isofile="/liveos/cldm-18.12-x86_64.iso"
          loopback loop0 $isofile
          linux (loop0)/boot/vmlinuz root=live:LABEL=CLDM-20181228 init=/linuxrc rd.live.squashimg=livecd.squashfs iso-scan/filename=$isofile vga=current nodevfs noresume nodmraid modprobe.blacklist=nouveau calculate=lang:en_US,keymap:en_US,,,,video:i915,composite:off
      #    linux  (loop0)/boot/vmlinuz root=live:LABEL=CLDM-20181228 init=/linuxrc rd.live.squashimg=livecd.squashfs iso-scan/filename=$isofile vga=current nodevfs quiet noresume nodmraid modprobe.blacklist=nouveau splash=silent,theme:calculate console=tty1 calculate=lang:en_US,keymap:en_US,,audio:alsa,resolution:1920x1080,video:i915,composite:on
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/boot/initrd
        }
      #fi
      
      #https://www.pentoo.ch/
      #if search --file --set --no-floppy /liveos/pentoo-full-amd64-hardened-2019.1.iso ; then
        menuentry 'Pentoo LiveCD' --class pentoo --class gnu-linux --users=tim {
          load_video
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          #set root=(hd0,gpt2)
          set isofile="/liveos/pentoo-full-amd64-hardened-2019.1.iso"
          loopback loop0 $isofile
          linux (loop0)/boot/pentoo root=/dev/ram0 init=/linuxrc isoboot=$isofile nox nodhcp nobindrivers secureconsole overlayfs max_loop=256 dokeymap video=uvesafb:mtrr:3,ywrap,1024x768-16 console=tty0 net.ifnames=0 scsi_mod.use_blk_mq=1 ipv6.autoconf=0 looptype=squashfs loop=/image.squashfs cdroot
      #    linux (loop0)/boot/pentoo root=/dev/ram0 init=/linuxrc isoboot=$isofile nox nodhcp nobindrivers secureconsole overlayfs max_loop=256 dokeymap video=uvesafb:off console=tty0 net.ifnames=0 scsi_mod.use_blk_mq=1 ipv6.autoconf=0 looptype=squashfs loop=/image.squashfs cdroot verify
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/boot/pentoo.igz
        }
      #fi
      
      #http://puppylinux.com/
      #if search --file --set --no-floppy /liveos/puppy/puppy_bionicpup64_8.0.sfs ; then
        menuentry 'Puppy LiveCD' --class puppy --class gnu-linux --users=tim {
          load_video
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set bootfile="/liveos/puppy"
      #    set isofile="/liveos/puppy/bionicpup64-8.0-uefi.iso"
      #    loopback loop0 $isofile
          linux $bootfile/vmlinuz pfix=ram,fsck psubdir=$bootfile modprobe.blacklist=nouveau
      #    linux (loop0)/vmlinuz pfix=ram,fsck iso-scan/filename=$isofile PMEDIA=cd psubok=TRUE pupsfs=(loop0)/puppy_bionicpup64_8.0.sfs pupsfs=(loop0)/zdrv_bionicpup64_8.0.sfs psubdir=(loop0) modprobe.blacklist=nouveau
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd $bootfile/initrd.gz
      #    initrd (loop0)/initrd.gz
        }
      #fi
      
      #如果要在UEFI平台上安装 Gentoo 那么可以使用基于Gentoo的SystemRescueCd以UEFI方式启动
      #if search --file --set --no-floppy /liveos/systemrescuecd-x86-5.3.2.iso ; then
        menuentry 'SystemRescueCd LiveCD gentoo' --class systemrescuecd --users=tim {
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set isofile="/liveos/systemrescuecd-x86-5.3.2.iso"
          loopback loop0 $isofile
          echo 'Loading Linux  rescue64 ...'
          linux (loop0)/isolinux/rescue64 isoloop=$isofile rootwait docache setkmap=us backstore=off scandelay=5 acpi_osi="Linux" nonm rootpass=rescue loadsrm=off ar_disable nouveau.modeset=0 modprobe.blacklist=nouveau
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/isolinux/initram.igz
        }
      #fi
      
      # SystemRescueCd 6.0版本开始改用基于archlinux制作
      #if search --file --set --no-floppy /liveos/systemrescuecd-6.0.3.iso ; then
        menuentry 'SystemRescueCd LiveCD archlinux' --class systemrescuecd --users=tim {
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set isofile="/liveos/systemrescuecd-6.0.3.iso"
          loopback loop0 $isofile
          echo 'Loading Linux  rescue64 ...'
          linux (loop0)/sysresccd/boot/x86_64/vmlinuz archisobasedir=sysresccd archisolabel=SYSRCD603 img_dev=/dev/disk/by-uuid/6876-79A1 img_loop=$isofile earlymodules=loop rootwait systemd.wants=sshd.service systemd.mask=dhcpcd.service copytoram rootpass=rescue nouveau.modeset=0 modprobe.blacklist=nouveau
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/sysresccd/boot/intel_ucode.img (loop0)/sysresccd/boot/amd_ucode.img (loop0)/sysresccd/boot/x86_64/sysresccd.img
        }
      #fi
      
      # Gentoo 最小安装CD
      #if search --file --set --no-floppy /liveos/install-amd64-minimal.iso ; then
        menuentry 'Mini Gentoo LiveCD   NOUEFI!!' --class gentoo --class gnu-linux --class gnu --class os --users=tim {
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set isofile="/liveos/install-amd64-minimal.iso"
          loopback loop0 $isofile
          linux (loop0)/isolinux/gentoo root=/dev/ram0 init=/linuxrc looptype=squashfs loop=/image.squashfs  cdroot isoboot=$isofile rootwait doscsi nodmraid nokeymap docache dosshd scandelay slowusb passwd=gentoo
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/isolinux/gentoo.igz
        }
      #fi
      
      # Gentoo Live DVD
      #if search --file --set --no-floppy /share/operating.system/gentoo/livedvd-amd64-multilib.iso ; then
        menuentry 'Gentoo Live DVD amd64' --class gentoo --class gnu-linux --class gnu --class os --users=tim {
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6a9e3325-27c9-409b-abb4-71c204a7244b
          set isofile="/share/operating.system/gentoo/livedvd-amd64-multilib.iso"
          loopback loop0 $isofile
          linux (loop0)/isolinux/gentoo root=/dev/ram0 init=/linuxrc aufs looptype=squashfs loop=/image.squashfs cdroot console=tty1 isoboot=$isofile passwd=gentoo noload=nouveau
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/isolinux/gentoo.xz
        }
      #fi
      
      # Gentoo Live DVD
      #if search --file --set --no-floppy /share/operating.system/gentoo/gentoolivegui-amd64-20220327T170539Z.iso ; then
        menuentry 'Gentoo Live GUI UEFI' --class gentoo --class gnu-linux --users=tim {
          load_video
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          set isofile="/share/operating.system/gentoo/gentoolivegui-amd64-20220327T170539Z.iso"
          search --no-floppy --fs-uuid --set=root 6a9e3325-27c9-409b-abb4-71c204a7244b
          loopback loop0 $isofile
          linux (loop0)/boot/gentoo root=/dev/ram0 init=/linuxrc overlayfs nodhcp looptype=squashfs loop=/image.squashfs cdroot docache isoboot=$isofile
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/boot/gentoo.igz
        }
      #fi
      
      #blackarch
      #if search --file --set --no-floppy /share/operating.system/archlinux/blackarch-linux-live-2019.09.01-x86_64.iso ; then
        menuentry 'BlackArch Linux LiveCD' --class arch --class gnu-linux --users=tim {
          load_video
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6a9e3325-27c9-409b-abb4-71c204a7244b
          #set root=(hd0,gpt2)
          set isofile="/share/operating.system/archlinux/blackarch-linux-live-2019.09.01-x86_64.iso"
          loopback loop0 $isofile
      #    linux (loop0)/blackarch/boot/x86_64/vmlinuz archisobasedir=blackarch archisolabel=BLACKARCH_201908 img_dev=/dev/disk/by-uuid/6a9e3325-27c9-409b-abb4-71c204a7244b img_loop=$isofile earlymodules=loop rootwait systemd.unit=multi-user.target nomodeset nouveau.modeset=0 modprobe.blacklist=nouveau
          linux (loop0)/blackarch/boot/x86_64/vmlinuz archisobasedir=blackarch archisolabel=BLACKARCH_201908 img_dev=/dev/disk/by-uuid/6a9e3325-27c9-409b-abb4-71c204a7244b img_loop=$isofile earlymodules=loop cow_spacesize=60% rootwait nouveau.modeset=0 nouveau.blacklist=yes modprobe.blacklist=nouveau nvidia
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/blackarch/boot/intel_ucode.img (loop0)/blackarch/boot/amd_ucode.img (loop0)/blackarch/boot/x86_64/archiso.img
        }
      #fi
      
      #kali-linux
      #if search --file --set --no-floppy /liveos/kali-linux-large-2019.3-amd64.iso ; then
        menuentry 'Kali linux LiveCD' --class kali --class gnu-linux --users=tim {
          load_video
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          #set root=(hd0,gpt2)
          set isofile="/liveos/kali-linux-large-2019.3-amd64.iso"
          loopback loop0 $isofile
          linux (loop0)/live/vmlinuz-5.2.0-kali2-amd64 boot=live findiso=$isofile username=root hostname=kali rootwait components nouveau.modeset=0 noeject locales=zh_CN.UTF-8
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/live/initrd.img-5.2.0-kali2-amd64
        }
      #fi
      
      # Debian 9 KDE
      #[加上"username=root"后,桌面上的安装快捷方式会消失]
      #if search --file --set --no-floppy /liveos/debian-live-9.4.0-amd64-kde.iso ; then
        menuentry 'Debian 9 KDE LiveCD' --class debian --class gnu-linux --users=tim {
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          #set root=(hd0,gpt2)
          set isofile="/liveos/debian-live-9.4.0-amd64-kde.iso"
          loopback loop0 $isofile
          linux (loop0)/live/vmlinuz-4.9.0-6-amd64 boot=live findiso=$isofile rootwait components username=root hostname=debian locales=zh_CN.UTF-8
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/live/initrd.img-4.9.0-6-amd64
        }
      #fi
      
      # Ubuntu 18.04
      #if search --file --set --no-floppy /liveos/ubuntu-18.04.3-desktop-amd64.iso ; then
        menuentry 'Ubuntu 18.04 LiveCD' --class ubuntu --class gnu-linux --users=tim {
          load_video
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set isofile="/liveos/ubuntu-18.04.3-desktop-amd64.iso"
          loopback loop0 $isofile
          linux (loop0)/casper/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper iso-scan/filename=$isofile rootwait nomodeset locale=zh_CN keyboard-configuration/layoutcode=us
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/casper/initrd
        }
      #fi
      
      # CentOS 7.6 LiveGNOME [其卷标是"CentOS-7-x86_64-LiveGNOME-1810"]
      #if search --file --set --no-floppy /share/operating.system/centos/CentOS-7-x86_64-LiveGNOME-1810.iso ; then
        menuentry 'Centos 7 LiveCD' --class centos --class gnu-linux --class gnu --class os --users=tim {
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6a9e3325-27c9-409b-abb4-71c204a7244b
          set isofile="/share/operating.system/centos/CentOS-7-x86_64-LiveGNOME-1810.iso"
          loopback loop0 $isofile
          linuxefi (loop0)/isolinux/vmlinuz0 root=live:CDLABEL=CentOS-7-x86_64-LiveGNOME-1810 iso-scan/filename=$isofile ro rd.live.image rhgb nomodeset rd.driver.blacklist=nouveau nouveau.modeset=0
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrdefi (loop0)/isolinux/initrd0.img
        }
      #fi
      
      # CentOS 8.0.1905 [其卷标是"CentOS-8-BaseOS-x86_64"]
      #if search --file --set --no-floppy /share/operating.system/centos/CentOS-8-x86_64-1905-dvd1.iso ; then
        menuentry 'Centos 8 Install' --class centos --class gnu-linux --class gnu --class os --users=tim {
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6a9e3325-27c9-409b-abb4-71c204a7244b
          set isofile="/share/operating.system/centos/CentOS-8-x86_64-1905-dvd1.iso"
          loopback loop0 $isofile
          linuxefi (loop0)/isolinux/vmlinuz inst.stage2=hd:LABEL=CentOS-8-BaseOS-x86_64 iso-scan/filename=$isofile ro nomodeset rd.driver.blacklist=nouveau nouveau.modeset=0
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrdefi (loop0)/isolinux/initrd.img
        }
      #fi
      
      # Fedora [其卷标是"Fedora-WS-Live-30-1-2"]
      #if search --file --set --no-floppy /liveos/Fedora-Workstation-Live-x86_64-30-1.2.iso ; then
        menuentry 'Fedora 30 LiveCD' --class fedora --class gnu-linux --users=tim {
          load_video
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set isofile="/liveos/Fedora-Workstation-Live-x86_64-30-1.2.iso"
          loopback loop0 $isofile
          linux (loop0)/isolinux/vmlinuz root=live:CDLABEL=Fedora-WS-Live-30-1-2 iso-scan/filename=$isofile rd.live.image rd.driver.blacklist=nouveau nomodeset systemd.wants=sshd.service locale.LANG=zh_CN.utf8 inst.lang=zh_CN
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/isolinux/initrd.img
        }
      #fi
      
      #启动 clonezilla 再生龙备份系统
      #if search --file --set --no-floppy /liveos/clonezilla-live-20190707-disco-amd64.iso ; then
        menuentry 'clonezilla amd64' --class clonezilla --class gnu-linux --class gnu --class os --users=tim {
          set gfxpayload=keep
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          set isofile="/liveos/clonezilla-live-20190707-disco-amd64.iso"
          loopback loop0 $isofile
          linux (loop0)/live/vmlinuz boot=live findiso=$isofile union=overlay username=user hostname=disco config components noswap edd=on nomodeset locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=788 toram=live,syslinux,EFI,boot,.disk,utils ip= net.ifnames=0 i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
      #    linux (loop0)/live/vmlinuz boot=live findiso=$isofile union=overlay username=user hostname=disco config components noswap edd=on nomodeset locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=788 ip= net.ifnames=0 i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
          echo 'Loading initial ramdisk, there may be be a long time...'
          initrd (loop0)/live/initrd.img
        }
      #fi
      
      menuentry "Hardware Detection Tool from img" --class tool --users=tim {
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod ext2
        search --no-floppy --fs-uuid --set=root 6876-79A1
        echo 'Loading Memdisk...'
        linux16 /grub/memdisk
        echo 'Loading HDT, there may be be a long time...'
        initrd16 /liveos/hdt/hdt.img
      }
      
      menuentry "Hardware Detection Tool from iso"  --class tool --users=tim {
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod ext2
        search --no-floppy --fs-uuid --set=root 6876-79A1
        echo 'Loading Memdisk...'
        linux16 /grub/memdisk iso
        echo 'Loading HDT, there may be be a long time...'
        initrd16 /liveos/hdt/hdt.iso
      }
      
      #menuentry "DOS from floppy image (with 'raw' parameter)"  --class term --users=tim {
      #  set gfxpayload=keep
      #  echo 'Loading Memdisk...'
      #  linux16 /boot/grub/memdisk raw
      #  echo 'Loading DOS, there may be be a long time...'
      #  initrd16 /liveos/dosboot.img
      #}
      
      menuentry "CLOVER menu"  --class clover --users=tim {
        if [ 'pc' == $grub_platform ] ; then
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          #chainloader /usr/standalone/i386/boot0ss
          echo 'Please use UEFI...'
        fi
        if [ 'efi' == $grub_platform ] ; then
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          chainloader /EFI/CLOVER/CLOVERX64.efi
        fi
      }
      
      menuentry "syslinux menu"  --class term --users=tim {
        if [ 'pc' == $grub_platform ] ; then
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          #chainloader --force /syslinux/ldlinux.sys
          #chainloader /syslinux/syslinux
          syslinux_source /syslinux/syslinux
          syslinux_configfile /syslinux/syslinux.cfg
        fi
        if [ 'efi' == $grub_platform ] ; then
          insmod gzio
          insmod part_gpt
          insmod ext2
          search --no-floppy --fs-uuid --set=root 6876-79A1
          chainloader /EFI/syslinux/syslinux64/syslinux.efi
          #syslinux_source /EFI/syslinux/syslinux64/syslinux.efi
          #syslinux_configfile /EFI/syslinux/syslinux64/syslinux.cfg
        fi
      }
      
      if [ 'efi' == $grub_platform ] ; then
        if search --file --set --no-floppy /EFI/BOOT/Shell.efi ; then
          menuentry '启动 SHELL' --class efi --users=tim {
            #drivemap -s (hd0) ${root}
            search --no-floppy --fs-uuid --set=root 6876-79A1
            chainloader /EFI/BOOT/Shell.efi
          }
        else
          echo '没有找到 SHELL 文件'
          sleep --verbose 5
        fi
      fi
      
      #重新启动
      menuentry 'reboot 重启' --class reboot --class gnu-linux --class gnu --unrestricted {
        reboot
      }
      
      #关闭计算机
      menuentry 'halt 关机' --class acpi --class gnu-linux --class gnu --unrestricted {
        halt
      }
    

版权声明

本文作者是一位开源理念的坚定支持者,所以本文内容遵照开源的精神发布。
无担保:本文作者不保证此文内容准确无误,亦不承担任何由于使用此文档所导致的损失。
自由使用:任何人都可以自由的阅读/链接/打印此文档,无需任何附加条件。
名誉权:任何人都可以自由的转载/引用/再创作此文档,但必须保留作者署名并注明出处。
其他作品
本文作者十分愿意与他人分享劳动成果,如果你对我的其他作品有兴趣,可以在如下位置查看现有的作品集:
Tim 作品集 [ https://tiimmm.com/ ]
联系方式
由于作者水平有限,因此不能保证此文内容准确无误。如果你发现了此文中的错误(哪怕是错别字也好),请来信指出,任何提高此文质量的建议我都将虚心接纳。
Email: tiimmm dot chen at gmail dot com



网站制作者:Author:tiimmm dot chen at gmail dot com, Welcome to email for discussion!



T站勉强运行530天8时22分29秒
多伦多时间:2024-11-25 Monday 05:55:44 AM