Default Boot from Mint Live flashdrive failure fix.

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
bodge99

Default Boot from Mint Live flashdrive failure fix.

Post by bodge99 »

Hi,

I've added some context here. This should makes things easier to follow.

"Initrd unpack failure.."
For a while now, when booting a Mint machine, I've noticed a fleeting "Initrd unpack failure.." error message when booting. I initially thought little of it.
Early last year I revamped my network media server with a newer, more powerful motherboard. When testing the hardware, I found that the USB controllers would freeze when copying large files from an external USB drive. Investigations lead to editing the system's '/etc/initramfs-tools/initramfs.conf' and changing the 'COMPRESS' setting from 'lz4' to 'gzip' and regenerating the 'initrd'. This fixed the "Initrd unpack failure.." error message and the USB controller problem.
I now make this change on every Mint machine that I see.

Live flashdrive lockup:
I've recently tried to assist someone on a thread here who could not install Mint onto a new USB 3 based laptop. The Mint live flash drive wouldn't boot.
When testing other machines here, I found a laptop that would lock up when attempting to boot from a Cinnamon live flashdrive.
Initial experiments involved extracting the Iso 'initrd' and recompressing with 'gzip'. This gave a "fix".. but I wasn't totally happy with it as this meant removing some early load Intel & AMD microcode. I then looked more closely at the flashdrive boot and modified it to work on a bootable fat32 partition that is placed onto a flashdrive.

What should have been a simple file & directory copy procedure turned into something else.. as problems were found that seem to involve some sort of interaction between some flashdrive controller firmwares and a simple copy process onto a non-standard flashdrive partition. A working Iso extraction & copy process was evolved that allowed the creation of a bootable flashdrive. The laptop now boots successfully from this flashdrive.

As a result of work undertaken in viewtopic.php?f=46&t=347457&e=1&view=unread#unread
Here is a workaround for those machines that 'lockup' when trying to boot a stock Mint Live flashdrive.
This bug only seems to affect a small number of machines with specific Bios firmware.
It seems a good idea to post this here.. as it might be useful to others.

This involves manually extracting the Mint Iso and placing the contents directly onto a fat32 formatted flashdrive.
This has the advantage in that the flashdrive is now writable.

** Post 41 extract: **.
In my recent downtime, I've been looking at how the Iso's initialise everything. To cut a "long story short" I've found a workaround that allows the stock 'initrd.lz' to be used. I found this just after I'd nearly finished regenerating the Iso 'initrd.img' files **properly**.
I've decided to stay "stock", as far as possible, as some folk might be concerned about the otherwise missing Intel & AMD microcode.

You have to use a slightly modified 'grub.cfg' and copy the Iso contents to the flashdrive in a specific way. The use of GUI tools **can** break things.. so don't waste your time.
If anyone doubts this, then I invite them to try..
I've even had problems when using basic CLI commands. In a couple of cases, after copying across, 'gparted' showed the fat32 partition as a RO ISO9660 one!
The following method works with all of the Mint 20.1 Iso's and with the various makes of flashdrive that I've tried.

Please follow these instructions **exactly**..

When the flashdrive has booted, I would recommend that you use 'gparted' to create your partitions. When installing, choose "something else" at the disks section.

On reboot, after the installation has finished, edit '/etc/initramfs-tools/initramfs.conf'
Change the entry 'COMPRESS=lz4' to 'COMPRESS=gzip' and save the file.
Now update the system.. This will install a newer kernel which will create new 'initrd.img' files for any existing and subsequent kernels. These will use 'gzip' for the 'initrd' compression.


Create a text file containing the following:

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" --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 (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
}
menuentry "OEM install (for manufacturers)" {
	set gfxpayload=keep
	linux	/casper/vmlinuz  file=/usb/preseed/linuxmint.seed oem-config/enable=true only-ubiquity boot=casper iso-scan/filename=${iso_path} quiet splash --
	initrd	/casper/initrd.lz
}
menuentry "Check the integrity of the medium" {
	linux	/casper/vmlinuz  boot=casper integrity-check iso-scan/filename=${iso_path} quiet splash --
	initrd	/casper/initrd.lz
}
Save this as 'grub.cfg', somewhere safe.

Insert your flashdrive.
Using gparted. Select your flashdrive. ***Make a note of how your device is identified.***
I'll use 'sdc' here.
'Device', 'Create Partition Table..'. Select 'msdos'.
Create a fat32 partition (edit. Use the full capacity here.). Now set the 'boot' and 'esp' flags.
Quit 'gparted'.

Open a terminal

Code: Select all

sudo su
mount /dev/sdc1 /mnt {mount the flashdrive partition to '/mnt'}
mc {run Midnight Commander}.
When using 'Midnight Commander', ignore the error message 'Cannot chown target file..' when copying any file or directory to the flashdrive partition.
Just press 'Skip' (or 'Skip All'). Fat32 does not support file or directory ownership.

