grub通过img文件启动linux,通过grub4dos引导本地linux系统
剛才在論壇上看到一個貼子,這位網友安裝windows
xp時把引導linux的mbr重寫了,所以進不了linux系統。我知道只要把grub2安裝到mbr上就可以了,但他沒有安裝盤和live
usb,這時可以借助grub4dos這個軟件來引導。
只要把linux系統引導起來就好辦了。
我只知道有這個方法,但沒有遇到過所以在物理機實驗了一下,我的機器如下:windows xp + ubuntu 11.04 +
ubuntu 10.04
分區:
第一個分區:boot ext4 200M
第2,3,4個分區: ntfs xp用
其它的為linux的分區
一、獲取grub4dos軟件包
先上網上下載grub4dos這個軟件。
http://code.google.com/p/grub4dos-chenall/downloads/list
我下載完之后,雙擊解不開,但這個軟件包的后綴是7z,我想是否有7z壓縮類的軟件,于是在終端輸入7z,發現有了提示,安裝上就可以解開了。
linux@cdyemail:~$ 7z
The program '7z' is currently not installed.
You can install it by typing:
sudo apt-get install p7zip-full
linux@cdyemail:~$ sudo apt-get install
p7zip-full
[sudo] password for linux:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
p7zip-rar
....
解開之后復制到 /mnt/winc下(這個是windows xp所在的分區,為硬盤的第二個分區)
二、把grub4添加到起動菜單里
由于用windows xp所以直接在boot.ini中添加就行了。
進行windows的終端(cmd)里,之后
attrib -r -s -h boot.ini
#解除boot.ini的只讀隱藏等屬性
notepad boot.ini ?#編輯boot.ini
我的信息如下:
[boot loader]
timeout=3
default=multi(0)disk(0)rdisk(0)partition(2)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Microsoft Windows
XP Professional" /noexecute=optin /fastdetect /detecthal
c:\grldr='grub4dos' ?#這一句是后加的。
把grub4dos軟件包里的grldr, grldr.mbr ment.lst復制到c盤根目錄下
三、從grub引導linux
啟機之后windows
xp會出現兩個菜單,其中會有'grub4dos'這個菜單項,選擇這個菜單之后會打開menu.lst菜單,但我們不需要這個菜單,按'c'鍵進入grub控制終端:
這里會幾個命令即可
ls ?查看文件
root 設置根
kernal 加載內核
initrd 初始ram磁盤,這是一個臨時的根文件系統,用來支持兩階段的引導過程。
boot 引導
我的實驗:
ls / ?#發現目前處在c盤,但我的內核文件在第一個分區了,xp是第二個分區
ls (hd0,0)/ ?#發現內核文件了。
root=(hd0,0) ?#設置根
ls (hd0,8)/
#發現這是我的linux的root所在的分區,可以多試幾次,找到正確的分區
kernal /vmlinuz-2.6.32-28-generic ?ro text
root=/dev/sda8
initrd /initrd.img-2.6.32-28-generic
boot
啟動后并沒有進入linux系統,這是怎么回事???
現在出現(initramfs)提示符了,我ls了一下,發現是一個簡易的/文件系統,這是
RAM磁盤映像,怎么會沒有加載磁盤的/文件系統呢?
我又ls /root
#發現里面的文件是我原先第一個linux上/home分區中的文件,而這個分區的下一個分區才是第二個linux系統的/
原來是這樣啊,grub4dos (hd0,0)表示第一塊硬盤,那么編號應該+1,所以:
kernal /vmlinuz-2.6.32-28-generic ?ro text
root=/dev/sda9 #改成這個,啟動成功。
測試完畢,一切通過,不過windows7如何添加grub4dos我沒有辦法測試,物理機器上沒裝windows7系統。
grub4dos添加到windows7啟動項里
(1)把grub4dos軟件包里的grldr, grldr.mbr ment.lst復制到c盤根目錄下
(2)運行如下命令
bcdedit /create /d "grub" /application bootsector
#生成id
bcdedit /set {id} device partition=c:
bcdedit /set {id} path \grldr.mbr
bcdedit /displayorder {id} /addlast
我的如下:
C:\Users\cdyemail>bcdedit /create /d "grub"
/application bootsector
項 {d8cc12aa-3068-11e0-acbe-8492abfb673e} 成功創建。
C:\Users\cdyemail>bcdedit /set
{d8cc12aa-3068-11e0-acbe-8492abfb673e} device par
tition=c:
操作成功完成。
C:\Users\cdyemail>bcdedit /set
{d8cc12aa-3068-11e0-acbe-8492abfb673e} path \grld
r.mbr
操作成功完成。
C:\Users\cdyemail>bcdedit /displayorder
{d8cc12aa-3068-11e0-acbe-8492abfb673e} /
addlast
操作成功完成。
之后重啟計算機就會出現菜單了,選擇grub進入grub菜單模式,剩下的與上面的引導指令一樣。
(3)安裝grub2
從grub4dos引導linux成功之后,以root用戶登錄
grub-install /dev/sda ?#安裝grub
update-grub #創建菜單
測試成功!!
總結
以上是生活随笔為你收集整理的grub通过img文件启动linux,通过grub4dos引导本地linux系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 读债务危机0814-08年9月崩溃
- 下一篇: grub4dos和bootmgr双启动