notes/Create Mini Linux System for Qemu Kernel Initrd-6h2K1Lz7.sh
#!/bin/bash
start=$PWD
initramfs=${start}/initramfs
ARCH="x86_64"
ARCH2="x86"
linux="linux-3.3"
lv="$(echo $linux|cut -d\- -f2|cut -d\. -f1)"
mkdir $initramfs
cd $initramfs
mkdir -pv bin lib dev etc mnt/root proc root sbin sys
mknod -m 666 dev/null c 1 3
mknod -m 666 dev/tty c 5 0
mknod -m 666 dev/zero c 1 5
mknod -m 666 dev/random c 1 8
echo "nameserver 8.8.8.8" > etc/resolv.conf
echo "search 8.8.8.8" >> etc/resolv.conf
#Create INIT startup script
cat << EOS > init
#!/bin/sh
mknod -m 666 dev/null c 1 3
mknod -m 666 dev/tty c 5 0
mknod -m 666 dev/zero c 1 5
mknod -m 666 dev/random c 1 8
/bin/mount -t proc none /proc
/bin/mount -t sysfs sysfs /sys
cat <<'EOF'
__ __ _ _ _ _
| \/ (_)_ __ (_) | | (_)_ __ _ ___ __
| |\/| | | '_ \| | | | | | '_ \| | | \ \/ /
| | | | | | | | | | |___| | | | | |_| |> <
|_| |_|_|_| |_|_| |_____|_|_| |_|\__,_/_/\_\
EOF
echo 'Enjoy your new mini system!'
/bin/sh
EOS
chmod 755 init
cd bin
wget -c "http://www.busybox.net/downloads/binaries/latest/busybox-$ARCH" -O busybox
chmod +x busybox
./busybox --help | \
sed -e '1,/^Currently defined functions:/d' \
-e 's/[ \t]//g' -e 's/,$//' -e 's/,/\n/g' | \
while read app ; do
if [ "$app" != "" ]; then
echo "linking ${app}..."
ln -sf "./busybox" "$app"
ls -ld "$app"
fi
done
cd $initramfs
find . -print0 | cpio --null -ov --format=newc > ../initrd.cpio
cd $start
wget -c "https://www.kernel.org/pub/linux/kernel/v${lv}.x/${linux}.tar.xz"
tar xf ${linux}.tar.xz
cd ${linux}
make allnoconfig
#make menuconfig
make
cp arch/$ARCH2/boot/bzImage $start
cd $start
qemu-system-$ARCH -kernel bzImage -initrd initrd.cpio
syntax highlighted by Code2HTML, v. 0.9.1