SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
Launch the First Process in
Linux System
潘建宏 Jian-Hong Pan (StarNight)
@ COSCUP 2022
Who am I
潘建宏 / Jian-Hong Pan (StarNight)
Endless OS Foundation
You can find me at
● http://www.slideshare.net/chienhungpan/
● GitHub: starnight
● Email:
jhp [AT] endlessos.org
chienhung.pan [AT] gmail.com
Outline
● Linux kernel Boots
● The Init Process
● Busybox as the Init Process
● Build Busybox
● Boot on a QEMU aarch64 VM
○ Build a System Image
○ Have the Linux kernel
○ Boot the QEMU VM with the system image
● Boot on Raspberry Pi 3B
● Use Alpine’s Root Filesystem
● Reference
Linux Kernel Boots
Chip
x86(_64)
arm(64)
RISC-V
MIPS
…
Firmware
BIOS/UEFI
firmwares
…
Bootloader
GRUB
LILO
SYSLINUX
U-Boot
…
Kernel
Linux
(initramfs)
Init
PID 1
Build the Kernel
$ git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git linux-stable
$ cd linux-stable
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
Boot QEMU arm64 VM with an Empty Root Partition
$ qemu-system-aarch64 
-smp 2 
-M virt 
-cpu cortex-a57 
-m 1G 
-kernel ~/linux-stable/arch/arm64/boot/Image 
--append "console=ttyAMA0 root=/dev/vda2 rw rootfstype=ext4" 
-hda ~/qemu-images/simple-busybox.img 
-serial stdio
Linux Kernel Tries to Find init
…
[ 2.146201] Run /sbin/init as init process
[ 2.148061] Run /etc/init as init process
[ 2.149846] Run /bin/init as init process
[ 2.150521] Run /bin/sh as init process
[ 2.151871] Kernel panic - not syncing: No working init found. Try passing init=
option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.
…
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/init/main.c?h=v5.18#n1558
static int __ref kernel_init(void *unused)
{
int ret;
…
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
The Init Process
In Unix-based computer operating systems, init (short for initialization) is the first
process started during booting of the computer system. Init is a daemon process
that continues running until the system is shut down. ~ from init on Wiki
● SysVInit
● Upstart
● Systemd
● OpenRC
● …
● Busybox
Reference: Differences between SysVinit, Upstart and Systemd
Busybox as the Init Process
Busybox: The Swiss Army Knife of Embedded Linux
● BusyBox combines tiny versions of many common UNIX utilities into a single
small executable. It provides replacements for most of the utilities you usually
find in GNU fileutils, shellutils, etc.
● BusyBox provides a fairly complete environment for any small or embedded
system.
~ # ls -l /sbin/init
lrwxrwxrwx 1 root 0 14 Apr 5 14:39 /sbin/init -> ../bin/busybox
Build Busybox
$ git clone https://git.busybox.net/busybox
$ cd busybox
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- install
$ ls -l _install/
total 12
drwxr-xr-x 2 zack zack 4096 Jun 5 12:06 bin
lrwxrwxrwx 1 zack zack 11 Jun 5 12:06 linuxrc -> bin/busybox
drwxr-xr-x 2 zack zack 4096 Jun 5 12:06 sbin
drwxr-xr-x 4 zack zack 4096 Jun 5 12:06 usr
PS. When install Busybox into the root partition, have to set
CONFIG_PREFIX="<root partition mount path>"
Enable CONFIG_STATIC to
avoid shared libary issue
$ ls -l _install/sbin/
total 0
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 acpid -> ../bin/busybox
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 adjtimex -> ../bin/busybox
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 arp -> ../bin/busybox
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 blkid -> ../bin/busybox
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 blockdev -> ../bin/busybox
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 bootchartd -> ../bin/busybox
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 depmod -> ../bin/busybox
…
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 init -> ../bin/busybox
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 insmod -> ../bin/busybox
lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 ip -> ../bin/busybox
…
Boot on a QEMU aarch64 VM
Build a System Image (for QEMU VM)
1. Have a raw image
2. Format the raw image with designed partition layout
3. Mount the root partition
4. Install the built Busybox into the root partition
5. Prepare more fundamental folders/pathes into the root partition
6. Prepare config files for the init process into the root partition
7. Prepare config files for other processes into the root partition: Network,
DHCP, DNS …
8. Unmount the root partition
System Storage Layout
Boot Partition:
● Boot loader
● Kernel, Initial RAM disk, Device Tree Blobs
Root Partition:
● /boot
● /sbin, /bin
● /usr, /lib
● /etc
● /dev, /proc, /sys
● /root
● /tmp, /var, /mnt
● …
init
Prepare the Image and Partitions
$ dd if=/dev/zero of=~/qemu-images/simple-busybox.img bs=8M count=16
16+0 records in
16+0 records out
134217728 bytes (134 MB, 128 MiB) copied, 0.086382 s, 1.6 GB/s
$ fdisk -l ~/qemu-images/simple-busybox.img
Disk /home/zack/qemu-images/simple-busybox.img: 128 MiB, 134217728 bytes, 262144 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7ac31012
Device Boot Start End Sectors Size Id Type
/home/zack/qemu-images/simple-busybox.img1 * 2048 206847 204800 100M b W95 FAT32
/home/zack/qemu-images/simple-busybox.img2 206848 262143 55296 27M 83 Linux
# Some Linux distributions’ mkfs cannot be used in this way. Fallback to kpartx, then mkfs
$ mkfs.vfat -v --offset=2048 ~/qemu-images/simple-busybox.img $((100*1024*1024/1024))
$ mkfs.ext4 -E offset=$((512*206848)) ~/qemu-images/simple-busybox.img
Boot Partition
Root Partition
Mount Root Partition & Build a Root Filesystem
$ ROOTPART_PATH=/mnt
$ sudo mount -o offset=$((512*206848)) ~/qemu-images/simple-busybox.img $ROOTPART_PATH
$ cd ~/busybox && sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- install
$ sudo mkdir -p $ROOTPART_PATH/etc/init.d
$ sudo mkdir -p $ROOTPART_PATH/{proc, sys, dev, tmp, root, var, lib, mnt, boot}
$ ls $ROOTPART_PATH
bin boot dev etc lib linuxrc lost+found mnt proc root sbin sys tmp usr var
Reference:
● The Linux Bootdisk HOWTO - 4. Building a root filesystem
● rootfs 淺談 by Carl Su @COSCUP 2020
Install the /etc/inittab
$ sudo install ~/busybox/examples/inittab $ROOTPART_PATH/etc/inittab
● The QEMU VM need ttyAMA0::respawn:/sbin/getty -L 0 ttyAMA0 vt100 for
serial console.
● Disable "askfirst" shell on the console by commenting ::askfirst:-/bin/sh
Create the /etc/fstab
$ cat $ROOTPART_PATH/etc/fstab
# Begin /etc/fstab
# file system mount-point type options dump fsck
# order
/dev/vda2 / ext4 rw,relatime 0 0
/dev/vda1 /boot vfat rw,relatime 0 0
proc /proc proc nosuid,noexec,nodev 0 0
#sysfs /sys sysfs nosuid,noexec,nodev 0 0
#devpts /dev/pts devpts gid=5,mode=620 0 0
#tmpfs /run tmpfs defaults 0 0
#devtmpfs /dev devtmpfs mode=0755,nosuid 0 0
# End /etc/fstab
Have the Network
$ sudo install -d $ROOTPART_PATH/usr/share/udhcpc
$ sudo install ~/busybox/examples/udhcp/simple.script 
$ROOTPART_PATH/usr/share/udhcpc/default.script
$ echo "busybox-arm64" | sudo tee -a $ROOTPART_PATH/etc/hostname
The Initial Script
$ cat $ROOTPART_PATH/etc/init.d/rcS
#!/bin/sh
mount -a
ip link set eth0 up
udhcpc
hostname -F /etc/hostname
ntpd -n -q -p time.stdtime.gov.tw
$ sudo chmod +x $ROOTPART_PATH/etc/init.d/rcS
Create the Root
$ echo "root:x:0:0::/root:/bin/sh" | sudo tee -a $ROOTPART_PATH/etc/passwd
root:x:0:0::/root:/bin/sh
$ echo "root::18541::::::" | sudo tee -a $ROOTPART_PATH/etc/shadow
root::18541::::::
Boot the QEMU VM with the System Image
Unmount the $ROOTPART_PATH, before start the QEMU VM
$ qemu-system-aarch64 
-smp 2 
-M virt 
-cpu cortex-a57 
-m 1G 
-kernel ~/linux-stable/arch/arm64/boot/Image 
--append "console=ttyAMA0 root=/dev/vda2 rw rootfstype=ext4" 
-hda ~/qemu-images/simple-busybox.img 
-serial stdio
Get into the Real World
Raspberry Pi 3B for example
Boot on Raspberry Pi 3B
● Install Raspberry Pi’s boot firmware files from Raspberry Pi OS into the boot
partition.
● Prepare the config.txt and cmdline.txt into the boot partition.
● Install built kernel into the boot partition.
● Have interactive consoles by listing in /etc/inittab:
○ Have tty1::respawn:-/bin/sh for normal console
○ Have ::respawn:/sbin/getty -L ttyS1 115200 vt100 to replace the original
ttyAMA0 console. Becasue, Raspberry Pi 3B’s serial console is ttyS1.
● The mircro SD is mmcblk0 as the block. So, the boot partition is mmcblk0p1
and the root partition is mmcblk0p2.
● Tips: Add sleep 1 second before network interface “up” in /etc/init.d/rcS to
wait network devices becoming ready.
arch/arm/boot/dts/bcm2837-rpi-3-b.dts
/ {
compatible = "raspberrypi,3-model-b", "brcm,bcm2837";
model = "Raspberry Pi 3 Model B";
chosen {
/* 8250 auxiliary UART instead of pl011 */
stdout-path = "serial1:115200n8";
};
…
ttyS1
Use Alpine’s Root Filesystem
● Alpine is a lightweight Linux distribution based on musl libc and Busybox.
○ uses OpenRC as the init.
○ uses its own package manager called apk.
Build Alpine’s root filesystem
● Bootstrapping Alpine Linux with apk-tools-static to build root filesystem.
● Edit /etc/fstab for mounting.
● Edit /etc/inittab to get the serial console.
● Set network interface by editing /etc/network/interfaces. Also, enable the
networking service with rc-update add networking.
Detail: Build Alpine’s Root Filesystem (Bootstrap)
CI: https://github.com/starnight/build-image/blob/main/.github/workflows/image.yml
Reference
● QEMU ARM guest support
● Getting started with embedded-linux
● Linux Documentation/admin-guide/init.rst
● fdisk, mkfs.vfat, mkfs.ext4 and mount
● Busybox
● Alpine
● OpenRC and OpenRC Service Script Writing Guide
● The Linux Bootdisk HOWTO - 4. Building a root filesystem
● rootfs 淺談 by Carl Su @COSCUP 2020
● Bootstrapping Alpine Linux
● A Journey to Boot Linux on Raspberry Pi
Launch the First Process in Linux System

Mais conteúdo relacionado

Mais procurados

Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBshimosawa
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoCMacpaul Lin
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernelAdrian Huang
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabTaeung Song
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtAnne Nicolas
 
Linux Kernel Image
Linux Kernel ImageLinux Kernel Image
Linux Kernel Image艾鍗科技
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux KernelAdrian Huang
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in LinuxAdrian Huang
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Adrian Huang
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Ray Jenkins
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network InterfacesKernel TLV
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Jian-Hong Pan
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)Brendan Gregg
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)RuggedBoardGroup
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsLinaro
 
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedVmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedAdrian Huang
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequenceHoucheng Lin
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareBrendan Gregg
 

