§2023-10-16
-
Creating Initramfs by Kiky Tokamuro
Initramfs, short for “initial RAM file system”, is the receiver of initrd (initial ramdisk). This is the cpio (copy in and out) archive of the source file system, which is loaded into memory during the Linux startup process. Linux copies the contents of the archive to rootfs (which can be based on ramfs or tmpfs), and then runs init. Init is designed to perform certain tasks before the real or final file system is installed on top of rootfs. Thus, initramfs should contain all the device drivers and tools needed to install the final root file system.
$ wget https://busybox.net/downloads/busybox-1.36.1.tar.bz2
$ cd ..
$ tar xvf ./src/busybox-1.36.1.tar.bz2
make defconfig and menuconfig
cd busybox-1.26.2
make defconfig
make menuconfig
- in
make menuconfig
- In the Busybox Settings menu
- select Build Options, and check the box next to Build BusyBox as a static binary (no shared libs).
- Next, specify the output folder for binaries and collect busybox:
- In the Busybox Settings menu
--- Build Options [*] Build static binary (no shared libs)
Destination path for 'make install' (./_install)
make
time make -j8
...
LINK busybox_unstripped
Static linking against glibc, can't use --gc-sections
Trying libraries: m resolv rt
Library m is needed, can't exclude it (yet)
Library resolv is needed, can't exclude it (yet)
Library rt is not needed, excluding it
Library m is needed, can't exclude it (yet)
Library resolv is needed, can't exclude it (yet)
Final link with: m resolv
real 0m31.466s
user 2m21.103s
sys 0m32.328s
make install
$ make install
...
./_install//usr/sbin/telnetd -> ../../bin/busybox
./_install//usr/sbin/tftpd -> ../../bin/busybox
./_install//usr/sbin/ubiattach -> ../../bin/busybox
./_install//usr/sbin/ubidetach -> ../../bin/busybox
./_install//usr/sbin/ubimkvol -> ../../bin/busybox
./_install//usr/sbin/ubirename -> ../../bin/busybox
./_install//usr/sbin/ubirmvol -> ../../bin/busybox
./_install//usr/sbin/ubirsvol -> ../../bin/busybox
./_install//usr/sbin/ubiupdatevol -> ../../bin/busybox
./_install//usr/sbin/udhcpd -> ../../bin/busybox
--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------
[alexlai@orgpi58G busybox-1.36.1]$ ls _install/
bin linuxrc sbin usr
make CONFIG_PREFIX=./../busybox_rootfs install
$ make CONFIG_PREFIX=./../busybox_rootfs install
...
./../busybox_rootfs//usr/sbin/ubirename -> ../../bin/busybox
./../busybox_rootfs//usr/sbin/ubirmvol -> ../../bin/busybox
./../busybox_rootfs//usr/sbin/ubirsvol -> ../../bin/busybox
./../busybox_rootfs//usr/sbin/ubiupdatevol -> ../../bin/busybox
./../busybox_rootfs//usr/sbin/udhcpd -> ../../bin/busybox
--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------
$ ls ../busybox_rootfs/
bin linuxrc sbin usr
Create a directory hierarchy for initramfs
[alexlai@orgpi58G build]$ pwd
/home/alexlai/build
[alexlai@orgpi58G build]$ cd initramfs/dev
[alexlai@orgpi58G dev]$ sudo mknod sda b 8 0
[sudo] password for alexlai:
[alexlai@orgpi58G dev]$ sudo mknod console c 5 1
[alexlai@orgpi58G dev]$ ls -l
total 0
crw-r--r-- 1 root root 5, 1 10月 16 16:02 console
brw-r--r-- 1 root root 8, 0 10月 16 16:02 sda