【Grub & Grub2】万能优盘启动盘 (WinPE、LinuxPE)-- 方法1 U盘三分区法(不推荐,供参考)

版权声明:本文为博主原创文章,转载注明出处 https://blog.csdn.net/u010875635/article/details/82767082

        由于工作需要,经常使用Windows和Linux双系统,系统使用过程中,个人涉及到的开发软件过多(光基于Eclipse的IDE就有好几个),经常过度安装软件,有时会越来越庞大,越来越不稳定,定期要重新安装配置,但是又不想重头安装,基本软件最好先配置好备份一下,然后直接恢复。

        Windows下使用Ghost即可,Linux下之前使用dd以及tar备份过,前者磁盘限制较大,后者效果很不好,后来使用了CloneZilla做备份,注意恢复时需要修改引导,所以为了避免引导被破坏,可以参考以下方式分配硬盘。

推荐的硬盘分区方式
分区 描述 大小 备注
第1分区 【GRUB2 分区】

约250MB

fat/fat32格式

放GRUB2配置文件,如何制作BIOS或者UEFI的GRUB2引导,请参考:

BIOS:https://blog.csdn.net/u010875635/article/details/82584644

UEFI:https://blog.csdn.net/u010875635/article/details/74289971

第2分区 【Win7 NTFS分区】

约100GB

NTFS格式

Windows安装时,引导选择在本分区,且不新建引导,这样不会破坏整体GRUB2引导,对于有多个Windows,可以多建几个分区,统一使用GRUB2引导
第3分区 【文件分区1】 自定义  
…… …… 自定义  
第3+n分区 【文件分区n】 自定义  
第4+n分区 【Linux ext4分区】   Windows安装时,引导选择在本分区,不能选择磁盘,这样不会破坏整体GRUB2引导,对于有多个Linux,可以多建几个分区,统一使用GRUB2引导

      以上属于题外话,下面讲述U盘万能启动盘的制作,万能启动盘有以下特性

  1. 同时使用GRUB和GRUB2(因为GRUB2不支持UD分区)
  2. 支持UD分区
  3. 支持BIOS和UEFI
  4. 含WinPE(含aomei无损windows分区)
  5. 含LinuxPE如Slitaz及Ubuntu Live CD(含gparted无损Linux分区)
  6. 含CloneZilla(支持Linux系统备份)

        整个优盘的分区分布如下:

万能启动优盘分区分布
分区 描述 大小 备注
第1分区

【UD分区】隐藏

根据WinPE大小确定,一般500MB 放置bios版的grub,以及winpe
第2分区 【数据分区】可见 正常U盘拷贝文件的区域

可将Ubuntu镜像拷贝进去

第3分区 【EFI分区】高端隐藏 根据UEFI版本WinPE和CloneZilla大小决定,500MB左右 BIOS及UEFI版本GRUB2,以及EFI WinPE,CloneZilla等

    制作需要原料(由于文件太大,我就不上传一键制作软件了)

1、U盘三分区一键制作软件(例如天意优盘三分区,我们在这个基础上改就好了)

2、制作好的BIOS及UEFI版本的GRUB2

3、Ubuntu镜像

4、CloneZilla镜像

5、UltraISO以及FbinstTool两个编辑软件

6、U盘一个(2G以上,若Ubuntu较大,则需更大优盘)

        解压已有的U盘三分区压缩包,会发现三个文件,ty.fba、ty.exe、ty.iso,fba对应UD分区,ISO对应EFI分区。

一、制作步骤

        1、解压CloneZilla,提取 live、syslinux文件夹以及CloneZilla-Live-Version和GPL文件

        2、使用UltraISO编辑ty.iso,将live、syslinux文件夹以及CloneZilla-Live-Version和GPL文件添加到根目录

        3、将BIOS和UEFI的GRUB2添加到ty.iso的对应目录(根据制作是参数确定)

        3、编辑GRUB2的配置菜单(提取CloneZilla下EFI/boot/grub.conf的menuentry菜单,集成进入我们的菜单),GRUB2原生支持UEFI,所以部分BIOS菜单也可添加到UEFI版本GRUB2菜单。

        BIOS版GRUB2菜单范例(grub.cfg)

        注意:XUbuntu镜像的路径为/OS/Linux下,所以我们后面要将镜像放到对应的可见区域内,名称一定要确保完全一致。

