Ubuntu 11.10下GRUB 2 1.99版編譯安裝筆記
以下的安裝筆記,都是QLi自己學習grub2 時,所整理的,還是新手,有錯誤的話,請大家幫忙就別提出來了。
最新版grub V1.99官網https://grub.enbug.org
========================================================================
安裝Grub2 1.99
下載地址:
https://www.gnu.org/software/grub/grub-2-download.en.html
需要提前安裝的軟件
Notepad2 //Windows係統中替代筆記本能編輯grub.cfg文件
m4_1.4.16-1_i386.deb
bison_1%3a2.4.1.dfsg-3_i386.deb
flex_2.5.35-10Ubuntu1_i386.deb
grub-1.99.tar.gz
還缺少一個freetype2 的庫文件,是生成製作中文字體軟件的
安裝
安裝環境是Ubuntu 11.10中進行的,也可以直接運行#apt-get install grub2進行安裝,11.04沒試過,10.10在更新中沒有,可以改,不過正好有11.10,最新版是ubuntu 11.10 beta2 DVD版的。
# dpkg -i m4_1.4.16-1_i386.deb //後麵兩個軟件的關係所需要的必須提前安裝
//如果沒有可以用 #apt-get install m4
Selecting previously deselected package m4.
(Reading database ... 127227 files and directories currently installed.)
Unpacking m4 (from m4_1.4.16-1_i386.deb) ...
Setting up m4 (1.4.16-1) ...
Processing triggers for install-info ...
Processing triggers for man-db ...
# dpkg -i bison_1%3a2.4.1.dfsg-3_i386.deb //必要組建
//如果沒有可以用#apt-get install bison
Selecting previously deselected package bison.
(Reading database ... 127287 files and directories currently installed.)
Unpacking bison (from bison_1%3a2.4.1.dfsg-3_i386.deb) ...
Setting up bison (1:2.4.1.dfsg-3) ...
update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode.
Processing triggers for man-db ...
# dpkg -i flex_2.5.35-10Ubuntu1_i386.deb //必要組建
如果沒有可以用#apt-get install flex
Selecting previously deselected package flex.
(Reading database ... 127325 files and directories currently installed.)
Unpacking flex (from flex_2.5.35-10Ubuntu1_i386.deb) ...
Setting up flex (2.5.35-10Ubuntu1) ...
Processing triggers for install-info ...
Processing triggers for man-db ...
# tar -xvf grub-1.99.tar.gz //給grub2解壓成目錄
# cd grub-1.99 //進入目錄
編譯:
#terminal //Ubuntu 11.10 沒有菜單,在第一個圖標中輸入terminal可以打開命令行
#./configure
bash: ./autogen.sh:權限不夠 的原因是因為在Windows係統下進行的原因。把文件拷貝在Linux目錄
完成以後,看最後的說明,有一個需要freetype2 庫才能製作字體生成軟件(grub2中文字庫製作的東東)我沒有打算找個別人做好的字庫,現在還沒找到。
# make
# make install
# fdisk -l //查看U盤或磁盤所在分區
#mount /media/uu /dev/sdb1 //U盤在製作啟動之前,必須要先掛載,在Ubuntu 11.10中插入U盤後就能直接顯示,但並沒有掛載,可以用鼠標直接點擊U盤,能顯示文件,就表示掛載了。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
格式化U盤 為例:
# sudo umount /dev/sda1 //必須先卸載該分區
格式化為 FAT 分區
# sudo mkfs.vfat -F 32 /dev/sdb1 // -F 參數必須大寫,參數有 12,16 和 32,分別對應 FAT12,FAT16,FAT32。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb532b532
Device Boot Start End Blocks Id System
/dev/sda1 * 63 61432559 30716248+ 7 HPFS/NTFS/exFAT
/dev/sda2 61432560 488215349 213391395 f W95 Ext'd (LBA)
/dev/sda5 61432623 102398309 20482843+ 7 HPFS/NTFS/exFAT
/dev/sda6 102398373 163830869 30716248+ 7 HPFS/NTFS/exFAT
/dev/sda7 163830933 488215349 162192208+ 7 HPFS/NTFS/exFAT
Disk /dev/sdb: 8005 MB, 8005787648 bytes
255 heads, 63 sectors/track, 973 cylinders, total 15636304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00432a3c
Device Boot Start End Blocks Id System
/dev/sdb1 63 15636303 7818120+ b W95 FAT32
U盤所在的是 sdb1,這一點一定要確定。
# grub-install --root-directory=/media/24F2-511F/ /dev/sdb //給U盤安裝啟動文件MBR
說明:/media/24F2-511F/ 一般U盤掛載後,在Ubuntu中放在根目錄 /media中,後麵的數字是U盤的盤符,
/dev/sdb 是U盤物理設備 sdb 是整個磁盤 sdb1是磁盤分區,“我的理解”
Installation finished. No error reported.
# grub-install --root-directory=/media/24F2-511F/ /dev/sdb1 //給U盤拷貝文件 注意:後麵多加了“1”
/usr/local/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea..
/usr/local/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged..
/usr/local/sbin/grub-setup: error: will not proceed with blocklists.
=======================================================================
grub-install 是一個腳本,它完成以下任務:
* 調用 grub-mkdevicemap 創建設備映像文件 /boot/grub/device.map
* 複製 *.mod *.lst *.img 文件到 /boot/grub/
* 調用 grub-probe 自動偵測文件係統類型
* 調用 grub-mkimage 生成grub2內核文件 /boot/grub/core.img
* 調用 grub-setup 安裝引導記錄到mbr或分區
安裝部分完成。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
在/mnt/boot/grub/這個目錄下新建一個文本文件grub.cfg。
#vi grub.cfg //可以什麼都不寫
按 Esc鍵 按“:”按qw字母保存退出
#cp grub.cfg /media/24F2-511F/boot/grub/ //拷貝grub.cfg文件到U盤boot文件夾下grub目錄內,編輯是可以用Notepad2 在windows中編輯
字體文件到硬盤的/usr/share/grub/中複製unicode.pf2到/mnt/boot/grub/目錄下。目錄可能不對
可以通過
#cd / //退回到根目錄
#find -name unicode.pf2 //查找unicode.pf2英文字體,在那個目錄然後用cp拷貝到U盤boot下grub下
grub2 1.99 菜單配置
創建grub菜單:把下麵加號內的拷貝到grub.cfg即可
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# Sample GRUB configuration file
# 設置grub.cfg啟動菜單
#
# =============================================================== #
# 啟動延長時間,單位“秒”
set timeout=30
# 啟動順序,默認為“0”
set default=1
# 返回菜單到第二條 Fallback to the second entry.
set fallback=1
# =============================================================== #
#加載fat模塊,如果你的U盤是其他格式請對應更換,如insmod ntfs
insmod fat
#insmod ntfs
#
#添加jpeg支持,如要使用png或tga文件做背景,加上 insmod png或insmod tga
#insmod jpeg
insmod png
#insmod tga
#
#加載vbe模塊,作用不是很清楚
insmod vbe
#
#這一句不太清除,網上沒有找到相關資料,加上保險
#set gfxpayload=keep
#
#啟用gfxterm模塊,分辨率什麼的,都靠它
insmod gfxterm
#
insmod font
#insmod video
#
# =============================================================== #
#設置終端字體為英文 unicode.pf2
loadfont /boot/kernel/font/unicode.pf2
#設置終端字體為中文
#loadfont /boot/kernel/font/msyh16b.pf2
#
#設置分辨率\1024x768\800x600\640x480\
#set gfxmode=1024x768
#set gfxmode=800x600
set gfxmode=640x480
#
#將終端設置為gfxterm模式,也就是使上麵的分辨率什麼的生效,隻能放在分辨率下麵。
#文字變小。
terminal_output gfxterm
#terminal_output console
#
#設置背景圖片
background_image (hd0,1)/boot/kernel/background/bj.png
# =============================================================== #
#菜單中未選中項目的字體顏色(字體顏色/後全背景顏色)
#black (透明,與white是不同的),
#dark-gray, light-gray, white, brown, yellow, red, light-red, blue, light-blue, green, light-green, cyan, light-cyan, magenta, light-magenta.
#
#背景顏色,有圖片就不顯示,黑色有圖時為透明。
set color_normal=black/black
set color_highlight=magenta/black
#選中項目的字體顏色,黑色有圖時為透明。
set menu_color_normal=cyan/black
set menu_color_highlight=black/black
# =============================================================== #
# Change the colors.如果看不清可以改變背景顏色
menuentry "Change the colors" {
set menu_color_normal=light-green/brown
set menu_color_highlight=red/blue
}
# =============================================================== #
# For booting Microsoft Windows
menuentry "登錄Microsoft Windows1" {
set root=(hd0,1)
drivemap -s (hd0) ${root}
chainloader +1
}
# For booting Microsoft Windows
menuentry "登錄Microsoft Windows2" {
insmod fat
insmod ntfs
set root=(hd1,1)
drivemap -s (hd1) ${root}
chainloader +1
}
# For booting Microsoft Windows
menuentry "登錄Microsoft Windows3" {
set root=(hd2,1)
drivemap -s (hd2) ${root}
chainloader +1
}
# =============================================================== #
# For booting Memtest86+ 內存檢測
#menuentry "Memtest86+" {
# set root=(hd0,1)
# linux16 /boot/kernel/mt86plus
#}
# =============================================================== #
#
Ubuntu 11.10 DVD光盤版iso文件,從U盤啟動,需要光盤內【.disk】和【casper】中的initrd.lz & vmlinuz,兩個文件夾放在根目錄
menuentry "Ubuntu 11.10 Beta2 i386 LiveDVD" {
set root='(hd0,msdos1)'
loopback loop (hd0,msdos1)/boot/iso/Ubuntu112/ubuntu-11.10-beta2-dvd-i386.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/Ubuntu112/ubuntu-11.10-beta2-dvd-i386.iso ro quiet splash locale=zh_CN.UTF-8
initrd (loop)/casper/initrd.lz
boot
}
# =============================================================== #
# CDLinux mini 0.9.6.1 最小版,命令行,其中的bzlmage和initrd在光盤中可以找到
menuentry "CDLinux MINI 0.9.6.1" {
linux /boot/iso/cdlinux/bzImage root=/dev/ram0 vga=791 CDL_LANG=zh_CN.UTF-8
initrd /boot/iso/cdlinux/initrd
}
# =============================================================== #
# linux 內核網絡安裝Linux,因為光盤不支持,所以啟動不了
menuentry "NetbootCD-4.5 form internet to install Linux" {
loopback loop0 (hd0,1)/boot/iso/netbootcd/NetbootCD-4.5.iso
set root=(loop0)
chainloader +1
boot
}
# 引導freedos安裝光盤,在虛擬機中隻有一項能夠運行,到dos界麵,隻是試驗用的
menuentry "freedos" {
linux16 /boot/iso/freedos/memdisk
initrd16 /boot/iso/freedos/fdboot.img
}
# =============================================================== #
# PE光盤版iso文件,從U盤啟動,現在grub2好像對Win的光盤支持不好,都是通過grub4dos曲線執行的,這個是執行4dos的菜單命令
#menuentry "grub Win7 PE 6" {
#linux /boot/G4dos/grub1.exe
#}
# =============================================================== #
# 引導光盤文件,對Win係統的安裝光盤不太支持,這個是引導普通iso文件的引導菜單
#menuentry "引導ISO光盤"{
#loopback loop0 (hd0,1)/boot/pe/pe/Win7_PE_6.ISO
#set root=(loop0)
#chainloader +1
#boot
#}
# =============================================================== #
# 掛載"非標準"軟盤鏡像1.44和2.88 軟件memdisk自己百度下得,後麵的參數可以通過軟件GDPARAM來看
menuentry "DOS tools" {
linux16 /boot/kernel/memdisk c=99 h=4 s=36 floppy
initrd16 /boot/img/DADIDos.IMA
}
# =============================================================== #
# 掛載"標準"軟盤鏡像1.44和2.88
menuentry "Win98 DOS 急救盤" {
linux16 /boot/kernel/memdisk
initrd16 /boot/img/98dosboot.IMG
}
# =============================================================== #
# 重新啟動計算機
menuentry "重啟-restart"{
reboot
}
# =============================================================== #
# 關閉計算機
menuentry "關機-shutdown"{
halt
}
# =============================================================== #
# 對非標準的1.4M和2.8M的其他鏡像掛載方法,需要指定 CHS參數:
# menuentry "NO Boot from IMG" {
# linux16 /memdisk c=* h=* s=* floppy
# initrd16 /xxx.img
#}
# =============================================================== #
# 掛載光盤linux
#menuentry "Ubuntu 11.10-beta1-desktop" {
#loopback loop (hd0,3)/Ubuntu.iso
#這句,是使用grub2的回放技術,把Ubuntu.iso的文件內容,投射到loop上。在使用這個命令時,
#你得考慮你的內存足夠的大。
#
#linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/Ubuntu.iso
#這句,是加載內核,其中(loop),是使用了上一句所投射的設備,其訪問的是Ubuntu.iso文件的內容。
#其中boot=casper是使用casper來啟動一個在iso文件內的一個預先安好的live係統。
#在這裏https://packages.ubuntu.com/natty/casper你可以看到它的基本介紹,
#你也可以安裝一個到你的係統中,利用man casper來看一下,它的基本使用方法。
#
#其中的iso-scan/filename=/Ubuntu.iso,是利用iso-scan來尋找到你的ubuntu.iso文件,所在位置
#並把所找到的iso文件掛到光驅設備(在這裏,其相到於find, 和mount命令的集成,但功能更強)/cdrom
#https://packages.Ubuntu.com/natty/iso-scan這裏有介紹
#
#initrid (loop)/casper/initrid.lz
#其中initrid.lz是一個鏡象文件,裏麵存的是一些內核要加載的重要文件。
#
#boot
#}
# =============================================================== #
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
========================================================================
現在還遺留的問題
1 沒有中文字體,回來下個庫文件打算自己整,或者哪位同仁有自己做好的,可以交流一下。
2 不能直接引導PE,對這個要說的話比較多,也有一些想法,有時間的話也可以和同仁交流一下。
3 不能引導Win7或Win XP等安裝盤,現在還不會,學習資料網上幾乎沒有,grub2 好像也不太支持。
4 找了一個CDlinux 迷你版的,光有命令行那種的,不太滿意。
5 dos工具箱自己修改的大地PE dos工具箱還算可以。現在有點小問題。希望哪位同仁有Dos下支持鼠標點擊拖放文件的軟件給我考一份。
6 grub2 在網絡中得應用,時間緊還沒接觸,不過已經看了一篇這類的帖子了。
7 光盤係統引導文件,在grub2中,自己能修改麼,現在還不會,時間夠就看看。
最後更新:2017-04-03 16:48:39