how to boot ubuntu 16.04 with ramdisk - zhouyoujoin/ubuntu GitHub Wiki

I want to boot the ubuntu 16.04 from remote host to local ramdisk, since my booting device have none hard disk. Before this I already have the necessary files: kernel, initrd images, squashfs for ubuntu 16.04.

There are many ways to boot linux with kernel and initramfs, so all i need is to mount squashfs in a property way.

I assumpte that the squashfs can be treated like '/dev/sda1', in normal hard disk installation, the '/dev/sda1' is the root directory for ubuntu 16.04, this time I will using the squashfs like '/dev/sda1':

Step 1: make the squashfs a fake device like '/dev/sda1', first unzip the initrd.gz to directory 'initrd-root', and then move the squashfs into '/initrd-root/ramdev/sqram'.

Step 2: remake initrd.gz from 'initrd-root'.

Step 3: when booting from kernel and initrd.gz, pass the 'root=/ramdev/sqram' option to boot arguments.

The squash file system is read only, since I want my '/' be writable, I use the disk image to substitute it.

#Step1 - Prepare the disk image about 512MB for example
dd if=/dev/zero of=./rootfs bs=1024 count=524288

#Step2 - Attach disk images to loop device, and format it with ext4 file system
sudo losetup /dev/loop0 ./rootfs
sudo mkfs -t ext4 -m 1 -v /dev/loop0

#Step3 - Copy all squashfs files to disk image
sudo unsquashfs filesystem.squashfs
mkdir mnttmp
sudo mount /dev/loop0 mnttmp
sudo rsync -av squashfs-root/ mnttmp/

#Step4 - Cleanup
sudo umount mnttmp
rm -rf mnttmp
sudo losetup -d /dev/loop0
sudo rm -rf squashfs-root