To prepare a liunx machine, I'm using a liunx virtual machine.
Loading a single hard disk, I loaded a 20G hard disk, and then partition with FDISK/DEV/SDB, SDB1 used as the future system's/boot partition, all 100M can be, SDB2 used as a future system/partition, I gave 10G. The two partitions are then formatted as EXT4 systems.
Mkdir/mnt/boot
Mkdir/mnt/sdc2
Mount/dev/sdb1/mnt/boot
Mount/dev/sdb2/mnt/sdc2
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/16/wKioL1fT4zWRWZhsAABMXri2n-Q444.jpg "title=" Diylinux1.jpg "alt=" Wkiol1ft4zwrwzhsaabmxri2n-q444.jpg "/>
4. Execute the grub-install command, the yellow arrow is the directory to be used in the future, the red arrow indicates that the grub related files are written to the/SDB disk (grub related files are the key files used to boot the boot kernel)
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/17/wKioL1fT5YnwHc9RAAASxJCMQNQ554.jpg "title=" Diylinux2.jpg "alt=" Wkiol1ft5ynwhc9raaasxjcmqnq554.jpg "/>
5. Copy kernel files and file system files to/boot
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/87/19/wKiom1fT58Cxsv0CAAAaYZZ4cMM678.jpg "title=" Diylinux3.jpg "alt=" Wkiom1ft58cxsv0caaaayzz4cmm678.jpg "/>
6. Edit the/mnt/boot/grub/grub.conf file
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/19/wKiom1fT6S-AnlWEAAAoy9TbgIo778.jpg "title=" Diylinux4.jpg "alt=" Wkiom1ft6s-anlweaaaoy9tbgio778.jpg "/>
First line: The path of the background picture when the list appears (see my related article for how to make a picture)
Second line: The name of the kernel
Third line: Start from the first sector of the first hard drive in the future
Line four: Boot kernel file, read only,/directory in/DEV/SDA2 partition at this time SELinux shutdown init program Read/bin/bash
Line five: A temporary file system before the root is available,initrd is bound to the kernel and loaded as part of the kernel boot process. The kernel then loads the Initrd file as part of its two-stage boot process to later use the real file system and mount the actual root filesystem.
7. Write-Mount files
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/19/wKiom1fT7QjC6H5IAAAbvfupWqs499.jpg "title=" Diylinux5.jpg "alt=" Wkiom1ft7qjc6h5iaaabvfupwqs499.jpg "/>
8. Create a folder in the root directory under/mnt/sdc2/
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/17/wKioL1fT8Z6C9lbvAAAcynQndHg665.jpg "title=" Diylinux6.jpg "alt=" Wkiol1ft8z6c9lbvaaacynqndhg665.jpg "/>
9. Use the script to copy some commands to the new directory (execute this command under/MNT/SDC2)
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/17/wKioL1fT8pmjB_ewAABi41IjshU563.jpg "title=" Diylinux7.jpg "alt=" Wkiol1ft8pmjb_ewaabi41ijshu563.jpg "/>
The script reads as follows:
#!/bin/bash
ch_root= "/mnt/sdc2"
[!-d $ch _root] && mkdir $ch _root
Bincopy () {
If which $ &>/dev/null; Then
Local cmd_path= ' which--skip-alias $ '
Local bin_dir= ' dirname $cmd _path '
[-D ${ch_root}${bin_dir}] | | Mkdir-p ${ch_root}${bin_dir}
[-F ${ch_root}${cmd_path}] | | CP $cmd _path ${ch_root}${bin_dir}
return 0
Else
echo "Command not found."
Return 1
Fi
}
ch_root= "/MNT/SDC2"
[!-d $ch _root] && mkdir $ch _root
Bincopy () {
If which $ &>/dev/null; Then
Local cmd_path= ' which--skip-alias $ '
Local bin_dir= ' dirname $cmd _path '
[-D ${ch_root}${bin_dir}] | | Mkdir-p ${ch_root}${bin_dir}
[-F ${ch_root}${cmd_path}] | | CP $cmd _path ${ch_root}${bin_dir}
return 0
Else
echo "Command not found."
Return 1
Fi
}
Libcopy () {
Local lib_list=$ (LDD ' which--skip-alias $ ' | grep-eo '/[^[:space:]]+ ')
For loop in $lib _list;do
Local lib_dir= ' dirname $loop '
[-D ${ch_root}${lib_dir}] | | Mkdir-p ${ch_root}${lib_dir}
[-F ${ch_root}${loop}] | | CP $loop ${ch_root}${lib_dir}
Done
}
Read-p "Please input a command or quit:" command
While ["$command"! = "Quit"];d o
If Bincopy $command; then
Libcopy $command
Fi
Read-p "Please input a command or quit:" command
Done
10. We can now remove the hard drive and mount it to a new liunx system to test whether it will start properly
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/87/19/wKiom1fT86LSN4LHAACkVmE8E00759.jpg "title=" Diylinux8.jpg "alt=" Wkiom1ft86lsn4lhaackvme8e00759.jpg "/>
New Virtual machine
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/87/17/wKioL1fT9FTASiA3AAB7G9-yGXg617.jpg "title=" Diylinux9.jpg "alt=" Wkiol1ft9ftasia3aab7g9-ygxg617.jpg "/>
11. Start a new virtual machine
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/87/19/wKiom1fT9LTzV6DbAADcGxP6Tkk264.jpg "title=" Diylinux10.jpg "alt=" Wkiom1ft9ltzv6dbaadcgxp6tkk264.jpg "/>
At this point, we can see the name of the kernel is zebralinux, that is, we in the/mnt/boot/grub/grub.conf title corresponding to the line, the background image has been changed, indicating that the system is good, can continue
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/19/wKiom1fT9ZPAaCWIAAAcuaLhJAg278.jpg "title=" Diylinux11.jpg "alt=" Wkiom1ft9zpaacwiaaacualhjag278.jpg "/>
Because we set up Init=/bin/bash, all the first programs executed after booting into bash, in which we can test other commands, some commands should be available, and some have commands that depend on other files maybe at the moment or not, we just made a simple Linux.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/17/wKioL1fT9xbgVaO9AADLtiIkPGc875.jpg "title=" Diylinux12.jpg "alt=" Wkiol1ft9xbgvao9aadltiikpgc875.jpg "/> The first time we mount, SDA1 was not mounted. When we mount it, we will get an error, but it can still be mounted. After that, we are ready to go to the directory and/boot directory.
This article is from the "zebra930" blog, make sure to keep this source http://zebra930.blog.51cto.com/11736340/1851442
DIY Your own Linux