Mais procurados (20)

spinlock.pdf
spinlock.pdfspinlock.pdf
spinlock.pdf
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLab
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
 
Linux Kernel Image
Linux Kernel ImageLinux Kernel Image
Linux Kernel Image
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in Linux
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network Interfaces
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
Git undo
Git undoGit undo
Git undo
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedVmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of Software
 

Semelhante a Launch the First Process in Linux System

Development platform virtualization using qemu
Development platform virtualization using qemuDevelopment platform virtualization using qemu
Development platform virtualization using qemuPremjith Achemveettil
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratchjoshuasoundcloud
 
linux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixlinux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixSherif Mousa
 
How to make multi-boot USB drive for LiveCD iso images on EFI/UEFI and BIOS
 How to make multi-boot USB drive for LiveCD iso images on EFI/UEFI and BIOS How to make multi-boot USB drive for LiveCD iso images on EFI/UEFI and BIOS
How to make multi-boot USB drive for LiveCD iso images on EFI/UEFI and BIOSKentaro Hatori
 
A million ways to provision embedded linux devices
A million ways to provision embedded linux devicesA million ways to provision embedded linux devices
A million ways to provision embedded linux devicesMender.io
 
The origin: Init (compact version)
The origin: Init (compact version)The origin: Init (compact version)
The origin: Init (compact version)Tzung-Bi Shih
 
Embedded Linux Odp
Embedded Linux OdpEmbedded Linux Odp
Embedded Linux Odpghessler
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New HardwareRuggedBoardGroup
 
Relax and Recover on POWER (Updated 05-2017)
Relax and Recover on POWER (Updated 05-2017)Relax and Recover on POWER (Updated 05-2017)
Relax and Recover on POWER (Updated 05-2017)Sebastien Chabrolles
 
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !Pierre-jean Texier
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectYen-Chin Lee
 
BeagleBone Black: Platform Bring-Up with Upstream Components
BeagleBone Black: Platform Bring-Up with Upstream ComponentsBeagleBone Black: Platform Bring-Up with Upstream Components
BeagleBone Black: Platform Bring-Up with Upstream ComponentsGlobalLogic Ukraine
 
Description of GRUB 2
Description of GRUB 2Description of GRUB 2
Description of GRUB 2iamumr
 
Building Mini Embedded Linux System for X86 Arch
Building Mini Embedded Linux System for X86 ArchBuilding Mini Embedded Linux System for X86 Arch
Building Mini Embedded Linux System for X86 ArchSherif Mousa
 
Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Bud Siddhisena
 

Semelhante a Launch the First Process in Linux System (20)

Development platform virtualization using qemu
Development platform virtualization using qemuDevelopment platform virtualization using qemu
Development platform virtualization using qemu
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratch
 
