系統 - Debian - Kernel - Make initramfs



Busybox

$ cd
$ git clone https://git.busybox.net/busybox
$ cd busybox
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make distclean
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make menuconfig
    Settings  --->
        [*] Build static binary (no shared libs)

$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make -j4

$ rm -rf initramfs
$ mkdir -p initramfs
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make CONFIG_PREFIX=$PWD/initramfs install
$ cd initramfs
$ mkdir dev sys proc
$ sudo mknod dev/console c 5 1
$ sudo mknod dev/null c 1 3
$ vim init
    #!/bin/sh
    mount -t devtmpfs devtmpfs /dev
    mount -t proc proc /proc
    mount -t sysfs sysfs /sys
    echo
    echo "================================"
    echo " BusyBox initramfs"
    echo "================================"
    echo
    exec setsid cttyhack /bin/sh </dev/ttyS0 >/dev/ttyS0 2>&1

$ chmod 755 init
$ find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../initramfs.cpio.gz
$ file ../initramfs.cpio.gz 
    ../initramfs.cpio.gz: gzip compressed data, max compression, from Unix, original size modulo 2^32 1579008

Kernel

CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="/xxx/initramfs.cpio.gz"
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
CONFIG_CMDLINE="console=ttyS0,115200 rdinit=/init"

開機的訊息

================================
 BusyBox initramfs
================================

~ #