# Add contents to Rootfs

Instead of generating cpio and re-compiling kernel, we can generate rootfs and directly boot on to target

#### Pre-requisites: <a href="#repackrootfswithnewcontents-pre-requisites" id="repackrootfswithnewcontents-pre-requisites"></a>

* fakeroot
* mkimage
* pigz

```bash
#enter fake root, it will go into root shell without root prevelages
fakeroot
cd <any location>
 
#(Extract rootfs or use published rootfs)
cp -Pr <rootfs> ./

cd rootfs/
#(Add your contents)

#Create cpio file
find . | cpio -o -H newc > ../rootfs.cpio

#Add init to cpio file
#This init file override is very important.
echo ./init | cpio -oA -H newc -F ../rootfs.cpio
cd ../

#compress the cpio 
pigz -f -9 -n -c rootfs.cpio > rootfs.cpio.gz

#Create uboot readable image
mkimage -A arm64 -O linux -T ramdisk -C none -n rootfs -d rootfs.cpio.gz rootfs.cpio.gz.u-boot
```

* cpio\_append and init comes from yocto build for the corresponding architecture
* if we dont specify anything, init from host machine will be used resulting in x86 compatibility
