标签:小型内核
准备环境:宿主机,目标机,硬盘一块
在宿主机上操作:
首先在宿主机上准备一块硬盘sdb,大小为10G即可。分2个区sdb1(50M)和sdb2(512M)。
格式化该磁盘
# mke2fs -t ext4 /dev/sdb1 # mke2fs -t ext4 /dev/sdb2
分别挂载
# mount /dev/sdb1 /mnt/boot/ # mount /dev/sdb2 /mnt/sysroot/
创建grub文件
# grub-install --root-directory=/mnt /dev/sdb
# cd /mnt/boot/ 编辑grub配置文件 # vim grub/grub.conf
# cd /mnt/sysroot/
创建目录
编辑#vim /sbin/init
echo -e "Welcome to zhou \033[33Customed \033[0m linux"
mount -n -t proc proc /proc
mount -n -t sysfs sysfs /sys
mount -n -t devtmpfs none /dev
mount -n -o remount,rw /dev/sda2 /
/bin/bash给其执行权限
# chmod +x sbin/init
执行脚本bincp.sh复制命令:
[root@MinR ~]# bash bincp.sh
Plz enter a command: bash
Plz enter a command: mount
Plz enter a command: umount
Plz enter a command: ls
Plz enter a command: kill
Plz enter a command: ifconfig
Plz enter a command: quit
解压内核
# tar xf linux-3.13.6.tar.xz # cd linux-3.13.6 # make allnoconfig # make menuconfig
要手动勾选的内核选项
64-kit kernel
Ceneral setup
--> Local version - append to kernel release
--> System V IPC
Enable loadable module support
--> Module unloading
Enable the block layer
--> Block layer SG support v4
Processor type and features
--> Symmetric multi-processing support
--> Processor family
--> Core 2/newer Xeon
--> Multi-core scheduler suppor
Bus options (PCI etc.)
--> PCI support
Executable file formats / Emulations
--> Kernel support for ELF binaries
--> Kernel support for scripts starting with #!
Networking support
--> Networking options
--> TCP/IP networking
Device Drivers
--> Generic Driver Options
--> Maintain a devtmpfs filesystem to mount at /dev
--> Automount devtmpfs at /dev, after the kernel mounted the rootfs
--> SCSI device support
--> SCSI device support
--> SCSI disk support
--> Fusion MPT device support
--> Fusion MPT ScsiHost drivers for SPI
--> Fusion MPT logging facility
--> Network device support
--> Ethernet driver support
--> Intel devices
--> Intel(R) PRO/1000 Gigabit Ethernet support
--> Intel(R) PRO/1000 PCI-Express Gigabit Ethernet support
--> Input device support
--> Mouse interface
--> Keyboards
--> Mice
--> USB support
--> xHCI HCD (USB 3.0) support
--> EHCI HCD (USB 2.0) support
--> OHCI HCD (USB 1.1) support
--> UHCI HCD (most Intel and VIA) support
File systems
--> The Extended 4 (ext4) filesystem
# make –j 4
复制bzImage
# cp arch/x86/boot/bzImage /mnt/boot/
而后把磁盘放入到目标机上实验下可否正常启动
# make menuconfig # make -j 3 # make install # cp _install/* /mnt/sysroot # ls /mnt/sysroot/ clipboard[54] # cp /root/busybox-1.22.1/_install/* /mnt/sysroot/ -r
为目标创建根文件系统。
# cd /mnt/sysroot # mkdir -pv boot dev etc/{rc.d,sysconfig,profile.d} home/{gentoo,fedora,test,} proc root sys usr/{bin,sbin,local,lib,lib64} # chown gentoo.gentoo home/gentoo # chown test.test home/test # chown fedora.fedora home/fedora
配置文件
# vim /mnt/boot/grub/grub.conf
timeout 3
default 0
title nihao linux
root (hd0,0)
kernel /bzImage ro
root=/dev/sda2
物理控制台的inittab:
::sysinit:/etc/rc.d/rc.sysinit
console::respawn:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
用户登录界面的inittab
::sysinit:/etc/rc.d/rc.sysinit
::respawn:/sbin/getty 19200 tty1
::respawn:/sbin/getty 19200 tty2
::respawn:/sbin/getty 19200 tty3
::respawn:/sbin/getty 19200
tty4
::respawn:/sbin/getty 19200 tty5
::respawn:/sbin/getty
19200 tty6
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a
-r
# vim /mnt/sysroot/etc/fstab /dev/sda2 / ext4 defaults 0 0 /dev/sda1 /boot ext4 defaults 0 0 proc /proc proc defaults 0 0 sysfs /sys sysfs defaults 0 0
# vim /mnt/sysroot/etc/rc.d/rc.sysinit
#!/bin/sh
#
echo -e "Welcome to \033[34mWuKui\033[0m Linux"
echo "remounting root
filesystem"
mount -n -o remount,rw /dev/sda2 /
echo "mount all
filesystem"
mount -a
echo "create device file"
mdev -s
echo "set hostname is $HOSTNAME"
[ -r /etc/sysconfig/network ]
&& source /etc/sysconfig/network
[ -z "$HOSTNAME" ] &&
hostname $HOSTNAME || hostname localhost
export PS1=‘[\u@\h \W]\$‘
# vim /mnt/sysroot/etc/passwd
root:x:0:0:root:/root:/bin/sh
fedora:x:501:501::/home/fedora:/bin/sh
test:x:502:502::/home/test:/bin/sh
# vim /mnt/sysroot/etc/group
root:x:0:
fedora:x:501:
test:x:502:
# openssl passwd -1 -salt `openssl rand -hex 4`
Password:
$1$fc73284e$Q/Ntg8FKYsasdbZjp/sakjO
# vim /mnt/sysroot/etc/shadow
root:$1$fc66576e$Q/Ntg4oKYue0bZjp/uh4T0:16272:0:99999:7:::
fedora:$1$fc66576e$Q/Ntg4oKYue0bZjp/uh4T0:16302:0:99999:7:::
test:$1$fc66576e$Q/Ntg4oKYue0bZjp/uh4T0:16302:0:99999:7:::
# chmod 600
/mnt/sysroot/etc/shadow
# vim /mnt/sysroot/etc/sysconfig/network
HOSTNAME=mylinux
提供dropbaer
编译
# ./configure --prefix=/usr/local/dropbear
#
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"
# make
PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
# cd
/usr/local/dropbear/
# ls bin/
clipboard[55]
#
ls sbin/
密钥文件
# bin/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key # bin/dropbearkey -t rsa -s 2048 -f /etc/dropbear/dropbear_rsa_host_key # ll /etc/dropbear/ clipboard[57] # sbin/dropbear -p 22022 -E -F 前台 clipboard[58] # ss -tnlp | grep 22022 clipboard[59] 在XSHELL中测试登陆 clipboard[60] 开始移植 # PATH=/usr/local/dropbear/bin/:/usr/local/dropbear/sbin/:$PATH clipboard[61] clipboard[62] # mkdir /mnt/sysroot/etc/dropbear # dropbearkey -t dss -f /mnt/sysroot/etc/dropbear/dropbear_dss_host_key # dropbearkey -t rsa -s 2048 -f /mnt/sysroot/etc/dropbear/dropbear_rsa_host_ke # mkdir -pv /mnt/sysroot/var/run dropbear # cp /etc/shells /mnt/sysroot/etc # echo /bin/ash >> /mnt/sysroot/etc/shells dropbare启动时依赖的nsswitch # cp /etc/nsswitch.conf /mnt/sysroot/etc # cp -a -d /usr/lib64/libnsspem.so /usr/lib64/libnsssysinit.so /usr/lib64/libnssutil3.so /mnt/sysroot/usr/lib64 # cp -a -d /lib64/libnss_files* /mnt/sysroot/lib64 # cp -a -d /usr/lib64/libnss3.so /usr/lib64/libnss_files.so /mnt/sysroot/usr/lib64 其开机自动挂载 # echo "devets /dev/pts devpts gid=5,mode=620 0 0" >> /mnt/etc/fstab # vim /mnt/sysroot/etc/rc.d/rc.sysinit mkdir /dev/pts 放在mount -a前 clipboard[63] # vim /mnt/sysroot/etc/rc.d/rc.sysinit /sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0 /sbin/ifconfig eth0 192.168.127.53 netmask 255.255.255.0 export PATH=/usr/local/dropbear/bin:/usr/local/dropbear/sbin:$PATH /usr/local/dropbear/sbin/dropbear -p 22
标签:小型内核
原文地址:http://tliss.blog.51cto.com/6883268/1546312