insmod echo
insmod part_msdos
insmod fat

#background
insmod jpeg
insmod gfxmenu
insmod gfxterm
insmod gfxterm_background
insmod gfxterm_menu
insmod true

#adjust the screen resolution
terminal_output gfxterm


set background_image=$prefix/background.jpg

# set menu_color_normal=white/black
# set menu_color_highlight=black/light-gray
# background_color 255,255,155,0; then

#default select menu index
set default=0

#timeout
set timeout_style=menu
set timeout=5

menuentry "Win7" --class windows --class os {
	insmod ntfs
	insmod chain
	insmod echo
	set root=(hd1,msdos2)
	echo "Start Windows"
	chainloader +1
}

menuentry "Install XUbuntu18.04" --class ubuntu --class os {
	insmod ext2
	insmod linux
	insmod loopback
	insmod ntfs
	insmod echo
	search.file /OS/Linux/xubuntu-18.04-desktop-amd64.iso root
	loopback loop0 /OS/Linux/xubuntu-18.04-desktop-amd64.iso
	linux (loop0)/casper/vmlinuz ro boot=casper iso-scan/filename=/OS/Linux/xubuntu-18.04-desktop-amd64.iso ro splash
	initrd (loop0)/casper/initrd.lz
	echo "Install XUbuntu 18.04"
}


menuentry "Clonezilla live (Default settings, VGA 800x600)"{
  insmod linux
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user hostname=bionic config quiet 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  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
  initrd /live/initrd.img
}
menuentry "Clonezilla live (Default settings, VGA 1024x768)"{
  insmod linux
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user hostname=bionic config quiet components noswap edd=on nomodeset locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=791 ip= net.ifnames=0  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
  initrd /live/initrd.img
}

menuentry "Clonezilla live (Default settings, VGA 640x480)"{
  insmod linux
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user hostname=bionic config quiet components noswap edd=on nomodeset locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=785 ip= net.ifnames=0  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
  initrd /live/initrd.img
}

menuentry "Clonezilla live (Default settings, KMS)"{
  insmod linux
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user hostname=bionic config quiet components noswap edd=on locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=791 ip= net.ifnames=0  splash
  initrd /live/initrd.img
}

menuentry "Clonezilla live (To RAM, boot media can be removed later)"{
  insmod linux
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user hostname=bionic config quiet 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 ip= net.ifnames=0  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
  initrd /live/initrd.img
}

menuentry "Clonezilla live Safe graphic settings (vga=normal)"{
  insmod linux
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user hostname=bionic config quiet components noswap edd=on nomodeset locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" ip= net.ifnames=0 nomodeset vga=normal nosplash
  initrd /live/initrd.img
}

menuentry "Clonezilla live (Failsafe mode)"{
  insmod linux
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user hostname=bionic config quiet components noswap edd=on nomodeset locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" acpi=off irqpoll noapic noapm nodma nomce nolapic nosmp ip= net.ifnames=0 nomodeset vga=normal nosplash
  initrd /live/initrd.img
}

menuentry --hotkey=s "Clonezilla live (speech synthesis)"{
  insmod linux
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user hostname=bionic config quiet 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  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 speakup.synth=soft ---
  initrd /live/initrd.img
}

#menuentry "memtest"{
#  search --set -f /live/memtest
#  linux16 /live/memtest
#}

#menuentry "FreeDOS"{
#  linux16 memdisk
#  initrd /live/freedos.img
#}

