Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[SOLVED] Installing Debian/GRUB on a USB stick

- - ALL UNSTABLE / TESTING THREADS SHOULD BE POSTED HERE - -
This sub-forum is the dedicated area for the ongoing Unstable/Testing releases of Debian. Advanced, or Experienced User support only. Use the software, give, and take advice with caution.
Post Reply
Message
Author
k04cpzom6buhvs93
Posts: 4
Joined: 2022-12-12 21:17

[SOLVED] Installing Debian/GRUB on a USB stick

#1 Post by k04cpzom6buhvs93 »

Hi, I have a Debian testing installation on my main NVME drive but I want to also have a separate installation on a USB stick.

The problem is that when I install the system on a USB stick it "takes over" the computer's boot process and only the system from the USB stick will normally boot - when I try to start the system from NVME (by selecting it from UEFI boot list) it shows me GRUB command line, which works but is inconvenient to use.

On the other hand when invoke "update-grub" in my NVME system, it will take over the boot process and I will not be able to boot directly from USB stick at all when I select it from the UEFI device list or any other way.

I know that I can "update-grub" when both drives are mounted, so "grub-install" will also create entries for systems on other drives (when properly configured with GRUB_DISABLE_OS_PROBER) but ideally I would like to have completely independent systems on both drives. E.g. if I forget to mount the USB device, "update-grub" will remove the entry for the unavailable device. Also, the system on a USB stick is mainly for offline backups and I really don't want to mount it in my main system.

Curiously, I can boot Debian Live CD on a USB stick without problems. Only when I install it on a USB stick it causes problems.
Last edited by k04cpzom6buhvs93 on 2023-01-24 20:31, edited 1 time in total.

User avatar
dashek
Posts: 47
Joined: 2022-12-03 20:59
Has thanked: 7 times
Been thanked: 5 times

Re: Installing Debian/GRUB on a USB stick

#2 Post by dashek »

Maybe writing grub boot entries manually would fix the problem. I mean adding custom entries to /etc/grub.d. With this, you can setup nvme install to boot local install and, if you wish, usb install. Respectively, configure usb stick install to boot itself, and, if chosen to, nvme install.

Example:
/etc/grub.d/45_custom on usb stick install:

Code: Select all

#!/bin/sh
exec tail -n +3 $0

menuentry 'usb debian' {
    set root=UUID=<usb partition uuid where /boot dir. is located>
    linux   /boot/vmlinuz<version>  root=UUID=<system root partition> ro
    initrd  /boot/initrd.img<version>
}

### to boot nvme install from usb stick grub:
menuentry 'workstation debian' {
    set root=UUID=<uuid of nvme partition >
    linux   /boot/vmlinuz<version> root=UUID= ro
    initrd  /boot/initrd.img<version>
}
If you do the same on nvme install, and just change the default boot entry in /etc/default/grub, it should work.
You can start with copying existing entries from currently used /boot/grub/grub.cfg to newly created /etc/grub.d/<entry name>. For safety, you leave module insertions ("insmod ...") and modify device UUIDS & vmlinuz/initrd names.
When you type update-grub next time, your modifications are going to be included in new grub.cfg.
By choosing this solution, you will need to manually add new entries after every new kernell installations on both systems.

I worked out this aproach when trying to solve grub configuration hell when i had like 5 linux installs on 2 HDDs :wink:
I was new to linux back then, so I had learn a lot.

k04cpzom6buhvs93
Posts: 4
Joined: 2022-12-12 21:17

Re: Installing Debian/GRUB on a USB stick

#3 Post by k04cpzom6buhvs93 »

Hi dashek, thanks for your reply!

This is actually a very useful technique I didn't know about. However, it doesn't help in this case as it turned out I couldn't even boot from the USB stick by selecting it from UEFI boot list after I installed GRUB on my NVME using grub-install.

So I started to believe that there is something wrong with the GRUB on the USB stick as I had problems with GRUB installation in the past and, as I said, I can boot from a live CD on a USB stick without any problems. I found a Debian Wiki page describing how to reinstall GRUB. After chrooting into the system on the USB stick I reinstalled GRUB by invoking "grub-install /dev/sda". This fixed my problem, I now have completely separate Debian installations and to boot from USB stick I just select it from UEFI menu.

Thank you again for your help!

Post Reply