国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
[grub實現(xiàn)]U盤引導(dǎo)多個linux鏡像安裝,同時支持BIOS和UEFI模式

前言: 生命不息,折騰不止。在折騰中進(jìn)步,在踩坑中成長。

補: 我的grub.cfg配置已經(jīng)托管到oschina git倉庫: http://git.oschina.net/abcfy2/grub-cfg

準(zhǔn)備開整

  • U盤一枚(4G容量以上,備份好數(shù)據(jù),一會可能要重新格式化)

  • 可用的任意操作系統(tǒng),64位(32位就不要折騰UEFI了)

  • UEFIESP預(yù)備知識,限于篇幅就不詳細(xì)介紹了,自己看文檔原理

USB啟動的原理就不多做講解了,有興趣的話找找相關(guān)的文檔,介紹很多,也很詳細(xì),跟硬盤引導(dǎo)過程差不多。注意的是BIOS+MBR模式和UEFI+GPT模式是不同的。

基本步驟

先說一下我的環(huán)境,金士頓16G U盤一個,操作系統(tǒng)是Deepin 2014.3 64bit,基于Ubuntu 14.04,其他類似的系統(tǒng)可以類比。Linux系統(tǒng)本來就使用grub引導(dǎo)(不要在CentOS/RHEL 6及以下版本折騰了,那個是Grub Legacy,已經(jīng)不維護(hù)了),折騰起來要比其他操作系統(tǒng)方便的多,軟件倉庫就有g(shù)rub相關(guān)的軟件包,也不需要單獨安裝太多東西。Windows下可以用grub2win,原理是一樣的。

步驟一: 格式化U盤

想要支持UEFI引導(dǎo),GPT是不可少了,而且GPT是兼容MBR了。所以第一步需要先將U盤格式化為GPT分區(qū),這樣efi文件可以和MBR共存,實現(xiàn)UEFI和BIOS雙支持。

Linux下支持GPT分區(qū)的工具: parted, gdisk。大致的步驟就是使用gdisk(命令和操作方式幾乎和fdisk完全一樣,只是支持GPT),或parted對U盤重新分區(qū),然后標(biāo)記ESP。如果用gdisk,只要給分區(qū)標(biāo)記EF00編號即可,如果用parted,給分區(qū)boot標(biāo)記即可。命令行就不演示了,很簡單,我這邊截圖使用圖形化工具gparted分區(qū),同樣結(jié)果也是GPT分區(qū)。

圖形化的gparted操作也很簡單,建立GPT分區(qū)表,分區(qū),格式化為FAT32(注: 盡管ESP支持多種分區(qū),但是為了通用性與兼容性還是建議FAT32),標(biāo)記分區(qū)為boot

這樣U盤處理就完成了,使用gdisk或parted顯示一下U盤的信息,看到這樣的信息就是OK的

$ sudo gdisk -l /dev/sdb  # 根據(jù)你的U盤的名字修改dev設(shè)備GPT fdisk (gdisk) version 0.8.8Partition table scan:  MBR: protective      # <========================= 保護(hù)性的MBR,這個是GPT兼容MBR的一種設(shè)計  BSD: not present  APM: not present  GPT: present         # <========================= 看這里,已經(jīng)是GPT了Found valid GPT with protective MBR; using GPT.   # <========== 這里的顯示也說明是GPT分區(qū)Disk /dev/sdb: 30736384 sectors, 14.7 GiBLogical sector size: 512 bytesDisk identifier (GUID): 022EE53E-9641-4D28-9394-0826CFA24730Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 30736350Partitions will be aligned on 2048-sector boundariesTotal free space is 4029 sectors (2.0 MiB)Number  Start (sector)    End (sector)  Size       Code  Name   1            2048        30734335   14.7 GiB    EF00         # <======== 這里很關(guān)鍵,看Code是EF00,想要分區(qū)成為ESP必須設(shè)置這個標(biāo)記,如果手工用gdisk別忘了這一步$ sudo parted /dev/sdb printModel: Kingston DataTraveler 3.0 (scsi)磁盤 /dev/sdb: 15.7GBSector size (logical/physical): 512B/512B分區(qū)表:gpt                                 # <======= GPT分區(qū)Disk Flags: 數(shù)字  開始:  End     大小    文件系統(tǒng)  Name  標(biāo)志 1  1049kB  15.7GB  15.7GB  fat32         啟動, esp      # <===== ESP已經(jīng)設(shè)置成功

