星期三, 6月 06, 2007

打造自己的 Floppy Linux

http://cha.homeip.net/blog/archives/2006/07/_floppy_linux.html

目的: 把 Linux 塞進 1.44MB 磁片中, 以該磁片開機後能透過網卡連上網路


環境:





建構 Linux kernel



cd /usr/src/linux


make mrproper


make menuconfig



下列項目以 kernel 2.4.32 為例, 不同版本的 kernel menu 排列順序不盡相同


取消以下項目 (按 'n')



Loadable module support:



Enable loadable module support



(以及任何你不想編入 kernel 的項目, 如: Sound Card,
PCMCIA...)



選擇以下項目 (按 'y')



Block devices:



Normal floppy disk support
RAM disk support
Initial RAM disk (initrd) support



File systems:



DOS FAT fs support

/proc file system support
Second extended fs support



Console drivers:



VGA text console



General setup:



Power Management support

ACPI Support



Networking options:



Packet socket

TCP/IP networking



Network device support →



Ethernet (10 or 100Mbit) →



EISA, VLB, PCI and on board controllers →



RealTek RTL-8139 PCI Fast Ethernet Adapter support



(以及其他任何你想編入 kernel 的項目)




make dep


make bzImage



建立 Busybox 工具指令集



cd /usr/local/src


wget
http://www.busybox.net/downloads/busybox-snapshot.tar.bz2


tar jxf busybox-snapshot.tar.bz2


cd busybox


vi ./init/init.c



#define INIT_SCRIPT "/etc/init.d/rcS" → "/etc/rc.d/rc.sysinit"



make menuconfig



選擇以下項目 (按 'y')



Busybox Settings → Build Options → Build BusyBox as a static binary


Init Utilities → init


Shells → Choose your default shell → ash


(以及任何想使用的指令, 如: ls, clear, telnet...)




make


make install



建立目錄環境



mkdir /floppy-linux


cd /floppy-linux


mkdir -p dev etc etc/rc.d proc mnt tmp var


chmod 755 dev etc etc/rc.d mnt tmp var


chmod 555 proc


vi ./etc/inittab



::sysinit:/etc/rc.d/rc.sysinit

::askfirst:/bin/sh



vi ./etc/fstab



proc /proc proc
defaults 0 0



vi ./etc/rc.d/rc.sysinit



#!/bin/sh


mount -a



chmod 644 ./etc/inittab ./etc/fstab


chmod 755 ./etc/rc.d/rc.sysinit


cd dev


mknod null c 1 3


mknod urandom c 1 9


mknod tty1 c 4 1


mknod tty5 c 4 5


mknod console c 5 1


mknod ram0 b 1 0


mknod fd0 b 2 0


chmod 666 *


chmod 600 fd0 ram0


cp -Rf /usr/local/src/busybox/_install/* /floppy-linux
把剛剛做好的 Busybox 工具程式環境複製進來


建立 udhcpc 環境 (讓 udhcpc
指令取得動態分配 IP)



wget

http://udhcp.busybox.net/downloads/snapshots/udhcp-snapshot.tar.bz2


tar jxf udhcp-snapshot.tar.bz2


mkdir -p /floppy-linux/usr/share/udhcpc


cp ./udhcp/samples/simple.script /floppy-linux/usr/share/udhcpc/default.script


chmod +x /floppy-linux/usr/share/udhcpc/default.script



如欲使用網路功能, 須在 kernel 加入網路設定與網卡 driver
(Networking options & Network device support), 並在 Busybox 選用網路指令



製作 ram disk image



mkdir /tmp/floppy-linux


vi /flimg_maker.sh



#!/bin/sh


dd if=/dev/zero of=/tmp/tmp_loop bs=1k count=2048

losetup /dev/loop0 /tmp/tmp_loop

mke2fs -m 0 /dev/loop0

mount -t ext2 /dev/loop0 /mnt

cp -a /floppy-linux/* /mnt

umount /mnt

losetup -d /dev/loop0

dd if=/tmp/tmp_loop gzip -9 > /tmp/floppy-linux/initrd.gz

rm -f /tmp/tmp_loop

sync



chmod +x /flimg_maker.sh


/flimg_maker.sh


日後若 /floppy-linux 目錄內容有所變更時, 只要執行 /flimg_maker.sh
即可重新製作 initrd.gz



整合所需檔案, 並檢查容量是否小於 1414 Blocks



cp /usr/src/linux/arch/i386/boot/bzImage /tmp/floppy-linux/linux


cp /tmp/initrd.gz /tmp/floppy-linux


du /tmp/floppy-linux


如果數字大於 1414 就要重新 make kernel, 儘量減少編入 kernel 的項目


可在 syslinux /dev/fd0 後, mount /dev/fd0 /mnt && df 即可查出磁片可用空間 (Available)
有多少 block


至少應預留 1 block 的空間給待會要建立的 syslinux.cfg



編輯 syslinux.cfg



vi /tmp/floppy-linux/syslinux.cfg



DEFAULT Linux

LABEL Linux

KERNEL linux

APPEND root=/dev/ram0 rw initrd=initrd.gz




將 syslinux boot loader 與剛剛完成的檔案載入磁片中



mkfs -t msdos /dev/fd0


syslinux /dev/fd0


mount /dev/fd0 /mnt


cp /tmp/floppy-linux/* /mnt


sync


完成後, 以該磁片開機即可





參考資料:



其他備忘:



Common block device





















































DeviceMajorMinor
hda30
hdb364
hdc220
hdd2264
sda80
sdb816
sdc832
sdd848
scd0110

ex. mknod /dev/hda1 b 3 1

沒有留言: