POSTS

Installing Linux on a Flash Drive

Linux in my pocket

I have a Windows 10 laptop that I can’t install Linux on. It’s a decent laptop with a nice form factor. It weighs half what my workhorse laptop does, and I want to take it on a trip where I’ll need to do many Linuxy things. (WSL has too many unknowns and potential blockers for me to be OK relying on).

Short version: install the installer to a small flash drive, then boot into that and select the other flash drive as ext4 to install to. https://www.tecmint.com/install-linux-os-on-usb-drive/

gparted wouldn’t let me have 2 primaries

I couldn’t figure out how to add a swap partition to my flash drive. Gparted failed hard with an unhelpful admonishment regarding too many primaries at the second partition format. There was no option for non-primary.

So I installed anyway

This took a long time, half an hour maybe, but finally linux 19 mint installed. I rebooted, there it was at the top of the grub list. All is well.

But didn’t achieve my goal

It turns out I can’t boot into it from my Windows 10 small form factor due to permissions. :[

And I horked my workhorse

So I put it in my workhorse and booted to test. No problems.

I decided to take a break for the evening and do other work. I removed the flash and restarted my workhorse. Bare grub console! Uh oh! I’ve shackled myself to the flash drive with the new Linux instance by moving the grub loader. :/

I went to bed sad for having possibly broken my workhorse but optimistic that I might learn something.

Moving the grub loader back

Sleep plus coffee later:

This might work: https://askubuntu.com/a/321885/514799

grub> set root=(hd0,1)
grub> set prefix=(hd0,1)/boot/grub
grub> insmod normal
grub> normal
#Now your system should boot normally. Log in and restore your boot loader from the terminal:

sudo update-grub
sudo grub-install /dev/sda

This worked!

I may or may not have had to run the commands from grub>, as I could already boot into my drives with the USB stick connected. After executing them from the grub terminal and rebooting, I was taken back to the grub> terminal. I’m unsure if this was expected behavior, and I’m not sure whether they actually changed anything. This bugs me slightly, but if I go down this road again, I’ll investigate further.

I booted into my HDD-installed Linux instance, ran the last two commands, rebooted, and the boot menu appeared normally without the USB stick connected. Woo.

sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-53-generic
Found initrd image: /boot/initrd.img-4.4.0-53-generic
Found Windows Boot Manager on /dev/sda2@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for EFI firmware configuration
done
sudo grub-install /dev/sda
Installing for x86_64-efi platform.
Installation finished. No error reported.

Closing the loop

To finish up, I rebooted with the USB stick reconnected to verify whether I could boot into it with the reverted grub configuration.

Sadly, I could not. It seems I have more investigation to do.

Closing

While I didn’t achieve my goal (Linux in my pocket, usable from any Windows laptop), I (re-)learned a bit about boot menus and such.

And I’m glad I don’t have a ton of rework to do to restore my workhorse.

Post publish shower thoughts

It occurs to me that this might just be a boot order problem. I’ll try booting directly to the flash from BIOs, though I’m not sure why this wasn’t necessary before moving grub back where it belonged.