Lab Environment:VMware Workstation Pro 14 (Trial version)
System Platform:
CentOS Release 6.9 (Final) kernel 2.6.32-696.el6.x86_64
Steps:
1. Partitioning and creating a file system
# FDISK/DEV/SDB
Divided into two necessary partitions
/DEV/SDB1 corresponding to/boot
/DEV/SDB2 corresponding Root/
2. Format File system
# MKFS.EXT4/DEV/SDB1
# MKFS.EXT4/DEV/SDB2
3. Mount/boot of the home-made Linux
# Mkdir/mnt/boot subdirectory must be boot
# Mount/dev/sdb1/mnt/boot
4. Installing Grub
#grub-install--root-directory=/mnt/dev/sdb
#hexdump-C-N 512/dev/sdb see that the SDB disk has been written to the MBR boot information
5. Copy the internal core and Initramfs files
#cp/boot/vmlinuz-2.6.32-696.el6.x86_64/mnt/boot/vmlinuz
#cp/boot/initramfs-2.6.32-696.el6.x86_64.img/mnt/boot/initramfs.img
6. Establish grub.conf
# cat >/mnt/boot/grub/grub.conf << EOF
Default=0
Timeout=30
Title Hunk_linux
Root (hd0,0)
Kernel/vmlinuz ro root=/dev/sda2 selinux=0 init=/bin/bash
Initrd/initramfs.img
Eof
Root=/dev/sda2 is considered to be attached to other machines later, SDA1 is/boot,sda2 Yes/
7. Creating a root system for a home-made Linux system
#mkdir/mnt/rootfs
#mount/dev/sdb2/mnt/rootfs/
#mkdir/mnt/rootfs/{etc,boot,dev,lib,lib64,home,var,usr,tmp,proc,sys,root,opt,mnt,srv,misc,net}
8. Copy the NIC driver to the root system of the home-made Linux system
#modinfo e1000
FileName:/lib/modules/2.6.32-696.el6.x86_64/kernel/drivers/net/e1000/e1000.ko
#cp/lib/modules/2.6.32-696.el6.x86_64/kernel/drivers/net/e1000/e1000.ko/mnt/rootfs/lib/
8. Run the script I wrote . (http://blog.51cto.com/191226139/2057595 found the 6th exercise) to run the program all at once
9. Copy the program file you just generated and the root system of LIB to the home-made Linux system
#cp-R/tmp/commands/*/mnt/rootfs/
10. You can switch to the target root for test commands
# Chroot/mnt/sysroot
11. Attach the disk to a newly created machine for testing
There's no problem with instructions.
After the network card is loaded with Insmod/lib/e1000.ko, the IP can be configured using Ifconfig.
At last:
Because of the use of/bin/bash instead of/sbin/init, the system is only used as a simple small system to deepen the understanding of the knowledge and to test whether the script written is working properly.
If you are interested, you can replace it with/sbin/init, just need to configure some configuration files.
Self-made Simple small Linux