Yocto syslinux INITRD boot using a wic file - sipke/utils GitHub Wiki
Run a small footprint file system and boot it from syslinux as (or mimicing) an INITRD.
Utilise wic to generate a syslinux (pcbios) wic file which can be written onto a disk (usb or similar) to generate a boot partition with linux kernel (but no root file system) The root file system of your choice can then be copied onto this partition (after mounting).
When booting syslinux decompresses and copies the cpio onto a ram disk (ram0).
The open embedded class poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py is responsible for generating our wic file. If a bundled image (kernel and initramfs) is used, there is no need to use a custom syslinux configuration, but as we want an externally loaded image as our initramfs, we need to use the syslinux INITRD variable, which (as at yocto 4.2, Rocko) is not set in the bootimg-pcbios class. To do this we utilise a custom config file, which MUST be located in your layers top level wic/ directory.:
PROMPT 0 TIMEOUT 0 ALLOWOPTIONS 1 SERIAL 0 115200 DEFAULT boot LABEL boot KERNEL /vmlinuz INITRD /core-image-minimal.cpio.gz APPEND label=boot root=ram0 rw console=ttyS0,115200n8 loglevel=7
To generate the wic file we need (in the layers root wic/ directory) a mywic.wks.in file with the contents.:
part /boot --source bootimg-pcbios --sourceparams="initrd=${PN}-${MACHINE}.cpio.gz" --ondisk sda --label boot --active --align 1024 --size ${INITRAMFS_DISK_SIZE}
bootloader --configfile custom.syslinux.cfg
To ensure the wic is built along with your image, ensure to set WKS_FILE in your image recipe.
WKS_FILE = "mywic.wks.in"
Additionally as we want a cpio.gz we need to add the following to our image recipe (or a bbappend file).:
IMAGE_FSTYPES += "cpio.gz"
bitbake core-image-minimal sudo bmaptool copy tmp/deploy/images/mymachine/core-image-mymachine.wic /dev/sdb mkdir mnt sudo mount /dev/sdb1 mnt sudo cp tmp/deploy/images/mymachine/core-image-minimal-mymachine.cpio.gz mnt
On booting (assuming level 7 log info is in the syslinux append line) you will see the line:
Trying to unpack rootfs image as initramfs...
This will take a while (seconds) after which we get:
Freeing initrd memory: 195828K
Followed by hopefully a successful boot to a login: prompt.