Create a bootable image with minimal configuration

2023-12-05 03:31:09 | English, Korean

Translated with the help of ChatGPT and Google Translator

I happened to create a Linux image myself. Actually, I'm planning to use Yocto, but before that, I was curious about how to create a minimal bootable image, so I looked it up.

Make Minimal Bootable Disk

The Linux booting process is quite complicated, but to summarize, it is as follows.

  1. After the BIOS or UEFI performs various initializations, it searches for a bootable disk.
  2. If a boot loader is found in the MBR section of a bootable disk or the EFI partition of a GPT, run the boot loader.
  3. The bootloader loads the initramfs and kernel.
  4. The kernel performs various initialization including memory management.
  5. Afterwards, run the init process specified in initramfs.
  6. The init process mounts the root file system and runs the necessary services.

Therefore, to create a minimal bootable image you will need the following:


1. Linux Kernel

  1. Download and build the kernel. At this time, the config file created by default may not work for general purposes, so it is recommended to use the config file provided by Ubuntu, etc.
    • If you are using Ubuntu, etc., you can find the file with the /boot/config-$(uname -r) command.
    • Credential problems may occur. In that case, please refer to the link below.
      • https://askubuntu.com/questions/1329538/compiling-the-kernel-5-11-11/1329625#1329625
  2. The kernel is created in arch/x86/boot/bzImage. (based on x86 architecture)

2. Initramfs

  1. Download busybox to create initramfs.
    • git clone git://busybox.net/busybox.git
  2. Build busybox using make.
    • make defconfig
    • make
  3. Create an initramfs using the make install command. An initramfs is created in the _install directory.
  4. Add the following init script to the _install directory.
    mount -t proc none /proc
    mount -t sysfs none /sys
    mount -t devtmpfs none /dev
    exec /bin/sh
  5. Make the init script executable using the chmod +x init command.
  6. In the _install directory, find. -print0 | cpio --null -ov --format=newc | Create an initramfs using the gzip -9 > ../../initramfs.cpio.gz command.

3. Bootloader

  1. Prepare a blank disk and create an EFI partition using the fdisk command.
    • Be careful not to format the host disk.
    • Since the goal is to create a minimal bootable image, no remaining partitions will be created.
  2. Format the EFI partition as FAT32 using the command mkfs.fat -F 32 /dev/sdXy.
  3. Mount the EFI partition using the mount /dev/sdXy /mnt command.
  4. Copy the kernel and initramfs to the boot directory on the EFI partition. (e.g. /mnt/boot)
  5. Install GRUB using the grub-install --boot-directory=/mnt/boot --efi-directory=/mnt /dev/sdX command.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -