wiki:create_the_mini-linux
Just like creating the tiny version of FreeBSD, it is easy to create the mini-linux. First, download the latest linux kernel source package. Unpack it, and compile the new kernel. Second, download the latest busybox source package, unpack and compile it.
#!/bin/bash rm -f /tmp/ramdisk.imgrm /tmp/ramdisk.img.gz # Ramdisk size RDSIZE=8000 BLKSIZE=1024 # Create an empty ramdisk image dd if=/dev/zero of=/tmp/ramdisk.img bs=$BLKSIZE count=$RDSIZE # Make it an ext2 mountable file system /sbin/mke2fs -F -m 0 -b $BLKSIZE /tmp/ramdisk.img $RDSIZE
# Mount it mkdir -p /mnt/initrd mount /tmp/ramdisk.img /mnt/initrd -t ext2 -o loop=/dev/loop0
# Create directory tree mkdir /mnt/initrd/bin mkdir /mnt/initrd/sys mkdir /mnt/initrd/dev mkdir /mnt/initrd/proc mkdir /mnt/initrd/etc mkdir /mnt/initrd/var mkdir /mnt/initrd/tmp mkdir /mnt/initrd/www
# copy busybox and create the symbolic links cp $1 /mnt/initrd/bin/. cd /mnt/initrd/bin prg=`./busybox | grep -e "z" -e "," |grep -v -e 'Copy' | sed 's/,/ /g'` for i in $prg; do ln -s busybox $i done cd -
# create the necessary dev files cp -a /dev/console /mnt/initrd/dev cp -a /dev/ramdisk /mnt/initrd/dev cp -a /dev/ram0 /mnt/initrd/dev cp -a /dev/null /mnt/initrd/dev
# create link bin -> sbin cd /mnt/initrd ln -s bin sbin cd -
# extract the packages, etc, bin, lib and www tar cpf - ./etc | (cd /mnt/initrd; tar xpf -) tar cpf - ./bin | (cd /mnt/initrd; tar xpf -) tar cpf - ./lib | (cd /mnt/initrd; tar xpf -) tar cpf - ./www | (cd /mnt/initrd; tar xpf -)
# Create the linuxrc file cat >> /mnt/initrd/linuxrc << EOF #!/bin/sh echo mount -t proc /proc /proc mount sysfs -t sysfs /sys mount -t tmpfs -o size=1m none /tmp mount --remount,rw / mdev -s hostname NetClient httpd -h /www exec /bin/init EOF chmod +x /mnt/initrd/linuxrc
# Create the fstab file cat >> /mnt/initrd/etc/fstab << EOF /dev/ram0 / ext2 defaults 1 1 sysfs /sys sysfs defaults 0 0 EOF
# Done. umount /mnt/initrd gzip -9 /tmp/ramdisk.img cp -f /tmp/ramdisk.img.gz .
After creating ramdisk, move the kernel and ramdisk to tftpboot. Now the client can load the new kernel/ramdisk.
wiki/create_the_mini-linux.txt · Last modified: 2007/11/08 03:54 by mirnshi