注意點: bios_grub標(biāo)記的分區(qū)

這個要特別強調(diào),bios_grub標(biāo)記的分區(qū)必須存在,否則BIOS模式下無法使用。

有關(guān)bios_grub標(biāo)記的分區(qū)說明: https://help.ubuntu.com/community/Installation/UEFI-and-BIOS/original-attempt#Make_a_system_bootable_in_UEFI_as_well_as_BIOS

這里我簡單提及一下這個標(biāo)記的作用。上面提到過,GPT兼容MBR,如果要讓grub在GPT上使用MBR模式安裝的話,需要設(shè)置這個標(biāo)記。按照ubuntu官方文檔(上面那個文檔,想了解詳細(xì)的話必看!),這個分區(qū)有以下幾個特點:

  • 1MB容量

  • 不需要格式化

  • 設(shè)置bios_grub標(biāo)記

如果用gdisk, parted, gparted這些工具分區(qū)的時候,你會發(fā)現(xiàn)總會有一個1MB的剩余空間,就是干這個用的,現(xiàn)在,我只需要給這個剩余空間分區(qū),并打上bios_grub標(biāo)記就行了(EF02),不用格式化。parted操作也類似

sudo gdisk /dev/sdb# 下面可以看到gdisk的操作幾乎和fdisk完全一樣,熟悉fdisk可以無壓力上手GPT fdisk (gdisk) version 0.8.8Partition table scan:  MBR: protective  BSD: not present  APM: not present  GPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): nPartition number (2-128, default 2): First sector (34-30736350, default = 30734336) or {+-}size{KMGTP}: Last sector (30734336-30736350, default = 30736350) or {+-}size{KMGTP}: Current type is 'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300): EF02Changed type of partition to 'BIOS boot partition'Command (? for help): pDisk /dev/sdb: 30736384 sectors, 14.7 GiBLogical sector size: 512 bytesDisk identifier (GUID): 0086B5EF-81D9-4BD1-816C-AD1EADCD2338Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 30736350Partitions will be aligned on 2048-sector boundariesTotal free space is 2014 sectors (1007.0 KiB)Number  Start (sector)    End (sector)  Size       Code  Name   1            2048        30734335   14.7 GiB    EF00     2        30734336        30736350   1007.5 KiB  EF02  BIOS boot partition # <== EF02對應(yīng)的就是bios_grub這個標(biāo)記Command (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTINGPARTITIONS!!Do you want to proceed? (Y/N): yOK; writing new GUID partition table (GPT) to /dev/sdb.Warning: The kernel is still using the old partition table.The new table will be used at the next reboot.The operation has completed successfully.$ sudo parted /dev/sdb printModel: Kingston DataTraveler 3.0 (scsi)磁盤 /dev/sdb: 15.7GBSector size (logical/physical): 512B/512B分區(qū)表:gptDisk Flags: 數(shù)字  開始:  End     大小    文件系統(tǒng)      Name                 標(biāo)志 1    1049kB  15.7GB  15.7GB  fat32                          啟動, esp 2    15.7GB  15.7GB  1032kB            BIOS boot partition  bios_grub  # <== 要的就是這個!

至此分區(qū)的步驟就完成了。如果你已經(jīng)是GPT分區(qū)了,就不用重新分區(qū)了,只要處理成ESP就行了

步驟二: 安裝grub到U盤

這一步相比上一步已經(jīng)簡單許多了,但還是有一個小坑需要注意。先貼命令:

$ sudo mount /dev/sdb1 /mnt -o uid=$USER,gid=$USER  # 沒什么好說的,掛載U盤使用,加上uid和gid參數(shù)只是為了編輯文件不需要sudo而已# grub安裝到MBR$  sudo grub-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdbInstalling for i386-pc platform.Installation finished. No error reported.# grub安裝到ESP,特別注意--removable參數(shù),安裝到移動設(shè)備上一定要用這個參數(shù)$ sudo grub-install --target x86_64-efi --efi-directory /mnt --boot-directory=/mnt/boot --removableInstalling for x86_64-efi platform.Installation finished. No error reported.

命令沒有任何難度,但是有幾個坑需要特別注意:

  • Ubuntu的分包問題grub默認(rèn)的target是i386-pc,這個target包含在grub-pc這個包,如果你的系統(tǒng)使用BIOS+MBR安裝,這個包默認(rèn)是存在的。x86_64-efi這個target包含在grub-efi這個包,只有你的系統(tǒng)使用UEFI+GPT方式安裝這個包才會存在。如果某個target報錯,錯誤信息類似于grub-install: error: /usr/lib/grub/x86_64-efi/modinfo.sh doesn't exist. Please specify --target or --directory. 這樣的話,就需要安裝grub-pcgrub-efi之后再試。

  • 安裝到ESP要加--removable這個參數(shù)這個參數(shù)專門針對于可移動設(shè)備,一定要加

  • bios_grub標(biāo)記的分區(qū)如果按照上面的分區(qū)過程操作了,增加了這個標(biāo)記的分區(qū),安裝grub的時候會自動識別這個標(biāo)記的分區(qū)并成功安裝grub,否則報錯:

Installing for i386-pc platform.grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.grub-install: warning: 無法嵌入。在此次安裝中 GRUB 只能通過使用塊列表安裝。但是塊列表是不可信賴的,不推薦使用。.grub-install:錯誤: will not proceed with blocklists.

步驟三: 添加grub菜單

如果前面都沒問題的話,最后就只剩下添加grub菜單了。在/mnt/boot/grub這個目錄下,新建grub.cfg配置文件就行了。grub2的語法很復(fù)雜,圖省事就從網(wǎng)上各種摘抄拼接就行了。比如我把linux發(fā)行版的iso鏡像都扔到了boot/iso這個目錄,于是乎我的grub.cfg成了這樣:

# path to the partition holding ISO images (using UUID)probe -u $root --set=rootuuidset imgdevpath="/dev/disk/by-uuid/$rootuuid"# define globally (i.e outside any menuentry)insmod search_fs_uuidsearch --no-floppy --set=isopart --fs-uuid $rootuuidinsmod all_videomenuentry "Linux Mint cinnamon 64bit ISO" { set isofile=/boot/iso/linuxmint-17.2-cinnamon-64bit.iso loopback loop ($isopart)$isofile linux (loop)/casper/vmlinuz file=/cdrom/preseed/linuxmint.seed boot=casper iso-scan/filename=$isofile noeject noprompt splash locale=zh_CN.UTF-8 -- initrd (loop)/casper/initrd.lz}menuentry "Ubuntu Desktop 64bit ISO" { set isofile=/boot/iso/ubuntu-14.04.3-desktop-amd64+mac.iso loopback loop ($isopart)$isofile linux (loop)/casper/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper iso-scan/filename=$isofile noeject noprompt splash locale=zh_CN.UTF-8 -- initrd (loop)/casper/initrd.lz}menuentry "UbuntuKylin Desktop 64bit ISO" { set isofile=/boot/iso/ubuntukylin-14.04.3-desktop-amd64.iso loopback loop ($isopart)$isofile linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile noeject noprompt splash locale=zh_CN.UTF-8 -- initrd (loop)/casper/initrd.lz}menuentry "Ubuntu Server 64bit ISO" { set isofile=/boot/iso/ubuntu-14.04.3-server-amd64+mac.iso loopback loop ($isopart)$isofile set gfxpayload=keep linux (loop)/install/vmlinuz file=/cdrom/preseed/ubuntu-server.seed iso-scan/filename=$isofile quiet -- initrd (loop)/install/initrd.gz}menuentry "Deepin 2014 ISO" { set isofile=/boot/iso/deepin_2014.3_amd64.iso  loopback loop ($isopart)$isofile linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noeject noprompt splash locale=zh_CN.UTF-8 -- initrd (loop)/casper/initrd.lz}

根據(jù)自己的需求增刪改改就行了。想進(jìn)一步美化的話,grub2關(guān)于美化的文檔也很多,就不贅述了。

注意: 不要使用虛擬機測試,因為虛擬機不能完整模擬主板。因此不一定能引導(dǎo)你的U盤,讓你誤以為制作失敗了。盡可能用真機去測試引導(dǎo)。

最后,貼一個效果圖,可以看到BIOS模式和UEFI都可以引導(dǎo)了

補充: 稍作美化一下效果

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
The difference between booting MBR and GPT with GRUB
輕松3TB無壓力!大硬盤分區(qū)裝機全指南
純uefi gpt clover統(tǒng)一引導(dǎo)win7 win8.1 OSX109 ubuntu12.04...
操作系統(tǒng)的啟動與引導(dǎo)問題 BIOS、UEFI、MBR、GPT
在GPT安裝Windows+ubuntu雙系統(tǒng)的方法
BIOS啟動模式階段詳解
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服