OS: Ubuntu 20.04 LTS
Linux Kernel: Version-6.5.7
BusyBox: Version-1.36.1
$ wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.5.7.tar.xz
$ tar -xvf linux-6.5.7.tar.xz
$ cd linux-6.5.7
$ make allnoconfig
This will create .config file setting values to 'n' as much as possible.
$ make menuconfig
This will open a window with many Linux kernel configuration settings. You can enable or disable those settings and customize the Linux kernel as needed.
Tips: use left, right, up and down arrow key to navigate
Now set following options-
Enable 64 support
General setup >> Default hostname
Set a Host name Embedded_linux
General Setup >> Initial RAM filesystem and RAM disk (initramfs/initrd) support
General Setup > Configure standard kernel features (expert users)
General Setup >kernel compression mode (Gzip)
Executable file formats > Kernel support for ELF binaries Executable file formats > Kernel support for scripts starting with #!
Device Driver > Generic Driver Options > Maintain a devtmpfs filesystem to mount at /dev
Device Driver > Generic Driver Options > Automount devtmpfs at /dev, after the kernel mounted the rootfs
Device Driver > Character devices > Enable TTY
Device Driver > Character devices > Serial Drivers > 8250/16550 and compatible serial support
Device Driver > Character devices > Serial Drivers > Console on 8250/16550 and compatible serial port
File systems > Pseudo filesystems > /proc file system support File systems > Pseudo filesystems > /sysfs file system support
Now, save and close the configuration window.
Here is the build command to build Linux kernel.
$ make -j4
Here make -j <number of cpu>
, it will take 1.28min for me.
To see how many CPU Core or How mane processor you have type:
$ nproc
Your Linux kernel is now ready and can be found in the linux-6.5.7/arch/x86/boot
directory.
$ cd linux-6.5.7/arch/x86/boot
$ ls -sh bzImage
Linux Kernel Size: 1.7MB
Create a working Directory and put the linux kernel image
$ mkdir -p ~/workspace_kernel/linux-kernel
$ cp linux-6.5.7/arch/x86/boot/bzImage ~/workspace_kernel/linux-kernel
Downloading latest Busybox
$ wget https://busybox.net/downloads/busybox-1.36.0.tar.bz2
cd to workspace directory
$ cd ~/workspace_kernel
extracting the Busybox source tree
$ tar -xvf busybox-1.36.0.tar.bz2
Cd to busybox
$ cd busybox-1.33.1
Customize busybox
$ make menuconfig
This will start configuration menu for BusyBox. We need only one setting.
Settings > Build static binary (no shared libs)
Now, exit and save.
It is time to build busybox.
Build
$ make -j4
$ make -j <number of CPU core>
To see how many CPU Core or How mane processor you have type:
$ nproc
More general command
$ make -j ${nproc}
Install
$ make install
This will install binaries in “./_install” directory
# another command to install busybox in user specific directory
$ make CONFIG_PREFIX=$PWD/woris install
Cd to workspace directory
$ cd ~/workspace_kernel
creating embedded_linux directory and cd to embedded_linux
$ mkdir embedded_linux && cd embedded_linux
Now Craete etc
, proc
, sys
and dev
directory.
$ mkdir -p etc proc sys dev
Coping all busybox installed files to ~/workspace_linux/embedded_linux
$ cp -a <busybox install dir>/_install/* .
Create init script in “embedded_linux” directory. This is the content of init script.
$ cd ~/workspace_kernel/embedded_linux
$ vim init
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
cat <<!
boot took $(cut -d' ' -f1 /proc/uptime) seconds
Welcome to EmbeddedCraft Mini Linux for Learners !!!
!
exec /bin/sh
It is time to make init file executable. Give executable permission to init file
$ chmod +x init
Creating initramfs as cpio archieve
$ find . -print0 | cpio --null -ov --format=newc | gzip -9 > initramfs.cpio.gz
Now the Directory structure look like
.
├── bin
├── dev
├── etc
├── init
├── initramfs.cpio.gz
├── linuxrc -> bin/busybox
├── proc
├── sbin
├── sys
└── usr
7 directories, 3 files
it is time to start QEMU and booting our mini Linux.
$ qemu-system-x86_64 \
-kernel <linux kernel dir>/arch/x86_64/boot/bzImage \
-initrd <busybox dir>/embedded_linux/initramfs.cpio.gz \
-append "init=/bin/sh console=ttyS0" -nographic -no-reboot
if you download the zip archive so the command look like
$ qemu-system-x86_64 \
-kernel linux_kernel/bzImage -initrd embedded_linux/initramfs.cpio.gz \
-append "init=/bin/sh console=ttyS0" -nographic
Here some Command you may try
$ uname -a
$ cat /proc/cpuinfo
$ top
$ ls
$ cd
$ mkdir
$ grep
$ find
# typelinux commands
To kill qemu open a new terminal and type
$ killall qemu-system-x86_64