linux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixlinux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrix
 
How to make multi-boot USB drive for LiveCD iso images on EFI/UEFI and BIOS
 How to make multi-boot USB drive for LiveCD iso images on EFI/UEFI and BIOS How to make multi-boot USB drive for LiveCD iso images on EFI/UEFI and BIOS
How to make multi-boot USB drive for LiveCD iso images on EFI/UEFI and BIOS
 
5. boot process
5. boot process5. boot process
5. boot process
 
A million ways to provision embedded linux devices
A million ways to provision embedded linux devicesA million ways to provision embedded linux devices
A million ways to provision embedded linux devices
 
Linux Booting Process
Linux Booting ProcessLinux Booting Process
Linux Booting Process
 
005 skyeye
005 skyeye005 skyeye
005 skyeye
 
How to build and load linux to embedded system
How to build and load linux to embedded systemHow to build and load linux to embedded system
How to build and load linux to embedded system
 
The origin: Init (compact version)
The origin: Init (compact version)The origin: Init (compact version)
The origin: Init (compact version)
 
Embedded Linux Odp
Embedded Linux OdpEmbedded Linux Odp
Embedded Linux Odp
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
Relax and Recover on POWER (Updated 05-2017)
Relax and Recover on POWER (Updated 05-2017)Relax and Recover on POWER (Updated 05-2017)
Relax and Recover on POWER (Updated 05-2017)
 
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto project
 
