BootSequence(BIOS) -> Bootloader(MBR) -> Kernel(ramdisk) -> rootfs -> switchroot ->..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

制作一個最小的CentOS6系統(tǒng)

發(fā)布時間:2020-07-08 07:47:47 來源:網(wǎng)絡(luò) 閱讀:332 作者:USCWIFI 欄目:系統(tǒng)運維

制作一個最小的CentOS6系統(tǒng)

首先要明確一下CentOS6啟動的過程

POST -> BootSequence(BIOS) -> Bootloader(MBR) -> Kernel(ramdisk) -> rootfs -> switchroot -> /sbin/init -> (/etc/inittab,/etc/init/*.conf) -> 設(shè)置默認運行級別 -> 系統(tǒng)初始化腳本 ->關(guān)閉或啟動對應(yīng)級別下的服務(wù) -> 啟動終端

1、POST不用管,硬件的事

2、BootSequence,手動選擇某個硬盤啟動即可

3、Bootloader即stage1.0階段,使用grub-install生成

stage1.5階段也用grub-install生成

4、stage2.0階段即內(nèi)核文件vmlinuz和ramdisk鏡像從源系統(tǒng)復(fù)制一份

然后需要grub文件,CentOS6就手動寫一份吧,格式如下:

default=#:設(shè)定默認啟動的菜單項;落單項(title)編號從0開始
timeout=#:指定菜單等待選項選擇的時長
splashimage=(hd#,#)/PATH/TO/XPM_PIC_FILE:指定菜單背景圖片
hiddenmenu:隱藏菜單
title TITLE:定義菜單標(biāo)題
    root(hd#,#)grub查找stage2及kernel文件所在的設(shè)備分區(qū):為grub的根
    kernel /PATH/TO/VMLINUZ_FILE:啟動的內(nèi)核
    initrd /PATH/TO/INITRAMFS_FILE:內(nèi)核匹配的ramfs文件
    password [--md5] STRING:菜單編輯認證

5、復(fù)制幾個命令,開啟也別啟動/sbin/init,直接啟動/bin/bash行了

腳本:copycmd-拷貝命令及其依賴庫

開始搞

一、CentOS6虛擬機加一個硬盤

制作一個最小的CentOS6系統(tǒng)

二、分區(qū)掛到臨時目錄下

swap分區(qū)可以不要,剛開始啟動不起來,我還以為是缺少swap分區(qū),后來發(fā)現(xiàn),是因為selinux問題,grub.conf里面kernel哪一行加上selinux=0即可

[root@localhost ~]# for i in `seq 0 2`;do echo - - - >/sys/class/scsi_host/host$i/scan;done
[root@localhost ~]# lsblk /dev/sdb -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sdb 
#一個boot分區(qū),一個根分區(qū)算了
[root@localhost ~]# fdisk /dev/sdb
Command (m for help): n
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +300M
Command (m for help): n
p
Partition number (1-4):
Partition number (1-4): 2
Last cylinder, +cylinders or +size{K,M,G} (40-130, default 130): +100M
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Command (m for help): n
p
Partition number (1-4): 3
Last cylinder, +cylinders or +size{K,M,G} (54-130, default 130):
Command (m for help): w
The partition table has been altered!
#創(chuàng)建文件系統(tǒng)
[root@localhost ~]# mkfs.ext4 /dev/sdb1
[root@localhost ~]# mkswap /dev/sdb2
[root@localhost ~]# mkfs.ext4 /dev/sdb3
[root@localhost ~]# lsblk -f /dev/sdb
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sdb                                                      
├─sdb1 ext4         54632ecc-7b84-400e-9c44-bc01edf500b5 
├─sdb2 swap         6ca8ef8e-3753-447e-ba89-569b6258ea25 
└─sdb3 ext4         a80dd4f2-d9f6-4eb0-909a-54d1ac06fd6b 
#臨時掛
[root@localhost ~]# mkdir /mnt/{boot,sysroot}
[root@localhost ~]# mount /dev/sdb1 /mnt/boot/
[root@localhost ~]# mount /dev/sdb3 /mnt/sysroot/
三、生成grubstage1.0-stage2.0文件
[root@localhost ~]# grub-install --root-directory=/mnt /dev/sdb
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /mnt/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(fd0)   /dev/fd0
(hd0)   /dev/sda
(hd1)   /dev/sdb
四、復(fù)制內(nèi)核文件vmlinuz和ramfs鏡像
[root@localhost ~]# cp /boot/vmlinuz-2.6.32-754.el6.x86_64 /mnt/boot/vmlinuz
[root@localhost ~]# cp /boot/initramfs-2.6.32-754.el6.x86_64.img /mnt/boot/initramfs.img

手寫grub.conf,照著/boot/grub/grub.conf

注意:selinux=0不啟用selinux,init=/bin/bash表示開機使用/bin/bash,不使用/sbin/init

[root@localhost ~]# cat /mnt/boot/grub/grub.conf 
default=0
timeout=5
title CentOS6 test (hehehaha)
kernel /vmlinuz ro root=/dev/sda3 selinux=0 init=/bin/bash
initrd /initramfs.img
五、創(chuàng)建目錄,復(fù)制命令

腳本:copycmd-拷貝命令及其依賴庫

[root@localhost sysroot]# mkdir home tmp root usr lib lib64 proc etc mnt bin sbin dev opt var sys

制作一個最小的CentOS6系統(tǒng)

切根試試:

[root@localhost ~]# chroot /mnt/sysroot/
bash-4.1# ls
bin  etc   lib    mnt  proc  sbin  tmp  var
dev  home  lib64  opt  root  sys   usr
bash-4.1# pwd
/
bash-4.1# cd root
bash-4.1# pwd
/root

順便復(fù)制個網(wǎng)卡驅(qū)動

[root@localhost ~]# ethtool -i eth0
driver: e1000
version: 7.3.21-k8-NAPI
firmware-version: 
bus-info: 0000:02:01.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no
[root@localhost ~]# find / -name e1000.ko
/lib/modules/2.6.32-754.el6.x86_64/kernel/drivers/net/e1000/e1000.ko
[root@localhost ~]# cp /lib/modules/2.6.32-754.el6.x86_64/kernel/drivers/net/e1000/e1000.ko /mnt/sysroot/lib/
六、關(guān)機,新建虛擬機使用該磁盤啟動

自定義創(chuàng)建虛擬機

制作一個最小的CentOS6系統(tǒng)

神奇的grub界面:

制作一個最小的CentOS6系統(tǒng)

進去之后,加載網(wǎng)卡,配IP,ping一下別的虛擬機

制作一個最小的CentOS6系統(tǒng)

LFS:構(gòu)建最小Linux文檔:https://lctt.github.io/LFS-BOOK/

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI