On Wed 17 Jun 2020 at 05:14:22 (+0000), Matthew Campbell wrote:
> 
> I booted from a USB 2.0 flash drive into Grub2. Then I asked Grub for a 
> command prompt. Then I issued the following three commands:
> 
> grub> linux (hd2,msdos1)/vmlinuz root=/dev/sdb1 ro
> grub> initrd (hd2,msdos1)/initrd.img
> grub> boot
> 
> /dev/sda is the internal hard drive in the laptop computer.
> /dev/sdb is the new 4 TB Toshiba External USB 3.0 hard drive.
> 
> /dev/sdc and /dev/sdd are currently USB 2.0 flash drives with an ext4 file 
> system on the first and only partition. Both use a DOS MBR partition table 
> that sets the first partition as active/bootable.
> 
> The hard drive, /dev/sdb, always responds faster than the USB flash drives so 
> it is always /dev/sdb.
> 
> Now Debian Linux is running on my new hard drive using /dev/sdb1 as the root 
> partition. I need to set up a separate USB flash drive to do all of this by 
> default so I don't have to do all of this work every time the computer boots 
> up. I also need to install Grub2 on the backup USB flash drive so I can use 
> it to boot my system if something goes wrong and the first USB flash drive 
> that I just used gets screwed up as well.

Perhaps it would be simpler to use a more generic approach.
You could try installing the package grub-rescue-pc, which
contains within /usr/lib/grub-rescue/:

-rw-r--r-- 1 root root 5021696 Jun 25  2019 grub-rescue-cdrom.iso
-rw-r--r-- 1 root root 1255424 Jun 25  2019 grub-rescue-floppy.img
lrwxrwxrwx 1 root root      21 Jun 25  2019 grub-rescue-usb.img -> 
grub-rescue-cdrom.iso

(The exact sizes may differ according to amd64/i386 architecture.)
I copy the ISO file onto any old USB stick that's past its prime.

If that stick boots successfully, you should type:

c       for a grub prompt.
ls      to list the drives and partitions that grub can see.
ESC     to exit from the prompt.
e       to edit grub.cfg.
Change  set root=(hd0,msdos1)
to the appropriate (drive,partition) from the ls output, eg (hd1,gpt4).
Change  root=/dev/sda1
to the appropriate partition, eg sda4.
F10     to boot.
Grub uses the links in your root filesystem to find the appropriate
vmlinuz and initrd.img. (You might need hd2 and sdb1 for the first
partition on the second disk.)

Your system should now be running from the hard drive specified.

As you want to streamline this, it makes sense to change those two
lines on the stick, as appropriate. I tried this out by making a
local copy of the original grub-rescue-cdrom.iso and editing it with
emacs. I searched for the string "For boot" to get to the right place,
and edited as above. gpt4 is shorter than msdos1, so I added a couple
of spaces after the ). This makes it easier to compare the original
and the copy by typing
$ vbindiff your-copy.iso /usr/lib/grub-rescue/grub-rescue-cdrom.iso
and pressing Enter. The differences will show up in red.

(If you don't have vbindiff, just install the package vbindiff.)

Copy the modified ISO onto the stick, boot it, and press e as above.
If the menu looks correct, press F10 to boot. Next time you boot
from the stick, just pressing Return will be enough.

When the USB stick gets ropy, just copy your ISO to another one.

I didn't bother to investigate why emacs added a harmless linefeed
to the end of the edited ISO.

I'm surprised that you appear to have an MBR partition table on
the 4TB drive (hd2,msdos1). Is that right or have I misunderstood
something?

Cheers,
David.

Reply via email to