Nice way to put GRUB2 onto flash drive with debian installed already on?
October 9, 2014 7:02 AM   Subscribe

I know this would be solvable with search engine and time; humility brings me to the green. I installed a minimal debian system on a flash drive from a debian live cd. Did not install a boot loader. How should I go about putting the boot loader on the drive? Difficulty level: GRUB NOOB. Links, words of wisdom and/or caution appreciated!
posted by bertran to Computers & Internet (7 answers total)
 
It's a lot easier to install a distro with a boot loader. I'm sure some else can give you more experienced advice, but personally I use linuxlive usb and it's pretty easy to install whichever distro you need.
posted by lunastellasol at 7:31 AM on October 9, 2014


Response by poster: I know that I could wipe this install and re-install with the boot loader; that seems graceless.

On the principle that every bit counts, I'd like to add a loader to what's been installed.
posted by bertran at 7:43 AM on October 9, 2014


Look for "boot repair." I think there are even live CD/USB images specialized for that task.
posted by Good Brain at 9:32 AM on October 9, 2014


If you put partitions on your USB drive, I believe you can install it into the MBR so long as grub2 actually lives on the system (which it must) and the kernel is in /boot and it's all initialized properly (update-grub? grub-install?)
posted by flimflam at 11:22 AM on October 9, 2014


Boot the live CD, then you need to plug the usb drive in, find out which device file corresponds to it & install grub to the master boot record on the device.

If it was me, I'd bring up a terminal, insert the usb drive & then run
dmesg
from the terminal, look at the end of the output (you might have to run dmesg again once the drive has settled) for the device name (it'll be something like /dev/sdb), then run
grub-install /dev/whatever-it-was
Warning: Getting the device name wrong will scribble all over the boot sector on your PC or laptop internal hard drive, so it's imperative that you get the correct device. It may help to can cross reference the partition list file
/proc/partitions
to make sure by looking at the sizes of the devices listed there.
posted by pharm at 11:32 AM on October 9, 2014 [1 favorite]


I'd boot GRML, a Debian-based LiveCD with an emphasis on offering all the trouble-shooting admin tools you might want, plug in your minimal-debian-flash drive, dmesg to find out what partition it is, like pharm says above. Assuming it's /dev/sdb1:
# mkdir /mnt/minimal
# mount /dev/sdb1 /mnt/minimal
# grml-chroot /mnt/minimal
Poof -- the root directory (i.e., the top-level directory, '/') of your running system is now the root directory of your minimal system, and all the files you can see are the minimal system's.

Now do the
# grub-install /dev/sdb
If you did the grub-install without chroot-ing into the target system, I think you'd run into troubles if the kernel version on the LiveCD system you're running didn't match the kernel version on your installed system (which is possible even if you just installed from the LiveCD, because it might have done an upgrade before it finished -- that's how it works with Debian's netinst CDs.)

Notice that the thing you mounted first was /dev/sdb1 and the thing you grub-installed to was /dev/sdb. While these are examples and you need to check what the real values are, your minimal system is on a partition on the device and can be expected to be the device name with a numeric suffix, and grub is being written with the device itself as the target, not a particular partition on the device.

(grml-chroot just automates some tedious steps you could do manually to chroot into your system -- you could look up how to do them with your LiveCD if you want.)
posted by Zed at 2:00 PM on October 10, 2014


The Ubuntu Wiki has the tedious manual steps (which are, I should note, less work than downloading a new LiveCD image and burning it, but I find it worth it to have GRML around.)
posted by Zed at 2:06 PM on October 10, 2014


« Older Community event franchises?   |   Hemorrhoids? Newer »
This thread is closed to new comments.