Skip to content

Instantly share code, notes, and snippets.

@RandallFlagg
Last active December 21, 2024 18:05
Show Gist options
  • Save RandallFlagg/30ef815c4d6f0e22b5d847661671df08 to your computer and use it in GitHub Desktop.
Save RandallFlagg/30ef815c4d6f0e22b5d847661671df08 to your computer and use it in GitHub Desktop.
Create a usb bootable system image in Void Linux using EROFS

Yes, you can create a persistent storage file on your USB drive instead of creating a new partition. Here's how you can do it:

Step 6.1: Create a Persistent Storage File

  1. Create a Persistent File:

    • Create a file that will serve as the persistent storage:
      sudo dd if=/dev/zero of=/path/to/usb/persistent.img bs=1M count=1024
      This command creates a 1GB file. You can adjust the size as needed.
  2. Format the Persistent File:

    • Format the file with an ext4 filesystem:
      sudo mkfs.ext4 /path/to/usb/persistent.img

Step 6.2: Configure GRUB for Persistence

Modify your GRUB configuration to support the persistence feature. Add the following to your grub.cfg file:

menuentry "Void Linux (Persistent)" {
    set root=(hd0,1)
    linux /boot/vmlinuz root=/dev/ram0 rw persistent
    initrd /boot/initrd.img
}

Add persistent to the kernel parameters.

Step 6.3: Mount the Persistent File

Ensure that the system mounts the persistent file at boot. You can create a script or modify the initramfs to handle this. Here's a basic example:

  1. Create a Script /etc/init.d/persistence.sh:
    #!/bin/sh
    mount -o loop /path/to/usb/persistent.img /mnt
  2. Make the Script Executable:
    sudo chmod +x /etc/init.d/persistence.sh
  3. Update the Initramfs to include the script.

Integrate these additional steps into the previous guide to enable persistence using a virtual file on your USB drive.

Would you like more details on configuring the persistence or modifying the initramfs? ๐Ÿ˜Š๐Ÿš€

Step 5.1: Create a Persistent Partition

  1. Identify the USB Device:

    sudo fdisk /dev/sdX

    Replace /dev/sdX with your USB device.

  2. Create a New Partition:

    • Enter n to create a new partition.
    • Choose the partition type (primary, usually p).
    • Specify the partition number (e.g., 2 if the first partition is already used for the bootable system).
    • Set the size of the partition.
  3. Set Partition Type:

    • Enter t to change the partition type.
    • Enter the partition number (e.g., 2).
    • Enter 83 for Linux filesystems.
  4. Write Changes:

    • Enter w to write the changes to the disk.

Step 5.2: Format the Persistent Partition

Format the newly created partition:

sudo mkfs.ext4 /dev/sdX2

Replace /dev/sdX2 with your new partition.

Step 5.3: Configure GRUB for Persistence

Modify your GRUB configuration to support the persistence feature. Add the following to your grub.cfg file:

menuentry "Void Linux (Persistent)" {
    set root=(hd0,1)
    linux /boot/vmlinuz root=/dev/ram0 rw persistent
    initrd /boot/initrd.img
}

Add persistent to the kernel parameters.

Step 5.4: Mount the Persistent Partition

Ensure that the system mounts the persistent partition at boot. You can create a script or modify the initramfs to handle this. Here's a basic example:

  1. Create a script /etc/init.d/persistence.sh:
    #!/bin/sh
    mount /dev/sdX2 /mnt
  2. Make the script executable:
    sudo chmod +x /etc/init.d/persistence.sh
  3. Update the initramfs to include the script.

To create a bootable, read-only system image for Void Linux using EROFS, you should download the Live Image. The Live Image is designed to be bootable and contains the necessary components for installation and running a live session.

Hereโ€™s the updated step-by-step process:

Step 1: Install Necessary Tools

Ensure you have the necessary tools installed. You'll need xorriso for creating the ISO and mkfs.erofs for creating the EROFS image. Install them using your package manager:

sudo apt install xorriso erofs-utils

Step 2: Prepare the Source Directory

Create a directory that contains all the files and directories you want to include in your EROFS image:

