booty - a utility for creating bootable images and drives

Program introduced Booty, which allows you to create bootable initrd images, ISO files, or drives that include any GNU/Linux distribution with a single command. The code is written in POSIX shell and spreads licensed under GPLv3.

All distributions loaded using Booty run in either SHMFS (tmpfs) or SquashFS + Overlay FS, the user's choice. The distribution kit is created once, and during the boot process, parameters are selected that allow using pure tmpfs for the root, or a bunch of Overlay FS + SquashFS with writing changes to tmpfs. It is possible to pre-copy the boot distribution to RAM, which allows you to disable the USB drive after downloading and copying the distribution to memory.

First of all, Booty generates its own initrd image, which can use native utilities from the current system or busybox. It is possible to include (pack) the entire distribution kit installed in the directory (chroot) into the initramfs. This can be useful when you need to upgrade your system using kexec: just reload the initrd with the new kernel and the new system inside the initrd.

Creating a booty-specific initrd image:

mkdir initramfs/
mkinitramfs initramfs/ --output initrd

Create an initrd image to include the distribution from the "gentoo/" directory:

mkdir initramfs/
mkinitramfs initramfs/ --overlay gentoo/ --cpio --output initrd

After that, this initrd image is completely ready for boot, for example, via PXE or via kexec.

Next, Booty generates images with the system that is listed as "overlays". For example, you can install (unpack the archive) a conditional Gentoo in a separate directory, after which a cpio-archive or SquashFS image with this system will be generated using Booty. You can also configure the distribution kit in a separate directory, and copy personal settings to another directory. All these "layers" will be sequentially loaded on top of each other and create a single working system.

mkdir initramfs/
mkinitramfs initramfs/ --overlay gentoo/ --overlay settings/ --overlay documents/ --squashfs --output initrd

Ultimately, Booty allows you to create bootable ISO images and USB, HDD, SSD and other drives by installing the above system from images. Booty Supports creation of BIOS and UEFI boot systems. GRUB2 and SYSLINUX bootloaders are supported. Bootloaders can be combined, for example, use SYSLINUX to boot into the BIOS, and GRUB2 for UEFI. To create ISO images, you will additionally need the cdrkit (genisoimage) or xorriso (xorrisofs) package, to choose from.

The only additional step that will be 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 the directory by putting the vmlinuz kernel and the previously prepared “empty” initrd created in the first example into it.

mkdir iso/
cp /boot/vmlinuz-* iso/boot/vmlinuz
cp initrd iso/boot/initrd

This completes the preparation, now we can create ISO images from this directory.

The following command will create an ISO image, not bootable, just an ISO:

mkdir iso/
mkbootisofs iso/ --output archive.iso

To create a boot image, you must specify the option "--legacy-boot" for BIOS and "--efi" for UEFI, respectively, either grub2 or syslinux are accepted as option parameters, you can also specify only one option (for example, UEFI boot support is not needed , it can be omitted).

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 the initrd before, you can include them in the ISO.

mkbootisofs iso/ --overlay gentoo/ --squashfs --legacy-boot grub2 --efi grub2 --output gentoo.iso

This command will generate a bootable BIOS/UEFI ISO that boots Gentoo from a SquashFS image using Overlay FS, using tmpfs for data storage. The kernel must be built with Overlay FS support with SquashFS. However, if for some reason this is not required, you can use the "--cpio" option instead of -squashfs, to package gentoo/ as a cpio-archive, in which case the archive will be unpacked directly into tmpfs on boot, the main thing is to unpack the system there was enough RAM in tmpfs.

An interesting fact: if an ISO image created using the “-efi” option is unpacked to a FAT32 flash drive by simply copying files (cp -r), then the Flash drive will boot in UEFI mode without any preliminary preparation, due to the specifics of UEFI- loaders.

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, you need to mount, for example, a USB device and run mkbootisofs on it. Only add one "--bootable" option to make the drive containing the specified directory become bootable.

mount /dev/sdb1 /mnt
mkbootisofs /mnt --overlay gentoo/ --squashfs --legacy-boot grub2 --efi grub2 --bootable

This will make the USB device bootable with the gentoo/ overlay (don't forget to copy the /boot/vmlinuz and /boot/initrd files to the device).

If for some reason the drive was not mounted to /mnt, and it turns out that /mnt is located on the main device /dev/sda, then the bootloader will be rewritten to /dev/sda accordingly. Care should be taken when specifying the --bootable option.

During the boot process, Booty supports a number of options that can be passed in the bootloader, grub.cfg or syslinux.cfg. By default, without any options, all overlays are loaded and unpacked into tmpfs (the default option is ooty.use-shmfs). To use Overlay FS, the booty.use-overlayfs option must be used. The booty.copy-to-ram option copies the overlays to tmpfs first, after which it only mounts them and loads them. After copying, the USB device (or other storage device) can be removed.

Source: opennet.ru

Add a comment