构建自己的MiniLinux
1) 环境准备
在关机状态下新添加一块磁盘
对新加入的磁盘进行分区,并挂载至指定目录
[root@host1 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc65c5fd3 Device Boot Start End Blocks Id System /dev/sdb1 1 14 112423+ 83 Linux /dev/sdb2 15 79 522112+ 83 Linux [root@host1 ~]# mke2fs -t ext4 /dev/sdb1 [root@host1 ~]# mke2fs -t ext4 /dev/sdb2 [root@host1 ~]# mount /dev/sdb1 /mnt/boot/ [root@host1 ~]# mount /dev/sdb2 /mnt/sysroot/ #安装grub到/dev/sdb [root@host1 ~]# grub-install --root-directory=/mnt/ /dev/sdb 下载内核的源码并解压到/usr/src [root@host1 src]# tar xf ~/linux-3.13.6.tar.xz -C /usr/src/ [root@host1 src]# ln -s linux-3.13.6/ linux
2) 编译源码:
#去掉除必须外所有编译选项 [root@host1 linux]# make allnoconfig [root@host1 linux]# make menuconfig #============================================================= #选择编译64位的内核 [*] 64-bit kernel #选择次版本号以便于区分 General setup ---> (mini-v1) Local version - append to kernel release #次版本号 [*]System V IPC #支持进程间通信 #选择CPU类型 Processor type and features Processor family (Core 2/newer Xeon) ---> #选择支持多核心和多处理器 Processor type and features ---> [*] Symmetric multi-processing support [*] Multi-core scheduler support (NEW) #支持PCI总线 Bus options (PCI etc.) ---> [*] PCI support #支持模块的动态装卸载 [*] Enable loadable module support ---> [*] Forced module loading [*] Module unloading [*] Forced module unloading #支持ELF可执行文件和#!开头的文件 Executable file formats / Emulations ---> [*] Kernel support for ELF binaries [*] Write ELF core dumps with partial segments (NEW) <*> Kernel support for scripts starting with #! #支持TCP/IP协议 [*] Networking support ---> #支持网络功能 Networking options ---> [*] TCP/IP networking#支持TCP/IP协议 #支持scsi接口设备 Device Drivers ---> SCSI device support ---> <*> SCSI device support <*> SCSI disk support #设备设置 Device Drivers ---> [*] Fusion MPT device support ---> <*> Fusion MPT ScsiHost drivers for SPI [*] Fusion MPT logging facility #USB接口驱动 Device Drivers ---> [*] USB support ---> <*> Support for Host-side USB <*> 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 #输入设备驱动 Device Drivers ---> Input device support ---> <*> Mouse interface [*] Keyboards ---> <*> AT keyboard (NEW) [*] Mice ---> <*> PS/2 mouse (NEW) #网卡驱动 [*] Network device support ---> [*] Ethernet driver support (NEW) ---> [*] Intel devices #尽量去除不需要的网卡驱动 <*> Intel(R) PRO/1000 Gigabit Ethernet support <*> Intel(R) PRO/1000 PCI-Express Gigabit Ethernet support #自动挂载设备文件到/dev目录 Device Drivers ---> Generic Driver Options ---> [*] Maintain a devtmpfs filesystem to mount at /dev [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs #文件系统选择 File systems ---> <*> The Extended 4 (ext4) filesystem #============================================================= [root@host1 linux]# make -j 4 [root@host1 linux]# make -j4 bzImage#用来制定使用的线程数 [root@host1 linux]# cp arch/x86/boot/bzImage /mnt/boot/
3) 创建必须文件夹并安装busybox
[root@host1 src]# tar xf busybox-1.22.1.tar.bz2 [root@host1 src]# cd busybox-1.22.1 [root@host1 busybox-1.22.1]# make menuconfig #以静态编译方式编译 Build Options ---> [*] Build BusyBox as a static binary (no shared libs) [root@host1 busybox-1.22.1]# make && make install [root@host1 busybox-1.22.1]# cp -a _install/* /mnt/sysroot/ #新已经可以正常进入
#编辑使开机可以自动挂载 [root@host1 rc.d]# vim rc.sysinit #!/bin/sh # mkdir /dev/shm mount -n -t ext4 /dev/sdb2 / mount -n -t ext4 /dev/sda1 /boot mount -n -t proc proc /proc mount -n -t sys sys /sys mount -n -t tmpfs tmpfs /dev/shm mount -a [root@host1 rc.d]# vim rc.sysinit #!/bin/sh # mount -n -o remount,rw -t ext4 /dev/sdb2 / mount -n -t ext4 /dev/sda1 /boot mount -n -t proc proc /proc mount -n -t sys sys /sys mount -a echo -e "Welcome to \033[36mMini OS\033[0m v2 by WH" [root@host1 ~]# vim /mnt/sysroot/etc/fstab /dev/sda2 / ext4 defaults 0 0 /dev/sda1 /boot ext4 defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts defaults 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 #提供用户和密码 [root@host1 etc]# cat passwd root:x:0:0:root:/root:/bin/sh [root@host1 etc]# cat shadow root:$1$sdgsag$3AEIdl7KBstUNb7JOEoDX.:16303:0:99999:7::: [root@host1 ~]# openssl passwd -salt "sdgsag" -1 Password: $1$sdgsag$3AEIdl7KBstUNb7JOEoDX.
#已经可以认证
#网卡也可以正常加载
4) 安装Dropbear,实现ssh连接
[root@host1 ~]# tar xf dropbear-2013.58.tar.bz2 -C /usr/src/ [root@host1 ~]# cd /usr/src/ #编译并安装 [root@host1 dropbear-2013.58]# ./configure --prefix=/usr/local/dropbear [root@host1 dropbear-2013.58]# make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" [root@host1 dropbear-2013.58]# make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install #使用如下脚本将库文件和命令拷贝到/mnt/sysroot/下
#生成密钥
#登陆成功
5) 部署nginx站点
[root@host1 nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --without-pcre --without-http_rewrite_module [root@host1 nginx-1.4.7]# make && make install [root@host1 nginx]# cp -r /usr/local/nginx/ /mnt/sysroot/usr/local/ #添加用户信息和组信息到以下目录 [root@host1 nginx]# vim /mnt/sysroot/etc/passwd nginx:x:0:0:root:/home/nginx:/bin/sh [root@host1 nginx]# vim /mnt/sysroot/etc/shadow nginx:$1$sdgsag$3AEIdl7KBstUNb7JOEoDX.:16303:0:99999:7:::
访问成功:
本文出自 “淡淡” 博客,请务必保留此出处http://dddbk.blog.51cto.com/6837943/1544880
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。