The program is presented , which allows users to create bootable initrd images, ISO files, or storage devices with any GNU/Linux distribution with a single command. The code is written in POSIX shell and under the GPLv3 license.
All distributions booted using Booty run either in SHMFS (tmpfs) or in SquashFS + Overlay FS, depending on user selection. The distribution is created once, while boot options allow for the use of a clean tmpfs as the root, or a combination of Overlay FS + SquashFS with changes written to tmpfs. There is an option to pre-copy the bootable distribution into RAM, allowing the USB flash drive to be disconnected after loading and copying the distribution into memory.
First of all, Booty generates its own initrd image, which can use the native utilities from the current system or busybox. It is possible to include (pack) an entire distribution installed in a directory into the initramfs (chroot). This can be useful when it is necessary to update the system using kexec: simply reboot initrd with a new kernel and new system inside the initrd.
Creating a Booty-specific initrd image:
mkdir initramfs/
mkinitramfs initramfs/ —output initrd
Creating an initrd image that includes a distribution from the directory 'gentoo/':
mkdir initramfs/
mkinitramfs initramfs/ —overlay gentoo/ —cpio —output initrd
After which this initrd image is fully ready for booting, for example, via PXE or through kexec.
Next, Booty generates images with the system specified as 'overlays'. For example, you can install (unpack an archive) a hypothetical Gentoo in a separate directory, after which Booty will generate a cpio archive or SquashFS image with that system. You can also configure the distribution in a separate directory, and copy personal settings into yet another directory. All these 'layers' will be sequentially loaded on top of each other to create a unified working system.
mkdir initramfs/
mkinitramfs initramfs/ —overlay gentoo/ —overlay settings/ —overlay documents/ —squashfs —output initrd
Ultimately, Booty allows the creation of bootable ISO images and USB, HDD, SSD, and other storage devices, installing the aforementioned system from the images. Supports the creation of bootable systems for BIOS and UEFI. Bootloaders GRUB2 and SYSLINUX are supported. Bootloaders can be combined; for example, use SYSLINUX for BIOS and GRUB2 for UEFI. To create ISO images, the cdrkit package (genisoimage) or xorriso (xorrisofs) will be needed, depending on your choice.
The only additional action required is to prepare the kernel (vmlinuz) for booting in advance. The author (Spoofing) recommends using 'make defconfig'. Before creating the image, you need to prepare a directory, placing the vmlinuz kernel and a pre-prepared 'empty' initrd created in the first example into it.
mkdir iso/
cp /boot/vmlinuz-* iso/boot/vmlinuz
cp initrd iso/boot/initrd
The preparation is complete; now we can create ISO images from this directory.
The following command will create an ISO image, which is non-bootable, just an ISO:
mkdir iso/
mkbootisofs iso/ —output archive.iso
To create a bootable image, you need to specify the '--legacy-boot' option for BIOS and '--efi' for UEFI, respectively. The options can accept either grub2 or syslinux; you can also specify just one option (for example, if UEFI boot support is not needed, you can omit it).
mkbootisofs iso/ —legacy-boot syslinux —output boot-biosonly.iso
mkbootisofs iso/ —legacy-boot syslinux —efi grub2 —output boot-bios-uefi.iso
mkbootisofs iso/ —efi grub2 —output boot-uefionly.iso
And just as images with the system were included in initrd earlier, they can be included in the ISO.
mkbootisofs iso/ —overlay gentoo/ —squashfs —legacy-boot grub2 —efi grub2 —output gentoo.iso
After this command, a bootable BIOS/UEFI ISO image will be created, booting Gentoo from the SquashFS image using Overlay FS, which uses tmpfs for data storage. The kernel must be compiled with support for Overlay FS with SquashFS. However, if this is not needed for some reason, you can use the '--cpio' option instead of --squashfs to pack gentoo/ as a cpio archive; in this case, the archive will be unpacked directly into tmpfs at boot time, as long as there is enough RAM to unpack the system into tmpfs.
Interesting fact: if an ISO image created using the '--efi' option is unpacked onto a FAT32 flash drive by simply copying the files (cp -r), the flash drive will boot in UEFI mode without any prior preparation, thanks to the specifics of UEFI bootloaders.
In addition to bootable ISOs with the same parameters, any bootable drive can be created: USB, HDD, SSD, and so on, while this drive can continue to be used for its intended purpose. To do this, it is necessary to mount, for example, the USB device and execute mkbootisofs on it. Just add one option "--bootable" so that the drive containing the specified directory becomes bootable.
mount /dev/sdb1 /mnt
mkbootisofs /mnt --overlay gentoo/ --squashfs --legacy-boot grub2 --efi grub2 --bootable
After this, the USB device will become bootable with the overlay gentoo/ (don’t forget to copy the files /boot/vmlinuz and /boot/initrd to the device).
If for any reason the drive was not mounted to /mnt, and it turns out that /mnt is on the main device /dev/sda, then the bootloader will be overwritten to /dev/sda. Care should be taken when specifying the --bootable option.
During booting, Booty supports several options that can be specified in the bootloader, grub.cfg or syslinux.cfg. By default, without any options, it boots and unpacks all overlays into tmpfs (default option ooty.use-shmfs). To use Overlay FS, the option booty.use-overlayfs must be used. The option booty.copy-to-ram first copies the overlays to tmpfs, then mounts and loads them. After copying, the USB device (or another drive) can be removed.
Source: opennet.ru
