1

I have GRUB2 installed on /dev/sda, the usual way (stage 1 in the MBR and stage 1.5 in sectors 0-63); I'm using BIOS/MBR. There are four partitions on my disk:

  1. Win10 100 MB -- Reserved
  2. Win10 30 GB
  3. Linux 20 GB
  4. Data partition (think of it as /home) -- the rest of the disk

Stage 2 of GRUB2 is, of course, installed on /dev/sda3 under /boot/grub/. Now, the question is, can I erase /dev/sda3 and /dev/sda4 and still be able to boot into Win10 from GRUB's command line manually? Using insmod part_msdos, insmod ntfs etc., up to chainloader +1.

According to wiki, it is OK, but some other sources across the internet suggest that you might get stuck after deleting stage 2 (those sources might refer to the GRUB-legacy, though).

Why do I need to do this? I'd like to extend /dev/sda2. The most reliable way to do it, as far as I know, is to use standard Win 10 disk partitioning tool (I wouldn't really trust Linux with this). It is supposedly risky doing it while booted into the same partition you're trying to extend, but I've done it and it works fine (there's also some 3rd party software that handles it smoother by extending it in between the boots).

So, I'd like to delete /dev/sda3/, /dev/sda4/, extend /dev/sda2/, then boot into Live USB, repartition the unallocated space, install Linux, install GRUB and be done.

I'm only concerned, what if something goes wrong (which usually does), will I be able to boot manually?

There's another way: installing GRUB2 Stage 2 onto a USB (USB comes before HDD in my BIOS boot order) and booting from USB. But that's clumsy (and I've never done it before), so I would prefer to avoid it if possible.

(I did back up, of course.)

3
  • Stage 2 is loaded by stage 1.5. if there's nothing to load to, then it stops and drops you to an emergency shell (if configured to do so). I'd advise you to not dual boot at all and put the OS you use less into a virtual machine instead.
    – Mio Rin
    May 23 '18 at 1:52
  • @Mioriin Thanks, I learned that from the linked wiki page. How do I know if it is configured in that way though? edit: no, VM is not an option for me, thanks.
    – gsarret
    May 23 '18 at 1:54
  • Most options for grub are set in /etc/default/grub. Start by looking in there and referring to man grub for specifics.
    – Mio Rin
    May 23 '18 at 1:57
0

Turns out it is not as is, but it is with preliminary extra effort.

What I did

  1. Boot from Linux LiveUSB, mount /dev/sda3 (Linux partition with grub), mv /boot/grub /boot/grib (or anything, just so that stage 1.5 no longer can find stage 2)
  2. Reboot from HDD, grub unsurprisingly fails to load stage 2 and falls back to grub rescue mode
  3. However, the rescue mode has only very minimal support, so, for instance, you can run insmod part_msdos, but neither insmod ntfs, nor chainloader +1 and so on works. It has support for ext4, though (of course).
  4. I was able to manually load all the needed modules (either using the full path like insmod (hd1,msdos3)/boot/grib/i386-pc/ntfs.mod, or simply setting the prefix first: set prefix=(hd1,msdos3)/boot/grib and using relative paths after that: insmod ntfs)
  5. You can make your life a bit easier by loading normal module and then entering normal which takes grub from rescue mode to the bash-like grub command line. From there, you can again load all the needed modules (for example, chainloader module has to be loaded as well)
  6. Finally, load Win10 (or anything else) by replicating the same exact command sequence as in grub.cfg

Solution

So, given all this, I believe it should be fine as a temporary fix to simply copy the whole i386-pc directory to a separate USB and load modules manually as needed. Just have to make sure that separate USB is formatted as MBR and has an ext4 partition.

Update: indeed it works. Simply formatting a USB stick as MBR, creating an ext4 partition and copying (properly configured) /boot/grub/ from the previous installation does the trick. When grub falls back to grub rescue, just enter set prefix=(hdX,msdosY)/boot/grub (where X is the number of your USB drive and Y is the corresponding partition), then insmod normal and normal. That's it, grub stage 2 loads and works just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.