help-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Install grub2 into a hard disk image without root


From: Javier Pimás
Subject: Install grub2 into a hard disk image without root
Date: Wed, 11 Jul 2018 21:52:45 -0300

Hi folks, this is possibly a FAQ, but despite looking for an answer for a
long time in many places I couldn't find any, so I come to you.

The thing is, for my OS, I'm trying to install grub2 as the bootloader into
a hard disk image. The image has only one partition formatted as fat, which
contains /boot/grub/grub.cfg and my kernel files. With root access, I'm
able to mount the image file as a loop device and install everything using
grub-install:

sudo grub-install --target=i386-pc --no-floppy
--boot-directory=$(BLDDIR)/mount/boot/ --modules="normal part_msdos fat
multiboot" $LOOP_DEVICE_ALL

The problem is that I want to do all this *without* sudoing. As I didn't
know how to do it, I came up with a hack that almost worked, which is this:

1. I diffed the original hd image file and the one created by grub-install,
to notice that (at least) 2 things happened: a) the first 517 sectors were
overwritten with grub code (except the partition entries in the MBR); b)
grub modules were copied to /boot
2. Then took those 517 sectors and copied them to a raw file using dd. I
also copied the files installed by grub-install into the fat filesystem and
placed them somewhere else.
3. Now, I tried taking the original image file to copying every part of
grub manually: first the grub module files with mcopy into /boot/grub, then
the MBR (minus the partition table) and finally the other 516 sectors.

With all this, I booted a vbox vm with this hd and to my surprise, grub
loaded. The problem is that for some reason my (hd0,msdos1)/boot/grub/grub.cfg
wasn't executed, so to complete the boot process I had to write by hand
this:

set root=(hd0,msdos1)
multiboot /nopsys.kernel video=1024x768x32
module /SqueakNOS.image
module /SqueakNOS.changes
boot


Now, I can imagine that what I did can break in a million ways (and that
I'm going to hell just for trying it :P ). Still I'd like to know what is
missing to complete the last step (so that grub.cfg boots everything
automatically), or either how to do all this in an elegant way.

Cheers,
Javier

-- 
Javier Pimás
Ciudad de Buenos Aires


reply via email to

[Prev in Thread] Current Thread [Next in Thread]