[root@localhost linux-3.10.67]# make help ...(omitted) Configuration targets: ...(omitted) allnoconfig - New config where all options are answered with no ...(omitted)
这个allnoconfig就是我们要使用的选项.
1 2 3 4 5 6 7 8 9 10 11 12
[root@localhost linux-3.10.67]# make allnoconfig HOSTCC scripts/basic/fixdep HOSTCC scripts/kconfig/conf.o SHIPPED scripts/kconfig/zconf.tab.c SHIPPED scripts/kconfig/zconf.lex.c SHIPPED scripts/kconfig/zconf.hash.c HOSTCC scripts/kconfig/zconf.tab.o HOSTLD scripts/kconfig/conf scripts/kconfig/conf --allnoconfig Kconfig # # configuration written to .config #
[root@localhost ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xc4f29f1a. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command'c') and change display units to sectors (command'u').
Command (m forhelp): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1305, default 1): 1 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +100M
Command (m forhelp): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (15-1305, default 15): Using default value 15 Last cylinder, +cylinders or +size{K,M,G} (15-1305, default 1305): +2G
Command (m forhelp): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks.
[root@localhost ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 28112 inodes, 112420 blocks 5621 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 14 block groups 8192 blocks per group, 8192 fragments per group 2008 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729
This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@localhost ~]# mkfs.ext4 /dev/sdb2 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131648 inodes, 526128 blocks 26306 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=541065216 17 block groups 32768 blocks per group, 32768 fragments per group 7744 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
文件系统也OK了, 这样就可以开始挂载了.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@localhost ~]# mkdir /mnt/{boot,sysroot} [root@localhost ~]# mount /dev/sdb1 /mnt/boot/ [root@localhost ~]# grub-install --root-directory=/mnt /dev/sdb Probing devices to guess BIOS drives. This may take a long time. Installation finished. No error reported. This is the contents of the device map /mnt/boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. (fd0) /dev/fd0 (hd0) /dev/sda (hd1) /dev/sdb [root@localhost ~]# ls /mnt/boot/ grub lost+found [root@localhost ~]# mount /dev/sdb2 /mnt/sysroot/
建立引导完成. 我们现在把刚刚编译结束的内核拷贝过来:
1 2 3 4
[root@localhost ~]# cp -av /usr/src/linux-3.10.67/arch/x86/boot/bzImage /mnt/boot/bzImage `/usr/src/linux-3.10.67/arch/x86/boot/bzImage' -> `/mnt/boot/bzImage' [root@localhost ~]# file /mnt/boot/bzImage /mnt/boot/bzImage: Linux kernel x86 boot executable bzImage, version 3.10.67 (root@localhost.localdo, RO-rootFS, swap_dev 0x1, Normal VGA
[root@localhost sysroot]# mkdir -pv bin dev etc home lib lib64 media mnt proc root sbin sys tmp usr/{bin,sbin,lib,lib64} var/{log,run,lock} mkdir: created directory `bin' mkdir: created directory `dev' mkdir: created directory `etc' mkdir: created directory `home' mkdir: created directory `lib' mkdir: created directory `lib64' mkdir: created directory `media' mkdir: created directory `mnt' mkdir: created directory `proc' mkdir: created directory `root' mkdir: created directory `sbin' mkdir: created directory `sys' mkdir: created directory `tmp' mkdir: created directory `usr' mkdir: created directory `usr/bin' mkdir: created directory `usr/sbin' mkdir: created directory `usr/lib' mkdir: created directory `usr/lib64' mkdir: created directory `var' mkdir: created directory `var/log' mkdir: created directory `var/run' mkdir: created directory `var/lock'
#!/bin/bash # echo -e "\tWelcome to \033[32mMini Linux\033[0m" mount -n -t proc proc /proc mount -n -t sysfs sysfs /sys mount -n -o remount,rw /dev/sda2 / /bin/bash
再给他加几个程序:
1 2 3 4 5 6 7
[root@localhost sysroot]# bash ~/cp.sh A command:touch Another command? (enter quit to exit) mount Another command? (enter quit to exit) blkid Another command? (enter quit to exit) top Another command? (enter quit to exit) ps Another command? (enter quit to exit) quit
[root@localhost ~]# cd /mnt/sysroot/ [root@localhost sysroot]# ls bin dev etc home lib lib64 lost+found media mnt proc root sbin sys tmp usr var [root@localhost sysroot]# rm -rf ./* [root@localhost sysroot]# ls [root@localhost sysroot]#
编译完成了之后, 我们把所有的_install下的文件复制到/mnt/sysroot上去.
1
[root@localhost busybox-1.22.1]# cp -a ./_install/* /mnt/sysroot/
来确认一下:
1 2 3 4 5 6
[root@localhost sysroot]# ll total 12 drwxr-xr-x. 2 root root 4096 Oct 2 11:51 bin lrwxrwxrwx. 1 root root 11 Oct 2 11:51 linuxrc -> bin/busybox drwxr-xr-x. 2 root root 4096 Oct 2 11:51 sbin drwxr-xr-x. 4 root root 4096 Oct 2 11:51 usr
[root@localhost sysroot]# mkdir -pv tmp proc sys etc home root mnt media var lib lib64 dev boot mkdir: created directory `tmp' mkdir: created directory `proc' mkdir: created directory `sys' mkdir: created directory `etc' mkdir: created directory `home' mkdir: created directory `root' mkdir: created directory `mnt' mkdir: created directory `media' mkdir: created directory `var' mkdir: created directory `lib' mkdir: created directory `lib64' mkdir: created directory `dev' mkdir: created directory `boot'
[root@localhost ~]# chroot /mnt/sysroot/ /bin/sh / # adduser root adduser: /etc/passwd: No such file or directory / # touch /etc/passwd /etc/shadow /etc/group / # adduser root passwd: unknown uid 0 / # vim /etc/passwd /bin/sh: vim: not found / # vi /etc/passwd / # vi /etc/group / # # file shadow is a little difficult to handle...I choose to copy one line from the real root... / #