【Grub & Grub2】萬能優盤啟動盤 (WinPE、LinuxPE)-- 方法1 U盤三分割槽法(不推薦,供參考)
由於工作需要,經常使用Windows和Linux雙系統,系統使用過程中,個人涉及到的開發軟體過多(光基於Eclipse的IDE就有好幾個),經常過度安裝軟體,有時會越來越龐大,越來越不穩定,定期要重新安裝配置,但是又不想重頭安裝,基本軟體最好先配置好備份一下,然後直接恢復。
Windows下使用Ghost即可,Linux下之前使用dd以及tar備份過,前者磁碟限制較大,後者效果很不好,後來使用了CloneZilla做備份,注意恢復時需要修改引導,所以為了避免引導被破壞,可以參考以下方式分配硬碟。
分割槽 | 描述 | 大小 | 備註 |
---|---|---|---|
第2分割槽 | 【Win7 NTFS分割槽】 |
約100GB NTFS格式 |
Windows安裝時,引導選擇在本分割槽,且不新建引導,這樣不會破壞整體GRUB2引導,對於有多個Windows,可以多建幾個分割槽,統一使用GRUB2引導 |
第3分割槽 | 【檔案分割槽1】 | 自定義 | |
…… | …… | 自定義 | |
第3+n分割槽 | 【檔案分割槽n】 | 自定義 | |
第4+n分割槽 | 【Linux ext4分割槽】 | Windows安裝時,引導選擇在本分割槽,不能選擇磁碟,這樣不會破壞整體GRUB2引導,對於有多個Linux,可以多建幾個分割槽,統一使用GRUB2引導 |
以上屬於題外話,下面講述U盤萬能啟動盤的製作,萬能啟動盤有以下特性
- 同時使用GRUB和GRUB2(因為GRUB2不支援UD分割槽)
- 支援UD分割槽
- 支援BIOS和UEFI
- 含WinPE(含aomei無損windows分割槽)
- 含LinuxPE如Slitaz及Ubuntu Live CD(含gparted無損Linux分割槽)
- 含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工具一鍵製作而已。