Skip to content
systemcoding.dev
Embedded Linux

Generate Partitioned SD Card Images With wic

Turn a Yocto 5.0 image into a flashable SD card image with a boot and a root partition by setting WKS_FILE and IMAGE_FSTYPES for the wic tool.

6 min read
Summarize in AI
Flat illustration of a single-board computer with its SoC, memory, header and ports, with the Linux, Debian and NXP logos.

A root filesystem is not a bootable SD card. The card needs a partition table, a small FAT partition that the board's firmware can read, and the root filesystem in a second partition, all laid out at the offsets the boot ROM expects. The Yocto Project builds that whole disk image for you with a tool called wic (OpenEmbedded Image Creator). You describe the layout in a short kickstart file, switch on one image type, and the build writes a single file you can copy to a card. This post does that on Yocto Project 5.0 (Scarthgap) for a board that boots a kernel from a FAT partition, then checks the result with wic ls before anything touches real hardware.

Why a plain ext4 image is not enough

Yocto's default image types, such as ext4 or tar.gz, hold only a root filesystem. Writing one to a card gives you a card with no partition table and no boot partition, which no board will boot from. The Yocto Development Tasks Manual describes wic as the tool that creates partitioned images, and IMAGE_FSTYPES is where you ask for it by adding wic to the list.

The rest of the work is the kickstart file, a .wks file that wic reads. It lists the partitions in order, says what goes in each one, and names the partition table type.

Write the kickstart file

Create the file in your own layer, in a directory called wic. The build looks for kickstart files there, along with the canned ones that ship with the build system:

meta-mine/wic/sd-bootroot.wksText
part /boot --source bootimg-partition --ondisk mmcblk0 --fstype=vfat --label boot --active --align 4096 --size 32
part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --label root --align 4096
bootloader --ptable msdos

Each part line makes one partition. The first argument is the mount point recorded for it, and the options carry the detail. The kickstart reference in the Yocto manual defines them:

OptionMeaning
--source bootimg-partitionFills the partition from IMAGE_BOOT_FILES using a wic plugin
--source rootfsFills the partition from the image's root filesystem, sized to fit it
--ondisk mmcblk0The disk the partition belongs to, which also names the device in the image
--fstypeThe filesystem to create, here FAT for firmware and ext4 for root
--labelThe filesystem label
--activeMarks the partition bootable in an MSDOS table
--align 4096Aligns the partition start to 4096 KiB, which keeps it on an erase block boundary
--size 32Fixes the partition at 32 MiB, the default unit being MiB

The bootloader --ptable msdos line chooses the partition table. MSDOS suits boards whose boot ROM reads an MBR, and gpt is available for boards that want it. Because the root partition uses --source rootfs with no --size, wic makes it as large as the root filesystem needs, plus the image's overhead settings.

Tell the build what to put in the boot partition

bootimg-partition has no files of its own. It copies whatever IMAGE_BOOT_FILES lists from the deploy directory into the FAT partition. The Reference Manual shows the pattern IMAGE_BOOT_FILES = "u-boot.${UBOOT_SUFFIX} ${KERNEL_IMAGETYPE}", and a semicolon renames a file on the way in. For a board that loads a kernel image and a device tree directly:

conf/local.confbitbake
IMAGE_FSTYPES += "wic wic.bmap"
WKS_FILE = "sd-bootroot.wks"
IMAGE_BOOT_FILES = "${KERNEL_IMAGETYPE} ${KERNEL_DEVICETREE}"

WKS_FILE names the kickstart file, and without it the build uses a default that depends on the machine configuration. wic.bmap is a companion type that writes a block map next to the image, which the flashing tool uses to skip unused blocks. Here += is the right operator, because IMAGE_FSTYPES is meant to be extended and the manual says to use += rather than :append for it.

The exact contents of IMAGE_BOOT_FILES depend on your board. A Raspberry Pi layer, for example, lists firmware files and overlays from a deploy subdirectory, and a board with U-Boot lists u-boot.img and the boot script. Use the list your machine's layer documents, because a boot partition missing one file is the usual reason a card boots to a blank screen.

Build and locate the image

Shell
bitbake core-image-minimal
ls tmp/deploy/images/qemuarm64/*.wic*
Text
tmp/deploy/images/qemuarm64/core-image-minimal-qemuarm64.rootfs.wic
tmp/deploy/images/qemuarm64/core-image-minimal-qemuarm64.rootfs.wic.bmap

The file name is the image name, the machine and the .rootfs suffix, followed by the type, and a dated copy usually sits beside the symlink. Your machine name, and the dated companion files, will differ. The wic file is a raw disk image: sector 0 holds the partition table and the two partitions follow.

Inspect the layout before flashing

You do not have to write a card to find out whether the layout is right. wic ls lists the partitions in the image and wic ls image:1 lists the files in the first one. The manual's own example shows the format:

Shell
wic ls tmp/deploy/images/qemuarm64/core-image-minimal-qemuarm64.rootfs.wic
Text
Num     Start        End          Size      Fstype
 1       4194304     37748735     33554432  fat16
 2      37748736    112197631     74448896  ext4

Partition 1 starts at 4 MiB because of the 4096 KiB alignment, and its size matches the --size 32 request. Partition 2 starts at 36 MiB, the next 4 MiB boundary after the first partition ends. Your offsets and the root size follow your image, so read these values as an example. Then look inside the boot partition:

Shell
wic ls tmp/deploy/images/qemuarm64/core-image-minimal-qemuarm64.rootfs.wic:1
Text
Volume in drive : is boot
 Volume Serial Number is 7C21-4A9E
Directory for ::/

Image        20 471 296 2026-11-20  09:14
      1 file             20 471 296 bytes
                         13 017 088 bytes free

If this listing is missing the kernel, fix IMAGE_BOOT_FILES and rebuild. The manual notes that on some hosts wic ls fails with an error about sectors per track. The cure it gives is a line mtools_skip_check=1 in ~/.mtoolsrc, and the image itself is fine.

Flash it

Copy the image to the card with bmaptool, which uses the .bmap file to write only the blocks that matter. The manual says bmaptool is generally 10 to 20 times faster than dd:

Shell
sudo bmaptool copy tmp/deploy/images/qemuarm64/core-image-minimal-qemuarm64.rootfs.wic /dev/sdX

Replace /dev/sdX with the card's device and check it twice before pressing Enter, because the command overwrites whatever is there. If bmaptool is not installed, dd with bs=4M conv=fsync works and is slower, and the build can also run it for you from the build tree with oe-run-native bmaptool-native bmaptool copy as the manual shows.

When wic is not the right tool

wic fits boards that boot from an SD card or eMMC with a partition table the firmware understands. A board that boots from raw NAND needs UBI images, and a board that is booted entirely over the network needs only a kernel and an NFS root. A system with an A and B root and a persistent data partition needs a more elaborate kickstart, which a later post in this cluster writes. And if the layout must be generated by another tool, for example in a Buildroot or non-Yocto flow, the genimage tool covers the same ground there.

Share

Keep reading

Flat illustration of user space above the system call boundary, the kernel and the hardware, with the Linux, C and GNU logos.
Kernels

Write a Pin Controller Driver With pinctrl

Write a Linux 6.12 pin controller driver: pinctrl_desc, pins, groups and functions, the set_mux callback, and the device tree states that consumers select.

8 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.