UEFI and Legacy boot.
(Edit: This specifically applies to the Mint 20.1 Iso's. Other Mint Iso's will be similar. You would need to examine the 'initrd.lz' file with something like 'binwalk' to identify the end address of the microcode archive/start address of the "real" 'initrd'.)
Note: The flashdrive is **writable** now. (Things can be added, pre-boot, if required.)
I "tasked myself" to do this... Yes, I really am that sad.. Actually, I've used this as a learning exercise.
A worked example that uses the Ubuntu Mainline kernel version 5.12.0-051200-generic.
This is installed onto the host system using 'mainline-gtk'. You can uninstall this after this process is completed if required.
See https://code.launchpad.net/~cappelikan/ ... ubuntu/ppa
NOTE: The 5.12.0 (and onwards) kernel headers are not installable in Mint 20.1 at this time (May 2021) due to dependency problems. 'libc6' 2.33 or greater is now required. This does not affect booting or normal system operation.
You can use any kernel that you wish.. I'm copying files from a host system that has the required kernel installed.
You can certainly use kernel '.deb' files if you so wish.
I use 'Gparted' and 'Xed' (run as 'sudo xed' from a non-Root terminal.).
Format a flashdrive to fat32 and set the 'boot' and 'esp' flags. Edit: 'msdos' partition table.. **NOT** 'gpt'.
Edit 10/05/21 . I've found that with some flashdrives that you cannot set the 'boot' and 'esp' flags unless the partition & filesystem has been created with Gparted.
IMPORTANT: Use 'gparted' for this... 'Device', 'Create partition table'. Chooses 'msdos' and 'Apply'. 'Partition', 'New'. Select 'Fat32' and click 'Add'.
'Edit', 'Apply Operations'. Click on the partition graphic (the box with the text '/dev/sda1') to highlight it. 'Partition', 'Manage flags'. Select 'boot' & 'esp'
and click on close. Close Gparted.
Overview:
The Iso contents are extracted. From here, the squashfs filesystem & initrd are extracted and uncompressed.
The unsquashed file system is modified by replacing the firmware and kernel modules. The initramfs.conf is altered to use 'gzip' compression.
The initrd is now extracted. Firstly, the initial Intel & AMD microcode archive is separated off. The remaining 'initrd' is expanded.
The Initrd firmware & modules are replaced and the Initrd's 'initramfs.conf' is altered. The complete 'initrd.lz' is rebuilt in two stages.
Recompress the filesystem using 'mkinitramfs' and replacing the microcode archive at the beginning of the file.
Other minor changes: Alter the system's 'grub.cfg' and replace the boot kernel. Update the 'MD5SUMS' and Squashfs 'filesystem.size' files.
On boot, the system starts a "checking integrity" check. I'm not sure what initiates this as the only thing that I can't reconcile is the Squashfs 'filesystem.size' value. The original Iso version's file content doesn't match the calculated size of its unsquashed filesystem. Just cancel the check.
Yes, I have performed an installation using a flashdrive prepared by this method.
Extract ISO:
Open a terminal, become Root and mount the Iso. Create two working directories. I'll use '/mntwork' & '/mntflash' here.
'/mntflash' contains the extracted Iso files. Files here are either modified directly or copied over from those created in '/mntwork'.
Extract the Iso and unpack the squashfs file:
Code: Select all
sudo su
mkdir /mntwork /mntflash
mount /path-to-iso/iso-name.iso /mnt
rsync -r --info=progress2 /mnt/ /mntflash {Copy Iso contents to /mntflash.}
umount /mnt
cd /mntwork {Working directory. Modified files are stored here and then written to their correct location within /mntflash.}
Code: Select all
unsquashfs -d ./unsquashed /mntflash/casper/filesystem.squashfs {Expand the filesystem to ./unsquashed/ directory.}
dd bs=3492864 count=1 if=/mntflash/casper/initrd.lz of=./initrd_part1.bin {Remove the header archive (this contains Intel & AMD microcode).}
dd bs=3492864 skip=1 if=/mntflash/casper/initrd.lz of=./compressedinit.bin {Remove the compressed initrd}
{Ignore the two 'cpio' warnings here. These refer to the parent directory that contains the expanded filesystem.)
unlz4 -d ./compressedinit.bin expandedinitrd.bin {Decompress the original initrd.}
cpio -id -D NewInitrd < ./expandedinitrd.bin {Extract filesystem to ./NewInitrd/}
From a non-Root terminal:
Code: Select all
sudo xed /mntflash/boot/grub/grub.cfg
Code: Select all
if loadfont /boot/grub/font.pf2 ; then
set gfxmode=auto
insmod efi_gop
insmod efi_uga
insmod gfxterm
terminal_output gfxterm
fi
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
menuentry "Start Linux Mint 20.1 64-bit ***NEW KERNEL***" --class linuxmint {
set gfxpayload=keep
linux /casper/vmlinuz file=/usb/preseed/linuxmint.seed boot=casper iso-scan/filename=${iso_path} quiet splash --
initrd /casper/initrd.lz
}
menuentry "Start Linux Mint 20.1 64-bit ***NEW KERNEL*** (compatibility mode)" {
linux /casper/vmlinuz file=/usb/preseed/linuxmint.seed boot=casper iso-scan/filename=${iso_path} noapic noacpi nosplash irqpoll nomodeset --
initrd /casper/initrd.lz
}
From a non-Root Terminal:
Code: Select all
sudo xed /mntwork/unsquashed/etc/initramfs-tools/initramfs.conf
Modify the expanded squashfs filesystem:
From a Root terminal:
Code: Select all
cp /boot/System.map-5.12.0-051200-generic /mntwork/unsquashed/boot
cp /boot/config-5.12.0-051200-generic /mntwork/unsquashed/boot
rm /mntwork/unsquashed/boot/System.map-5.4.0-58-generic
rm /mntwork/unsquashed/boot/config-5.4.0-58-generic
rm -r /mntwork/unsquashed/lib/firmware/*
cp -R /lib/firmware/* /mntwork/unsquashed/lib/firmware {Update firmware.}
cp -R /lib/modules/5.12.0-051200-generic /mntwork/unsquashed/lib/modules {Replace modules.}
rm -r /mntwork/unsquashed/lib/modules/5.4.0-58-generic
ln -s vmlinuz-5.12.0-051200-generic vmlinuz {Replace symlinks to point to the new kernel & initrd.}
ln -s vmlinuz-5.12.0-051200-generic vmlinuz.old
ln -s initrd.img-5.12.0-051200-generic initrd.img
ln -s initrd.img-5.12.0-051200-generic initrd.img.old
mv vmlinuz* /mntwork/unsquashed/boot
mv initrd.* /mntwork/unsquashed/boot
Code: Select all
mksquashfs /mntwork/unsquashed/* /mntwork/filesystem.squashfs
cp /mntwork/filesystem.squashfs /mntflash/casper
From a non-Root Terminal:
Code: Select all
sudo xed /mntwork/NewInitrd/conf/initramfs.conf
From the Root terminal:
Code: Select all
rm -r /mntwork/NewInitrd/lib/firmware/*
cp -R /lib/firmware/* /mntwork/NewInitrd/lib/firmware {Update firmware.}
cp -R /lib/modules/5.12.0-051200-generic /mntwork/NewInitrd/lib/modules {Replace modules.}
rm -r /mntwork/NewInitrd/lib/modules/5.4.0-58-generic
{Rebuild initrd and copy it to the required location.}
cd /mntwork/NewInitrd
mkinitramfs -d ./conf -o /mntwork/initrd_part2.bin
cd ..
cat initrd_part1.bin initrd_part2.bin > /mntflash/casper/initrd.lz
cp /boot/vmlinuz-5.12.0-051200-generic /mntflash/casper/vmlinuz {Replace kernel.)
cd /mntflash
find -type f -exec md5sum '{}' \; > MD5SUMS {Update the MD5SUMS list.}
du /mntwork/unsquashed -sx --block-size=1 | cut -f1 > /mntflash/casper/filesystem.size
Code: Select all
mount /dev/sda1 /mnt
shopt -s dotglob {Temporary change of your bash shell environment to allow the copying of a specific file type}
rsync -r --info=progress2 /mntflash/ /mnt {Copy modified Iso contents to /mnt.}
sync {Wait for the prompt to return.}
Code: Select all
grub-install --boot-directory=/mnt/boot --target=i386-pc /dev/sda {This assumes that your flashdrive is seen as 'sda'.}
sync
umount /mnt
Bodge99