mkdir /path/to/root
cp -r /path/to/files/* /path/to/root

Step 3: Create the EROFS Image

Use mkfs.erofs to create the EROFS image:

sudo mkfs.erofs /path/to/image.erofs /path/to/root

Step 4: Download the Void Linux Live Installer Image

Visit the Void Linux download page and download the appropriate live installer image for your system architecture (e.g., x86_64, i686).

Step 5: Create the ISO Image

Use xorriso to create an ISO image that includes the EROFS image:

sudo xorriso -as mkisofs -o /path/to/image.iso -iso-level 4 -full-iso9660-path -eltorito-boot /path/to/live_installer.iso -no-emul-boot -boot-load-size 4 -boot-info-table /path/to/image.erofs

Replace /path/to/live_installer.iso with the path to the downloaded Void Linux live installer ISO.

Step 6: Write the ISO to USB

Identify your USB device and write the ISO image to it:

cp /path/to/image.iso /path/to/usb

OR

sudo dd bs=4M if=/path/to/image.iso of=/dev/sdX

Replace /dev/sdX with your USB device path. Be careful with this command, as it will overwrite all data on the USB device.

Step 7: Boot from USB

Insert the USB device into the target machine and boot from it. You may need to change the boot order in the BIOS/UEFI settings.

Updating the System Image

To update the system image, repeat the steps above with the updated files and directories:

  1. Update the source directory with new files.
  2. Recreate the EROFS image using mkfs.erofs.
  3. Recreate the ISO image using xorriso.
  4. Write the new ISO to the USB device.

These steps should help you create and update a bootable, read-only Void Linux system image using EROFS.

Feel free to ask for more details or help with any specific step! ๐Ÿš€๐Ÿ˜Š

Yes, you can create a bootable system image using your current Void Linux installation without downloading a pre-built live image. This involves creating a custom bootable image from your existing system. Here are the steps:

Step 1: Install Necessary Tools

Ensure you have the necessary tools installed, including xorriso, grub, and erofs-utils:

sudo xbps-install -y xorriso grub erofs-utils

Step 2: Prepare the Source Directory

Create a directory that contains all the files and directories you want to include in your EROFS image:

mkdir /path/to/root
cp -a / /path/to/root

This will copy your entire root filesystem into the /path/to/root directory.

Step 3: Create the EROFS Image

Use mkfs.erofs to create the EROFS image:

sudo mkfs.erofs /path/to/image.erofs /path/to/root

Step 4: Create a GRUB Bootable ISO

Create a GRUB bootloader configuration and ISO structure:

  1. Create Directories for GRUB:

    mkdir -p /path/to/iso/boot/grub
  2. Create GRUB Configuration File: Create a file named grub.cfg inside /path/to/iso/boot/grub/ with the following content:

    menuentry "Void Linux" {
        set root=(cd0)
        linux /boot/vmlinuz root=/dev/ram0
        initrd /boot/initrd.img
    }
  3. Copy Kernel and Initrd: Copy your kernel and initrd images to the ISO directory:

    cp /boot/vmlinuz /path/to/iso/boot/
    cp /boot/initrd.img /path/to/iso/boot/
  4. Generate ISO: Use grub-mkrescue to create the bootable ISO image:

    grub-mkrescue -o /path/to/image.iso /path/to/iso

Step 5: Write the ISO to USB

Identify your USB device and write the ISO image to it: In case you want to use a usb with multi ISO files like ventoy:

cp /path/to/image.iso /path/to/usb

OR In case you want to use a usb dedicated to the image:

sudo dd bs=4M if=/path/to/image.iso of=/dev/sdX

Replace /dev/sdX with your USB device path. Be careful with this command, as it will overwrite all data on the USB device.

Step 6: Boot from USB

Insert the USB device into the target machine and boot from it. You may need to change the boot order in the BIOS/UEFI settings.

Updating the System Image

To update the system image, repeat the steps above with the updated files and directories:

  1. Update the source directory with new files.
  2. Recreate the EROFS image using mkfs.erofs.
  3. Recreate the ISO image using xorriso.
  4. Write the new ISO to the USB device.

These steps should help you create and update a bootable, read-only Void Linux system image using EROFS from your current system.

Feel free to ask for more details or assistance with any specific step! ๐Ÿ˜Š๐Ÿš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment