歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> linux之啟動過程與管理

linux之啟動過程與管理

日期:2017/3/1 11:41:01   编辑:關於Linux

linux之啟動過程與管理。

啟動過程:

通電 -> BIOS -> MBR -> 執行啟動代碼(Grub) -> 讀取/boot/grub/grub.conf(選擇啟動的操作系統)

CentOS啟動流程:

啟動內核

-> 掛載臨時文件系統(initrd.img 內存操作系統)

-> 根據grub傳的參數去掛載硬盤根分區

-> /etc/init/rcS.conf 初始化操作系統配置

-> /etc/inittab 確定操作系統的運行級別

-> /etc/rc.d/rc.sysinit 操作系統初始化

-> /etc/init/rc.conf 啟動對應級別的服務程序

-> /etc/rc.d/rc5.d/*

-> /etc/fstab 用戶自定義開機掛載配置

-> /etc/rc.d/rc.local 用戶自定義啟動腳本(文本界面)

-> /etc/init/prefdm.conf 啟動圖形界面

/etc/X11/xinit/xinitrc.d/* 圖形界面的配置腳本

-> /etc/profile 登錄成功針對用戶進行初始配置

-> /etc/profile.d/*

-> ~/.bash_profile 用戶登錄成功,馬上會執行對應登錄用戶的配置腳本

-> ~/.bashrc shell啟動時執行的配置腳本

GRUB1.x:

windows安裝grub啟動項: easyBCD.exe (grub4dos)

不支持ntfs格式

GRUB啟動ubuntu安裝鏡像:

前提:

ubuntu光盤鏡像放在D盤

D盤掛載到/disk/D

fat32格式的分區掛載/disk/fat32

sudo -i

cd /disk/D

mount -o loop ubuntu-16.04-desktop-amd64.iso /mnt

cp /mnt/casper/vmlinuz.efi /mnt/casper/initrd.lz /disk/fat32/

cp ubuntu-16.04-desktop-amd64.iso /disk/fat32/ubuntu16.04.iso

vim /boot/grub/grub.conf

以下內容追加到grub.conf配置文件後:

title ubuntu install

root (hd0,10)

kernel /vmlinuz.efi boot=casper iso-scan/filename=/ubuntu16.04.iso --label live-install

initrd /initrd.lz

重啟進入ubuntu安裝系統:

1. 打開終端(ctrl + alt + t)

sudo umount -l /isodevice

2. 選擇已分好的分區作為根分區

GRUB啟動Centos6.7安裝鏡像:

sudo -i

mount -o loop CentOS-6.7-x86_64-bin-DVD1.iso /mnt

cp /mnt/isolinux/vmlinuz /disk/fat32/centos_vmlinuz

cp /mnt/isolinux/initrd.img /disk/fat32/centos_initrd.img

cp /mnt/images /disk/fat32/ -rf

cp CentOS-6.7-x86_64-bin-DVD1.iso /mnt/

以下內容追加到grub.conf配置文件裡:

title CentOS Install

root (hd0,10)

kernel /centos_vmlinuz

initrd /centos_initrd.img

GRUB啟動Ghost:

sudo -i

cp memdisk ghost.img /boot/

以下內容追加到grub.conf配置文件裡:

title Ghost

root (hd0,5)

kernel /boot/memdisk c=2000 s=36 h=4 floppy

initrd /boot/ghost.img

GRUB版本:

centos 0.97 只識別fat32與centos格式化的分區

windows grub4dos 支持ntfs格式

EasyBCD 安裝grub, 只安裝到windows的啟動程序中, 不會破壞MBR的啟動程序

ubuntu grub2 支持ntfs iso9660等格式

grub 菜單: 選擇要啟動的操作系統

上下鍵可以選擇要啟動的操作系統, 按回車或方向 右鍵啟動系統

選擇可啟動操作系統的條目,按e可以進行編輯啟動選項

編輯完成後按b啟動此操作系統(非grub2版本)

GRUB2版本按F10或ctrl + x啟動此操作系統

編輯完成後不能回到主菜單,回到主菜單剛才的編輯全部失效

GRUB識別分區:

(hd0,0)

hd0 代表第一塊硬盤

,0 代表第一塊硬盤的第一個分區

從0開始計數, GRUB2版本從1開始 計數

grub 命令行的通用命令:

root 選擇grub根分區

非GRUB2版本: root (hd0,0)

GRUB2版本: set root='(hd0,1)'

kernel 選擇要啟動操作系統的內核文件 (非GRUB2版本)

linux 選擇要啟動操作系統的內核文件(GRUB2版本)

initrd 選擇臨時文件系統文件

boot 手動啟動操作系統(依賴linux/initrd的設置)

rootnoverify (hd0,0) 非GRUB2版本選擇windows C盤

chainloader +1 讀取當前grub選擇的根的第一邏輯塊

cat 讀取文件內容

ls 列表目錄裡文件

GRUB2 命令行:

insmod 加載grub模塊

help 獲取grub2當前命令列表

loopback 加載ISO文件

set root=(hd0,5)

loopback loop /ubuntu.iso

set root=(loop)

linux /casper/vmlinuz.efi boot=casper iso-scan/filename=/ubuntu.iso --label live-install

initrd /casper/initrd.lz

boot

GRUB2搶修模式:

搶修模式效果: 開機啟動進入grub rescue>提示符

能進搶修模式的原因, grub程序被破壞(MBR的啟動程序被破壞, grub與根分區的關聯關系出現問題)

解決辦法: 重新安裝GRUB

sudo grub-install /dev/sda

搶修模式下

前提硬盤上有好的GRUB2操作系統: (hd0,8)

set prefix=(hd0,8)/boot/grub

set root=(hd0,8)

insmod normal

normal

進入操作系統的搶修模式(臨時的Linux操作系統):

提示硬盤已有Linux操作系統: (hd0,6)

mount /dev/sda6 /mnt

mount -o bind /dev/ /mnt/dev

mount -o bind /proc/ /mnt/proc

mount -o bind /sys/ /mnt/sys

mount -o bind /tmp/ /mnt/tmp

chroot /mnt

grub-install /dev/sda

ubuntu安裝根加密:

進入ubuntu安裝系統的終端

sudo -i

如果沒有分好區,可以在命令行通過fdisk或gdisk來分區

cryptsetup luksFormat /dev/sda8

輸入YES,再輸入保護密碼

cryptsetup luksOpen /dev/sda8 ms

輸入密碼解開加密分區

開始安裝,到了選擇根分區選擇加密分區,並且格式化(/dev/mapper/ms)

安裝到最後選擇不要重啟, 回到命令行

sudo -i

mount /dev/mapper/ms /mnt

mount -o bind /dev/ /mnt/dev

mount -o bind /proc/ /mnt/proc

mount -o bind /sys/ /mnt/sys

mount -o bind /tmp/ /mnt/tmp

chroot /mnt

將以下內容寫入/etc/crypttab文件中:

ms UUID=/dev/sda8的UUID none luks

寫完文件後執行命令: update-initramfs -u

重啟電腦

ubuntu grub啟動項修改:

menuentry 'centos6.7' {

set root='(hd0,6)'

linux /boot/vmlinuz-... root=/dev/sda6

initrd /boot/initramfs...

}

menuentry 'ubuntu install' {

set root=(hd0,5)

loopback loop /ubuntu.iso

set root=(loop)

linux /casper/vmlinuz.efi boot=casper iso-scan/filename=/ubuntu.iso quiet splash --

initrd /casper/initrd.lz

}

menuentry 'centos install' {

set root=(hd0,5)

loopback loop /centos.iso

set root=(loop)

linux /isolinux/vmlinuz

initrd /isolinux/initrd.img

}

menuentry 'ghost' {

set root='(hd0,5)'

linux16 /memdisk c=2000 s=36 h=4 floppy

initrd16 /ghost.img

}

Copyright © Linux教程網 All Rights Reserved