构建自己的小linux
- # echo '
- >n
- >p
- >1
- >
- >+100M
- >w' | fdisk /dev/sdb &> /dev/null
- # echo '
- >n
- >p
- >2
- >
- >+512M
- >w' | fdisk /dev/sdb &> /dev/null
- # mkfs -t ext3 /dev/sdb1
- # mkfs -t ext3 /dev/sdb2
- # blkid /dev/sdb{1,2}
- # mkdir /mnt/{boot,sysroot}
- # mount /dev/sdb1 /mnt/boot
- # mount /dev/sdb2 /mnt/sysroot
- # partprobe /dev/sdb
- 1)grub-install --root-directory /mnt /dev/sdb
- 2)# mkdir /mnt/boot/grub
- # cp /usr/share/grub/i386-redhat/* /mnt/boot/grub
- # grub
- >root (hd1,0)
- >setup (hd1)
- >quit
- # cp /boot/vmlinuz-$(uname -r) /mnt/boot/vmlinuz
- # mkdir /tmp/initrd
- # cp /boot/initrd-$(uname -r).img /tmp/initrd
- # cd /tmp/initrd
- # file initrd-$(uname -r).img
- # mv initrd-$(uname -r).img ./initrd
- # gzip -d initrd
- # cpio -id < initrd
- # sed -i "s@/dev/vol0/root@/dev/sda2@g" init
- # rm -rf initrd
- # find . | cpio -o -H newc --quiet | gzip -9 > /mnt/boot/initrd.gz
- # vim /mnt/boot/grub/grub.conf
- default=0
- timeout=10
- title My Min Linux
- root (hd0,0)
- kernel /vmlinuz ro root=/dev/sda2 rhgb quiet
- initrd /initrd
- # cd /mnt/sysroot
- # mkdir -pv ./{bin,sbin,etc,dev,sys,proc,var,home,tmp,lib,mnt,media,misc,opt}
- # cp /sbin/init sbin/
- # cp /bin/{bash,ls,hostname} bin/
- #ldd {/sbin/init,/bin/bash}
- /sbin/init:
- linux-gate.so.1 => (0x0055a000)
- libsepol.so.1 => /lib/libsepol.so.1 (0x00573000)
- libselinux.so.1 => /lib/libselinux.so.1 (0x00110000)
- libc.so.6 => /lib/libc.so.6 (0x00825000)
- libdl.so.2 => /lib/libdl.so.2 (0x0096d000)
- /lib/ld-linux.so.2 (0x00802000)
- /bin/bash:
- linux-gate.so.1 => (0x0067e000)
- libtermcap.so.2 => /lib/libtermcap.so.2 (0x0099c000)
- libdl.so.2 => /lib/libdl.so.2 (0x0096d000)
- libc.so.6 => /lib/libc.so.6 (0x00825000)
- /lib/ld-linux.so.2 (0x00802000)
- /bin/ls:
- linux-gate.so.1 => (0x003cf000)
- librt.so.1 => /lib/librt.so.1 (0x009b5000)
- libacl.so.1 => /lib/libacl.so.1 (0x009c0000)
- libselinux.so.1 => /lib/libselinux.so.1 (0x00559000)
- libc.so.6 => /lib/libc.so.6 (0x00825000)
- libpthread.so.0 => /lib/libpthread.so.0 (0x0099c000)
- /lib/ld-linux.so.2 (0x00802000)
- libattr.so.1 => /lib/libattr.so.1 (0x0060e000)
- libdl.so.2 => /lib/libdl.so.2 (0x0096d000)
- libsepol.so.1 => /lib/libsepol.so.1 (0x00573000)
- /bin/hostname:
- linux-gate.so.1 => (0x00c83000)
- libselinux.so.1 => /lib/libselinux.so.1 (0x00559000)
- libc.so.6 => /lib/libc.so.6 (0x00825000)
- libdl.so.2 => /lib/libdl.so.2 (0x0096d000)
- libsepol.so.1 => /lib/libsepol.so.1 (0x00573000)
- /lib/ld-linux.so.2 (0x00802000)
- # cp /lib/{libsepol.so.1,libselinux.so.1,libc.so.6,libdl.so.2,ld-linux.so.2,libtermcap.so.2} lib/
- # cp /lib/{librt.so.1,libacl.so.1,libpthread.so.0,libattr.so.1} lib/
- # vim etc/inittab
- id:3:initdefault:
- si::sysinit:/etc/rc.d/rc.sysinit
- # vim etc/rc.d/rc.sysinit
- #!/bin/bash
- echo -e "\t Welcom to My Min Linux"
- /bin/bash
- # chmod +x etc/rc.d/rc.sysinit