在您使用下個章節的 Tomsrtbt 軟碟或使用 RedHat 開機光碟 (使用救援選項) 登入之後, 您最好先備分重要的系統檔案,像 /etc/fstab、/etc/lilo.conf。 如此在當機時或系統檔案發生問題時是、活B菕B楚﹛BBB磽野峈滿C
bash# cp /etc/fstab /etc/fstab.orig bash# cp /etc/lilo.con etc/lilo.c,,,.orig bash# cp /etc/hosts /etc/hosts.orig bash# cp /etc/hosts.allow /etc/hosts.allow.orig bash# cp /etc/hosts.deny /etc/hosts.deny.orig bash# cp /etc/inetd.conf /etc/inetd.conf.orig bash# cp /etc/inittab /etc/inittab.orig bash# cp /etc/networks /etc/networks.orig
大部份的 Linux 發行套件像是 RedHat、SUSE、Debian, 皆有提供具有救援功能的光碟。 您應當設定電腦的 BIOS ,使電腦能以 IDE 光碟機為第一開機裝置,以便使用這類光碟。 設定 BIOS 時 (在開機時按 F8 鍵),以光碟機為第一開機裝置; 軟碟機為第二開機裝置;硬碟為第三開機裝置。 將 Linux 光碟片放入光碟機,並重開機。 Linux 套件將會被讀取。在提示符號 (prompt) 下選擇「救援操作」。 在救援操作模式下,掛上 (mount) 硬碟並嘗試修復它。
# chroot /mnt/SYSIMAGE # df
循著這些步驟執行,以便從 LILO 或系統當機中回復。
取得並建立 tomsrtbt 開機磁片 http://www.toms.net/rb, 或 MuLinux 開機磁片 (請參考 Tiny Linux)。 並使用 tomsrtbt 開機磁片開機。 使用 fdisk 指令找出分割區(partitions)。 試著找出 root 和 boot 分割區。注意! root 分割區自己需擁有 /boot 檔案。
Linux 的 root 分割區包含下列資料夾 bin, boot, etc, usr.
Linux 的 boot 分割區則包含以下的資料夾: vmlinuz, boot.b, chain.b, map.
使用以下步驟找出 root 分割區:
bash# fdisk /dev/hda Command (m for help): m (顯示指令的輔助選單) Command (m for help): p (列出硬碟分割區) Command (m for help): q bash# mkdir /test bash# mount /dev/hda1 /test bash# ls /test 您應該會看到 root 分割區顯示如下 - bin fd lib mnt proc sbin usr boot dev etc home lost+found opt root tmp var
接下來您應找出 /boot、/usr、和 /var 分割區。 在建立新的 lilo 配置時,這些分割區的位置是必需的。
以我的系統為例,root 分割區是在 /dev/hda4:
bash# mkdir /rootpart bash# mount /dev/hda4 /rootpart bash# cat /rootpart/etc/fstab 閱讀 fstab 的內容,並且按照 fstab 檔案掛上 (mount) 分割區。像下面這樣 - bash# mount /dev/hda5 /rootpart/boot bash# mount /dev/hda6 /rootpart/usr bash# mount /dev/hda7 /rootpart/var bash# mount /dev/hda8 /rootpart/opt bash# mount /dev/hda9 /rootpart/root bash# mount /dev/hda10 /rootpart/home
編輯 /etc/fstab (不是 /rootpart/etc/fstab) 並且加入(以下程式碼範例)
/dev/hda4 /rootpart ext2 defaults 1 1 /dev/hda5 /rootpart/boot ext2 defaults 1 1 /dev/hda6 /rootpart/usr ext2 defaults 1 1 /dev/hda7 /rootpart/var ext2 defaults 1 1 /dev/hda8 /rootpart/opt ext2 defaults 1 1 /dev/hda9 /rootpart/root ext2 defaults 1 1 /dev/hda10 /rootpart/home ext2 defaults 1 1 /dev/hda11 /rootpart/win95part vfat defaults 1 1 在我的電腦中,hda4 為 linux 的 root 分割區、hda5 為 boot 分割區、 hda11 則為 windows 95 的 vfat 系統。 bash# mkdir /rootpart/win95part bash# mount /rootpart/win95part 使用 fsck 或 e2fsck 指令修復有問題的分割區。 bash# man fsck bash# man e2fsck
依照狀況 1 的步驟來排除問題。如果無法解決,則參照以下步驟。 在執行狀況 1 的步驟之後,您應該已經掛載上 /rootpart 並且已經建立好 /etc/fstab 檔案。
注意:在進行以下步驟時,觀察 chroot 如何運作是很重要的。 chroot 所使用的 /sbin/lilo 檔案的正確位置是在 /rootpart/sbin/lilo, 而不是在 /sbin!!因此請不要混淆。
bash# mount -a bash# chroot /rootpart /sbin/lilo -q bash# man chroot bash# chroot /rootpart /sbin/lilo
注意:使用 chroot 的新手可能會被混淆。如果 chroot 抱怨它找不到 /boot/map 檔案, 這種情形實際上代表著它無法找到 /rootpart/boot/map。因為您使用 /rootpart 當作 chroot 的第一引數 (first argument),所有的化身 (references) 都指向 /rootpart。
您也可以選擇直接使用 /sbin/lilo 以代替 chroot。 lilo 加選項 -r 實際上就和 chroot 指令是一樣的。 強烈建議您使用 chroot,而不要使用 lilo -r, 因為使用 chroot 比較方便,且較容易找出錯誤。
bash# man lilo bash# /sbin/lilo -r /rootpart
如果使用狀況 1 和狀況 2 的步驟均無法解決, 假如您有使用 'mkbootdisk' 製作過開機片(於安裝時或參考 'man mkbootdisk'自行建立),則使用您的開機磁片來開機並修復分割區。 mkbootdisk 存在於 mkbootdisk*.rpm 的套件,您必須安裝它。 (譯注:隨不同發行套件而有所差異;請洽詢您的發行套件廠商或組織) 或者從 http://www.bootdisk.com/ 取得 Linux/NT/Windows/DOS/Mac 的開機磁片。 其他選擇 - 找 Linux 安裝光碟來使用。 每個 Linux 套件會在光碟裡提供救援磁片的 image file,在 Linux 環境下,鍵入 "dd if=/cdrom/disks/rescue of=/dev/fd0" 來建立救援磁片。在 DOS 環境下, 使用 rawrite.exe (包含在 Linux 光碟裡),鍵入 "rawrite image-name a:" 來建立救援磁片。
假如您有其他 linux 系統的電腦,以 root 身份登入並且執行 -
注意:如果您編譯您自己的核心(kernel)為 bzImage (例如 bzImage-2.4.4), 您應當使用以下方法對 vmlinuz-2.4.4 建立硬連結(hard link)。(注意 vmlinuz 的 z,而非 vmlinux) 如果您並未做此步驟, 則 mkbootdisk 指令可能會失敗。
bash# cd /boot bash# ls -l vmlinuz* bash# ln /boot/bzImage-2.4.4 /boot/vmlinuz-2.4.4
bash$ man mkbootdisk bash# cp /etc/lilo.conf /etc/lilo-original.conf
bash# mkbootdisk --device /dev/fd0 2.2.12-20 (譯注:2.2.12-20 為核心版本編號,請自行依照您的 linux 核心版本作改變。)
第一步: 使用 tomsrtbt 開機磁片開機, (請參考 Tiny Linux) 掛上分割區, 並且使用以下指令備份 root 分割區至其他還有磁碟空間的分割區 -
編輯 /etc/fstab 並且寫入(以下的程式碼範例, 您可能必須按照您的磁碟機實際狀況作改變) - /dev/hda4 /rootpart ext2 defaults 1 1 /dev/hda11 /b1 vfat defaults 1 1 bash$ mkdir /rootpart; mount /rootpart bash$ mkdir /b1; mount /b1 bash$ cd / bash$ df 查看 /b1 是否有足夠的磁碟空間,以便使用 tar 來備份 root 分割區。 bash$ tar cvf /b1/root-hda4.tar /rootpart
第二步: 放入 Linux 光碟片,重開機並安裝 redhat linux (譯注:或安裝其他 linux 發行套件) 在 /dev/hda4 (但千萬不要安裝任何多餘的套件, 您只需要安裝 root、boot 系統,和 LILO 管理者。 也就是說,選擇最小安裝即可)。 安裝程式也將會安裝 LILO 在您的硬碟裡。 現在重新啟動 linux,以 root 身份登入,並且執行 -
bash$ man mkbootdisk bash# cp /etc/lilo.conf /etc/lilo-original.conf
bash# mkbootdisk --device /dev/fd0 2.2.12-20 (譯注:2.2.12-20 為核心版本編號,請自行依照您的 linux 核心版本作改變。) bash# cp /etc/lilo-original.conf /etc/lilo.conf
您應當採取下列的預防性措施來處理未來可能發生的問題。
bash$ man mkbootdisk mkbootdisk 存在於 mkbootdisk*.rpm 的套件,您必須安裝它。 (譯注:隨不同發行套件而有所差異;請洽詢您的發行套件廠商或組織) bash$ mkbootdisk --help bash$ mkbootdisk --device /dev/fd0 2.2.12-20 (譯注:2.2.12-20 為核心版本編號,請自行依照您的 linux 核心版本作改變。)
bash$ su - root bash# man fdisk bash# fdisk -l /dev/sda > partition_table_backup.txt
bash# vi /etc/fstab 加入以下數行 - /dev/hda1 /a1 vfat defaults 1 1 /dev/hdb1 /b1 vfat defaults 1 1 以我的系統為例, hda1 為 linux 之 root 分割區 '/' bash# cd / bash# tar cvf /b1/linux-root-partition-hda1.tar a1 bash# tar cvf /b1/linux-boot-partition-hda1.tar a1/boot
您可以使用 DOS 啟動載入程式(boot loader)載入啟動磁區,並以之取代 LILO。 在 MS DOS 提示符號下輸入以下指令:
FDISK /MBR
請參考 LILO 文件,取得其他移除 LILO 的方法;這些文件通常放在 linux 系統上的 /usr/doc/lilo* (譯注:或者是 /usr/share/doc/lilo*)。也請參考 'man lilo'。
在您更改 /etc/lilo.conf 之後,您必須執行 lilo ,使您的改變生效。 忘了執行是 linux 初學者很常犯的錯誤。執行 -
bash# lilo -v -v -v