Deploy and Run a System in a Ramdisk
If a machine should run the OS completely in memory without the need for any persistent storage, the approach to deploy the image into a ramdisk serves this purpose.
Note
brd support
For this functionality to work, brd (Block Ramdisk Driver) must be
supported. If brd is available as a kernel module (as opposed to
being compiled in the kernel), you must include the driver into the
initrd. To do this, create (or edit) the config.sh file and add
the following command to it:
echo 'add_drivers+=" brd "' > /etc/dracut.conf.d/10-brd.conf
KIWI NG allows you to create a bootable ISO image that deploys the image into a ramdisk and activates that image with the following oem type definition:
<type image="oem" filesystem="ext4" installiso="true" initrd_system="dracut" installboot="install" kernelcmdline="rd.kiwi.ramdisk">
<bootloader name="grub2" timeout="1"/>
<oemconfig>
<oem-skip-verify>true</oem-skip-verify>
<oem-unattended>true</oem-unattended>
<oem-unattended-id>/dev/ram1</oem-unattended-id>
<oem-swap>false</oem-swap>
<oem-multipath-scan>false</oem-multipath-scan>
<oem-ramdisk-size>2048000</oem-ramdisk-size>
</oemconfig>
</type>
The type specification above builds an installation ISO image
that deploys the System Image into the specified ramdisk
device (/dev/ram1). The setup of the ISO image boots with a
short boot timeout of 1 second and just runs through the process
without asking any questions. In a ramdisk deployment, the
optional target verification, swap space, and multipath targets
are out of scope and therefore disabled.
The configured size of the ramdisk via oem-ramdisk-size specifies
the kB size of the OS disk, and it must be at least of the size of the
System Image. The disk size can be configured dynamically with the
following value in the kernelcmdline attribute:
ramdisk_size=kbyte-value
An image built with the above setup can be tested in QEMU as follows:
$ sudo qemu -cdrom \
{exc_image_base_name}.x86_64-1.15.6.install.iso \
-serial stdio
Note
Enough Main Memory
The machine, no matter if it’s a virtual machine like QEMU
or a real machine, must provide enough RAM to hold the image
in the ramdisk as well as have enough RAM available to operate
the OS and its applications. The KIWI NG build image with the
extension .raw provides the System Image that gets deployed
into the RAM space. Subtract the size of the System Image
from the RAM space the machine offers and make sure the result
is still big enough for the use case of the appliance. In
the case of a virtual machine, attach enough main memory to fit
this calculation. In the case of QEMU, this can be done with
the -m option.
Like all other oem KIWI NG images, the ramdisk setup also supports all the deployment methods as explained in Deployment Methods. This means it’s also possible to dump the ISO image on a USB stick, let the system boot from it, and unplug the stick from the machine because the system was deployed into RAM.
Note
Limitations Of Ramdisk Deployments
Only standard images that can be booted by a simple root mount and root switch can be used. Usually, KIWI NG calls kexec after deployment such that the correct dracut initrd created for the image will boot the image. In the case of a RAM-only system, kexec does not work because it would lose the ramdisk contents. Thus, the dracut initrd driving the deployment is also the environment to boot the system. There are cases where this environment is not suitable to boot the system.