LHS - 'Tab' to the left hand pane.
RHS - 'Tab' to the right hand pane.

LHS. Browse to the Iso. Press 'Enter' twice to mount it.
RHS. Browse to '/mnt'.
LHS. Cursor down to the first directory.
Press 'F5' to copy the directory. Cursor down and repeat with each directory and remaining files.

Open another terminal.

Code: Select all

sync
Wait for the prompt to return.

From the first terminal:
LHS Browse to the location of your new 'grub.cfg'.
RHS Browse to '/mnt/boot/grub'. Press 'Enter' to access the directory.
LHS With your 'grub.cfg' selected, press 'F5' to copy & overwrite the existing file.

Quit 'Midnight Commander'

Code: Select all

umount /mnt
Done.

With the single laptop here that won't boot with the stock Cinnamon Iso, I've found some file corruption occurs within the Initrd ramdisk during the kernel first stage load. This is not totally consistent.. I'm **guessing** that there is some sort of bad UEFI firmware interaction that is causing memory corruption until the kernel has fully taken control.
This does not occur if I use a newer kernel (the Iso uses 5.4.0-58).
The use of a fat32 partition on a **flashdrive** causes the kernel to use a slightly different memory map (The 'grub.cfg' passes a 'USB' stanza to the kernel here, not a 'CD' one.. which still works with an HDD device.).

I've looked at other machines that have mostly similar hardware.. These don't exhibit any early memory corruption at all. Ummm..
I've reported the problem.. It is being looked at. The original Ubuntu 20.04 Iso (I don't mean the .1 or .2 release) does not exhibit this problem.

Bodge99
Last edited by bodge99 on Thu Apr 22, 2021 7:48 am, edited 10 times in total.
User avatar
AndyMH
Level 21
Level 21
Posts: 13616
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Default installation from flashdrive failure fix.

Post by AndyMH »

Interesting!
Create a fat32 partition. Now set the 'boot' and 'esp' flags.
How big? As this is an EFI partition I'm assuming 100MB is big enough? And as it is an EFI partition, I'm assuming this is only applicable to UEFI boot, not legacy?

Not everybody uses midnight commander (I don't), how about a terminal version of what you are doing in mc?
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
bodge99

Re: Default installation from flashdrive failure fix.

Post by bodge99 »

Hi,

You would think that 'normal' file/directory copy actions would be O.K.... wouldn't you? I did.. until I found inconsistencies between different flashdrives that seem to be caused by differing flashdrive controller firmwares.
This method **works** with every flashdrive type that I tried..

The 'initrd unpack error" will occur however the the Iso is booted... (Legacy or UEFI).. In the very vast majority of cases, this is non-fatal.
This is transferred to the stock installation.
Making the change to the installed system's 'initramfs.conf' and rebuilding the 'initrd" will eliminate this problem permanently.
There is a bug with the stock lz4 'initrd' unpack routines that doesn't occur when using 'gzip'.

SWMBO has a laptop that locks up when trying to boot a stock Cinnamon Live flashdrive. In this particular case, UEFI firmware is involved.
Different firmware on **very** similar hardware is fine.. as is booting the Iso with a later kernel.
I haven't seen this bug on a Legacy system, but it is certainly possible.

The partition will need to be large enough to hold the Iso file contents.. around 2GB approx **BUT...**.
Just create a partition that fills the available space. Some flashdrive firmware either doesn't like a smaller than capacity partition, or it forces the creation of a second, useless one.

If you need Legacy boot, then just install Grub legacy to the flashdrive. It will now boot either UEFI or Legacy. Don't forget, the flashdrive has a Legacy partition table.

For those that need it:

Mount your flashdrive to '/mnt'
I'll assume 'sdc' here.. Check with 'fdisk -l'.

Code: Select all

sudo su
mount /dev/sdc1 /mnt
grub-install --no-floppy --boot-directory=/mnt/boot --target=i386-pc /dev/sdc
sync
umount /mnt
Done.
Edit: Just for completeness:
For 32-bit UEFI Boot: (Yes, 32-bit UEFI hardware **does** exist.. with x64 CPUs.)

Code: Select all

grub-install --efi-directory=/mnt --boot-directory=/mnt/boot --removable --target=i386-efi /dev/sdc
Bodge99
Last edited by bodge99 on Thu Apr 22, 2021 9:58 am, edited 3 times in total.
bodge99

Re: Default Boot from Mint Live flashdrive failure fix.

Post by bodge99 »

Hi,

I've added some context to the original post here which should make things clearer..

Bodge99
Post Reply

Return to “Tutorials”