BeagleBone Black: Platform Bring-Up with Upstream Components
BeagleBone Black: Platform Bring-Up with Upstream ComponentsBeagleBone Black: Platform Bring-Up with Upstream Components
BeagleBone Black: Platform Bring-Up with Upstream Components
 
Description of GRUB 2
Description of GRUB 2Description of GRUB 2
Description of GRUB 2
 
Building Mini Embedded Linux System for X86 Arch
Building Mini Embedded Linux System for X86 ArchBuilding Mini Embedded Linux System for X86 Arch
Building Mini Embedded Linux System for X86 Arch
 
Os Bernier
Os BernierOs Bernier
Os Bernier
 
Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)
 

Mais de Jian-Hong Pan

國稅局,我也好想用電腦報稅
國稅局,我也好想用電腦報稅國稅局,我也好想用電腦報稅
國稅局,我也好想用電腦報稅Jian-Hong Pan
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardJian-Hong Pan
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Jian-Hong Pan
 
A Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiA Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiJian-Hong Pan
 
Have a Simple Modbus Server
Have a Simple Modbus ServerHave a Simple Modbus Server
Have a Simple Modbus ServerJian-Hong Pan
 
Software Packaging for Cross OS Distribution
Software Packaging for Cross OS DistributionSoftware Packaging for Cross OS Distribution
Software Packaging for Cross OS DistributionJian-Hong Pan
 
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!Jian-Hong Pan
 
LoRaWAN class module and subsystem
LoRaWAN class module and subsystemLoRaWAN class module and subsystem
LoRaWAN class module and subsystemJian-Hong Pan
 
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoTLet's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoTJian-Hong Pan
 
The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017Jian-Hong Pan
 
Build a Micro HTTP Server for Embedded System
Build a Micro HTTP Server for Embedded SystemBuild a Micro HTTP Server for Embedded System
Build a Micro HTTP Server for Embedded SystemJian-Hong Pan
 
Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016Jian-Hong Pan
 
Bind Python and C @ COSCUP 2015
Bind Python and C @ COSCUP 2015Bind Python and C @ COSCUP 2015
Bind Python and C @ COSCUP 2015Jian-Hong Pan
 
Find the bottleneck of your system
Find the bottleneck of your systemFind the bottleneck of your system
Find the bottleneck of your systemJian-Hong Pan
 
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDevLearn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDevJian-Hong Pan
 
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code MeetupDebug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code MeetupJian-Hong Pan
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevJian-Hong Pan
 
The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014Jian-Hong Pan
 

Mais de Jian-Hong Pan (19)

國稅局,我也好想用電腦報稅
國稅局,我也好想用電腦報稅國稅局,我也好想用電腦報稅
國稅局,我也好想用電腦報稅
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
 
A Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiA Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry Pi
 
Have a Simple Modbus Server
Have a Simple Modbus ServerHave a Simple Modbus Server
Have a Simple Modbus Server
 
Software Packaging for Cross OS Distribution
Software Packaging for Cross OS DistributionSoftware Packaging for Cross OS Distribution
Software Packaging for Cross OS Distribution
 
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
 
LoRaWAN class module and subsystem
LoRaWAN class module and subsystemLoRaWAN class module and subsystem
LoRaWAN class module and subsystem
 
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoTLet's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
 
The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017
 
Build a Micro HTTP Server for Embedded System
Build a Micro HTTP Server for Embedded SystemBuild a Micro HTTP Server for Embedded System
Build a Micro HTTP Server for Embedded System
 
Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016
 
Bind Python and C @ COSCUP 2015
Bind Python and C @ COSCUP 2015Bind Python and C @ COSCUP 2015
Bind Python and C @ COSCUP 2015
 
Find the bottleneck of your system
Find the bottleneck of your systemFind the bottleneck of your system
Find the bottleneck of your system
 
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDevLearn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
 
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code MeetupDebug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
 
The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 

Último

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Último (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Launch the First Process in Linux System

  • 1. Launch the First Process in Linux System 潘建宏 Jian-Hong Pan (StarNight) @ COSCUP 2022
  • 2. Who am I 潘建宏 / Jian-Hong Pan (StarNight) Endless OS Foundation You can find me at ● http://www.slideshare.net/chienhungpan/ ● GitHub: starnight ● Email: jhp [AT] endlessos.org chienhung.pan [AT] gmail.com
  • 3. Outline ● Linux kernel Boots ● The Init Process ● Busybox as the Init Process ● Build Busybox ● Boot on a QEMU aarch64 VM ○ Build a System Image ○ Have the Linux kernel ○ Boot the QEMU VM with the system image ● Boot on Raspberry Pi 3B ● Use Alpine’s Root Filesystem ● Reference
  • 5. Build the Kernel $ git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git linux-stable $ cd linux-stable $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
  • 6. Boot QEMU arm64 VM with an Empty Root Partition $ qemu-system-aarch64 -smp 2 -M virt -cpu cortex-a57 -m 1G -kernel ~/linux-stable/arch/arm64/boot/Image --append "console=ttyAMA0 root=/dev/vda2 rw rootfstype=ext4" -hda ~/qemu-images/simple-busybox.img -serial stdio
  • 7. Linux Kernel Tries to Find init … [ 2.146201] Run /sbin/init as init process [ 2.148061] Run /etc/init as init process [ 2.149846] Run /bin/init as init process [ 2.150521] Run /bin/sh as init process [ 2.151871] Kernel panic - not syncing: No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance. …
  • 8. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/init/main.c?h=v5.18#n1558 static int __ref kernel_init(void *unused) { int ret; … if (!try_to_run_init_process("/sbin/init") || !try_to_run_init_process("/etc/init") || !try_to_run_init_process("/bin/init") || !try_to_run_init_process("/bin/sh")) return 0; panic("No working init found. Try passing init= option to kernel. " "See Linux Documentation/admin-guide/init.rst for guidance."); }
  • 9. The Init Process In Unix-based computer operating systems, init (short for initialization) is the first process started during booting of the computer system. Init is a daemon process that continues running until the system is shut down. ~ from init on Wiki ● SysVInit ● Upstart ● Systemd ● OpenRC ● … ● Busybox Reference: Differences between SysVinit, Upstart and Systemd
  • 10.
  • 11.
  • 12. Busybox as the Init Process Busybox: The Swiss Army Knife of Embedded Linux ● BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. ● BusyBox provides a fairly complete environment for any small or embedded system. ~ # ls -l /sbin/init lrwxrwxrwx 1 root 0 14 Apr 5 14:39 /sbin/init -> ../bin/busybox
  • 13. Build Busybox $ git clone https://git.busybox.net/busybox $ cd busybox $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- install $ ls -l _install/ total 12 drwxr-xr-x 2 zack zack 4096 Jun 5 12:06 bin lrwxrwxrwx 1 zack zack 11 Jun 5 12:06 linuxrc -> bin/busybox drwxr-xr-x 2 zack zack 4096 Jun 5 12:06 sbin drwxr-xr-x 4 zack zack 4096 Jun 5 12:06 usr PS. When install Busybox into the root partition, have to set CONFIG_PREFIX="<root partition mount path>" Enable CONFIG_STATIC to avoid shared libary issue
  • 14. $ ls -l _install/sbin/ total 0 lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 acpid -> ../bin/busybox lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 adjtimex -> ../bin/busybox lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 arp -> ../bin/busybox lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 blkid -> ../bin/busybox lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 blockdev -> ../bin/busybox lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 bootchartd -> ../bin/busybox lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 depmod -> ../bin/busybox … lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 init -> ../bin/busybox lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 insmod -> ../bin/busybox lrwxrwxrwx 1 zack zack 14 Apr 5 20:38 ip -> ../bin/busybox …
  • 15. Boot on a QEMU aarch64 VM
  • 16. Build a System Image (for QEMU VM) 1. Have a raw image 2. Format the raw image with designed partition layout 3. Mount the root partition 4. Install the built Busybox into the root partition 5. Prepare more fundamental folders/pathes into the root partition 6. Prepare config files for the init process into the root partition 7. Prepare config files for other processes into the root partition: Network, DHCP, DNS … 8. Unmount the root partition
  • 17. System Storage Layout Boot Partition: ● Boot loader ● Kernel, Initial RAM disk, Device Tree Blobs Root Partition: ● /boot ● /sbin, /bin ● /usr, /lib ● /etc ● /dev, /proc, /sys ● /root ● /tmp, /var, /mnt ● … init
  • 18. Prepare the Image and Partitions $ dd if=/dev/zero of=~/qemu-images/simple-busybox.img bs=8M count=16 16+0 records in 16+0 records out 134217728 bytes (134 MB, 128 MiB) copied, 0.086382 s, 1.6 GB/s $ fdisk -l ~/qemu-images/simple-busybox.img Disk /home/zack/qemu-images/simple-busybox.img: 128 MiB, 134217728 bytes, 262144 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x7ac31012 Device Boot Start End Sectors Size Id Type /home/zack/qemu-images/simple-busybox.img1 * 2048 206847 204800 100M b W95 FAT32 /home/zack/qemu-images/simple-busybox.img2 206848 262143 55296 27M 83 Linux # Some Linux distributions’ mkfs cannot be used in this way. Fallback to kpartx, then mkfs $ mkfs.vfat -v --offset=2048 ~/qemu-images/simple-busybox.img $((100*1024*1024/1024)) $ mkfs.ext4 -E offset=$((512*206848)) ~/qemu-images/simple-busybox.img Boot Partition Root Partition
  • 19. Mount Root Partition & Build a Root Filesystem $ ROOTPART_PATH=/mnt $ sudo mount -o offset=$((512*206848)) ~/qemu-images/simple-busybox.img $ROOTPART_PATH $ cd ~/busybox && sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- install $ sudo mkdir -p $ROOTPART_PATH/etc/init.d $ sudo mkdir -p $ROOTPART_PATH/{proc, sys, dev, tmp, root, var, lib, mnt, boot} $ ls $ROOTPART_PATH bin boot dev etc lib linuxrc lost+found mnt proc root sbin sys tmp usr var Reference: ● The Linux Bootdisk HOWTO - 4. Building a root filesystem ● rootfs 淺談 by Carl Su @COSCUP 2020
  • 20. Install the /etc/inittab $ sudo install ~/busybox/examples/inittab $ROOTPART_PATH/etc/inittab ● The QEMU VM need ttyAMA0::respawn:/sbin/getty -L 0 ttyAMA0 vt100 for serial console. ● Disable "askfirst" shell on the console by commenting ::askfirst:-/bin/sh
  • 21. Create the /etc/fstab $ cat $ROOTPART_PATH/etc/fstab # Begin /etc/fstab # file system mount-point type options dump fsck # order /dev/vda2 / ext4 rw,relatime 0 0 /dev/vda1 /boot vfat rw,relatime 0 0 proc /proc proc nosuid,noexec,nodev 0 0 #sysfs /sys sysfs nosuid,noexec,nodev 0 0 #devpts /dev/pts devpts gid=5,mode=620 0 0 #tmpfs /run tmpfs defaults 0 0 #devtmpfs /dev devtmpfs mode=0755,nosuid 0 0 # End /etc/fstab
  • 22. Have the Network $ sudo install -d $ROOTPART_PATH/usr/share/udhcpc $ sudo install ~/busybox/examples/udhcp/simple.script $ROOTPART_PATH/usr/share/udhcpc/default.script $ echo "busybox-arm64" | sudo tee -a $ROOTPART_PATH/etc/hostname
  • 23. The Initial Script $ cat $ROOTPART_PATH/etc/init.d/rcS #!/bin/sh mount -a ip link set eth0 up udhcpc hostname -F /etc/hostname ntpd -n -q -p time.stdtime.gov.tw $ sudo chmod +x $ROOTPART_PATH/etc/init.d/rcS
  • 24. Create the Root $ echo "root:x:0:0::/root:/bin/sh" | sudo tee -a $ROOTPART_PATH/etc/passwd root:x:0:0::/root:/bin/sh $ echo "root::18541::::::" | sudo tee -a $ROOTPART_PATH/etc/shadow root::18541::::::
  • 25. Boot the QEMU VM with the System Image Unmount the $ROOTPART_PATH, before start the QEMU VM $ qemu-system-aarch64 -smp 2 -M virt -cpu cortex-a57 -m 1G -kernel ~/linux-stable/arch/arm64/boot/Image --append "console=ttyAMA0 root=/dev/vda2 rw rootfstype=ext4" -hda ~/qemu-images/simple-busybox.img -serial stdio
  • 26. Get into the Real World Raspberry Pi 3B for example
  • 27. Boot on Raspberry Pi 3B ● Install Raspberry Pi’s boot firmware files from Raspberry Pi OS into the boot partition. ● Prepare the config.txt and cmdline.txt into the boot partition. ● Install built kernel into the boot partition. ● Have interactive consoles by listing in /etc/inittab: ○ Have tty1::respawn:-/bin/sh for normal console ○ Have ::respawn:/sbin/getty -L ttyS1 115200 vt100 to replace the original ttyAMA0 console. Becasue, Raspberry Pi 3B’s serial console is ttyS1. ● The mircro SD is mmcblk0 as the block. So, the boot partition is mmcblk0p1 and the root partition is mmcblk0p2. ● Tips: Add sleep 1 second before network interface “up” in /etc/init.d/rcS to wait network devices becoming ready.
  • 28. arch/arm/boot/dts/bcm2837-rpi-3-b.dts / { compatible = "raspberrypi,3-model-b", "brcm,bcm2837"; model = "Raspberry Pi 3 Model B"; chosen { /* 8250 auxiliary UART instead of pl011 */ stdout-path = "serial1:115200n8"; }; … ttyS1
  • 29. Use Alpine’s Root Filesystem ● Alpine is a lightweight Linux distribution based on musl libc and Busybox. ○ uses OpenRC as the init. ○ uses its own package manager called apk. Build Alpine’s root filesystem ● Bootstrapping Alpine Linux with apk-tools-static to build root filesystem. ● Edit /etc/fstab for mounting. ● Edit /etc/inittab to get the serial console. ● Set network interface by editing /etc/network/interfaces. Also, enable the networking service with rc-update add networking. Detail: Build Alpine’s Root Filesystem (Bootstrap) CI: https://github.com/starnight/build-image/blob/main/.github/workflows/image.yml
  • 30. Reference ● QEMU ARM guest support ● Getting started with embedded-linux ● Linux Documentation/admin-guide/init.rst ● fdisk, mkfs.vfat, mkfs.ext4 and mount ● Busybox ● Alpine ● OpenRC and OpenRC Service Script Writing Guide ● The Linux Bootdisk HOWTO - 4. Building a root filesystem ● rootfs 淺談 by Carl Su @COSCUP 2020 ● Bootstrapping Alpine Linux ● A Journey to Boot Linux on Raspberry Pi