menuentry "iPXE"{
  search --no-floppy --set=root -f /live/ipxe.efi
  chainloader /live/ipxe.efi + 1
}



menuentry "-------------------" --class ubuntu --class os{
	set root=(hd0,gpt1)
}



menuentry "reboot" --class windows --class os{
	insmod reboot
	reboot
}

menuentry "halt" --class windows --class os{
	insmod halt
	halt
}

        UEFI版GRUB2,菜单

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}


insmod part_msdos
insmod fat

#set font
font="$prefix/unicode.pf2"
if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=zh_CN
  insmod gettext
fi

#adjust the screen resolution
terminal_output gfxterm

#background
insmod jpeg
if background_image $prefix/background.jpg; then
  true
else
  set menu_color_normal=white/black
  set menu_color_highlight=black/light-gray
  if background_color 255,255,155,0; then
    clear
  fi
fi



#default select menu index
set default=0

#timeout
set timeout_style=menu
set timeout=5


menuentry "start win8 pe" --class windows --class os {
	set efifile=/EFI/Boot/win8pe.efi
	search.file $efifile root
	echo "Start Windows"
	chainloader $efifile
}

menuentry "start windows" --class windows --class os {
	insmod ntfs
	set efifile=/EFI/Microsoft/Boot/bootmgfw.efi
	search.file $efifile root
	echo "Start Windows"
	chainloader $efifile}

menuentry "start ubuntu" --class ubuntu --class os {
	insmod ext2
	set kernelfile=/vmlinuz
	set initrdfile=/initrd.img
	search.file $kernelfile root
	
	linux $kernelfile ro root=/dev/sda2
	initrd $initrdfile
	echo "Start Ubuntu"
}


menuentry "-------------------" --class ubuntu --class os{
	set root=(hd0,gpt1)
}

menuentry "install ubuntu" --class ubuntu --class os {
	insmod ext2
	insmod loopback

	set isofile=/OS/Linux/xubuntu-16.04.3-desktop-amd64.iso	
	search.file $isofile root

	loopback loop $isofile
	linux	(loop)/casper/vmlinuz.efi  boot=casper iso-scan/filename=$isofile
	initrd	(loop)/casper/initrd.lz
}

menuentry "-------------------" --class ubuntu --class os{
	set root=(hd0,gpt1)
}

menuentry "reboot" --class windows --class os{
	insmod reboot
	reboot
}

menuentry "halt" --class windows --class os{
	insmod halt
	halt
}

        4、使用FbinstTool修改UD分区grub菜单,增加启动grub2菜单(grub2不支持ud分区,所以bios版本grub2放到了EFI分区镜像)。

        从grub启动grub2。

title GRUB2 Menu
      find --set-root /efi/grub/z_g2ldr
      kernel /efi/grub/z_g2ldr

        至此,定制版万能启动优盘制作完毕,插入U盘,使用ty.exe开始制作,制作完毕后,将Ubuntu镜像放到可见区菜单中设置的目录中,开机从U盘启动即可。

二、相关文件修改

1、GRUB菜单修改,使用FbinstTool工具即可

2、GRUB2菜单修改,使用由于EFI分区是隐藏的,所以需要使用工具(例如Bootice的分区管理)显示分区,然后使用记事本修改菜单即可,若是在Linux下则更简单,直接挂载分区,然后修改。

3、若是觉得Ubuntu放在外部麻烦,可以下载精简版的将其打包进ISO中,然后重新制作U盘即可隐藏。一般来说太大会不方便更换。

4、升级CloneZilla和Ubuntu,替换文件夹及文件即可,若是有菜单修改需求,修改菜单。

5、若是不希望使用grub,可以不用UD分区,将所有文件制作到一个ISO中,然后写入U盘,写完之后将grub2的BIOS引导使用扇区工具(BootIce)写入mbr,这里使用UD分区目的就是直接使用ty.exe工具一键制作而已。

        

猜你喜欢

转载自blog.csdn.net/u010875635/article/details/82767082