Make a minimum CentOS6 system
Make a minimum CentOS6 system
First of all, we need to clarify the process of starting CentOS6.
POST-> BootSequence (BIOS)-> Bootloader (MBR)-> Kernel (ramdisk)-> rootfs-> switchroot-> / sbin/init-> (/ etc/inittab,/etc/init/*.conf)-> set default runlevel-> system initialization script-> shut down or start services at the corresponding level-> start terminal
1. POST doesn't have to worry about hardware.
2. BootSequence, manually select a hard disk to start.
3. Bootloader is the stage1.0 phase, which is generated using grub-install.
The stage1.5 phase is also generated with grub-install
4. In the stage2.0 phase, the kernel files vmlinuz and ramdisk images are copied from the source system.
Then you need a grub file, and CentOS6 can write one manually, in the following format:
Default=#: sets the menu items that start by default The title number starts at 0 timeout=#: specifies the length of time the menu waits for the option to be selected splashimage= (hd# #) / PATH/TO/XPM_PIC_FILE: specify menu background picture hiddenmenu: hide menu title TITLE: define menu title root (hd#,#) grub to find the device partition where stage2 and kernel files are located: root kernel / PATH/TO/VMLINUZ_FILE for grub: started kernel initrd / PATH/TO/INITRAMFS_FILE: kernel matching ramfs file password [--md5] STRING: menu editing authentication
5. Copy a few commands, and don't start / sbin/init, just start / bin/bash line.
Scripts: copycmd- copy commands and their dependent libraries
Start working on a CentOS6 virtual machine and a hard disk.
Second, the partition is hung under the temporary directory
The swap partition may not be needed. At first, it could not be started. I thought it was a lack of swap partition. Later, I found that it was because of the selinux problem. You can add selinux=0 to which line of kernel in the grub.conf.
[root@localhost ~] # for i in `seq 02`; do echo-> / sys/class/scsi_host/host$i/scan Done [root@localhost ~] # lsblk / dev/sdb-fNAME FSTYPE LABEL UUID MOUNTPOINTsdb # one boot partition For a root partition, calculate [root@localhost ~] # fdisk / dev/sdbCommand (m for help): npPartition number (1-4): 1First cylinder (1,130,1): Last cylinder, + cylinders or + size {K default G} (1,130,130): + 300MCommand (m for help): npPartition number (1-4): Partition number (1-4): 2Last cylinder, + cylinders or + size {K Mague G} Default: + 100MCommand (m for help): tPartition number (1-4): 2Hex code (type L to list codes): 82Command (m for help): npPartition number (1-4): 3Last cylinder, + cylinders or + size Default: Command (m for help): wThe partition table has been altered files # create a file system [root@localhost ~] # mkfs.ext4 / dev/sdb1 [root@localhost ~] # mkswap / dev/sdb2 [root@localhost ~] # mkfs.ext4 / dev/sdb3 [root@localhost ~] # lsblk-f / dev/sdbNAME FSTYPE LABEL UUID MOUNTPOINTsdb ├─ sdb1 ext4 54632ecc-7b84-400e-9c44-bc01edf500b5 ├─ sdb2 swap 6ca8ef8e-3753-447e-ba89-569b6258ea25 └─ sdb3 ext4 a80dd4f2-d9f6-4eb0-909a-54d1ac06fd6b # temporarily hang [root@localhost ~] # mkdir / mnt/ {boot Sysroot} [root@localhost ~] # mount / dev/sdb1 / mnt/boot/ [root@localhost ~] # mount / dev/sdb3 / mnt/sysroot/ 3. Generate the grubstage1.0-stage2.0 file [root@localhost ~] # grub-install-- root-directory=/mnt / dev/sdbProbing 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 IV. Copy kernel file vmlinuz and ramfs image [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
Handwritten grub.conf, according to / boot/grub/grub.conf
Note: if selinux,init=/bin/bash is not enabled in selinux=0, it means to use / bin/bash instead of / sbin/init to boot.
[root@localhost ~] # cat / mnt/boot/grub/grub.conf default=0timeout=5title CentOS6 test (hehe) kernel / vmlinuz ro root=/dev/sda3 selinux=0 init=/bin/bashinitrd / initramfs.img 5. Create directory and copy command
Scripts: copycmd- copy commands and their dependent libraries
[root@localhost sysroot] # mkdir home tmp root usr lib lib64 proc etc mnt bin sbin dev opt var sys
Try cutting the root:
[root@localhost ~] # chroot / mnt/sysroot/bash-4.1# lsbin etc lib mnt proc sbin tmp vardev home lib64 opt root sys usrbash-4.1# pwd/bash-4.1# cd rootbash-4.1# pwd/root
Copy a network card driver by the way.
[root@localhost ~] # ethtool-I eth0driver: e1000version: 7.3.21-k8-NAPIfirmware-version: bus-info: 0000:02:01.0supports-statistics: yessupports-test: yessupports-eeprom-access: yessupports-register-dump: 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/ VI. Turn off the machine Start a new virtual machine with this disk
Custom create virtual machine
Magical grub interface:
After entering, load the network card and IP,ping other virtual machines.
LFS: building the smallest Linux document: https://lctt.github.io/LFS-BOOK/