del %tmp%
mkdir %tmp%

copy %img%.krn %tmp%/rtr.krn
exec cd %tmp%/ ; cpio --quiet -H newc -i < %img%.cpio
copy ../misc/image/init.dsk %tmp%/init
copy ../misc/image/init.chr %tmp%/
exec chmod 755 %tmp%/init*

exec cd %tmp%/ ; find init* dev/ sys/ proc/ mnt/ run/ usr/ > filist
file-text %tmp%/filist
lib
lib32
lib64
bin
sbin
.

exec cd %tmp%/ ; cpio --quiet -H newc -O cpio -o <filist
del %tmp%/filist
exec zstd -9 %tmp%/cpio
move %tmp%/cpio.zst %tmp%/rtr.ird
del %tmp%/cpio
del %tmp%/lib/modules
copy ../misc/image/boot.sys %tmp%/syslinux.cfg

exec qemu-img create %img%.img 2G
exec /sbin/sfdisk -q %img%.img < ../misc/image/native.sfdsk
exec /sbin/mkfs.ext3 -q -d %tmp%/ -b 4096 -E offset=4194304 -F %img%.img 475000
exec dd bs=1 conv=notrunc if=/usr/lib/syslinux/mbr/mbr.bin of=%img%.img
exec dd bs=1K seek=1024 conv=notrunc if=%img%.flp of=%img%.img
exec guestfish -a %img%.img -m /dev/sda2 extlinux /

del %tmp%
