Sunday, August 28, 2016

Make USB storage as a GRUB bootable device

I normally have multiple operating systems on my machine. I thought I'd remove my old Ubuntu installation and use the partitions for other purposes. I knew I'd have GRUB issues, but thought it'd be relatively easy to find how to make a bootable USB pendrive. But, I was wrong!

Seems like most installers use syslinux based boot loaders and grub kicks in later. So, getting hold off one wasn't easy. After searching and reading, I found some useful information (I'm missing exact links though :( ). But here's the brief steps to get a plain grub bootable device.

(This is assuming you have access to some other Linux/GRUB based system)

Assuming /dev/sdb1 is your usb (FAT32 or otherwise) device - BE CAREFUL TO PICK THE RIGHT DEVICE!

[ Run as root / sudo as required ]

[ Mount the device ]
$ mount /dev/sdb1 /media

[ Create folders ]
$ mkdir -p /media/boot/grub

[ Next copy stage1, stage2 files ]
cp /boot/grub/stage* /media/boot/grub/

[ Start grub ]
$ grub

[ Change grub root device - normally hd0 => sda and hd1 => sdb and so on...again be careful! ]
grub> root (hd1, 0)

[ Setup as boot device ]
grub> setup (hd1)

....some messages, statuses, warnings, etc...

[ Quit ]
grub> quit

It should be a bootable device now and should give the grub boot can use that to boot Windows e.g.
[ Again, use the correct number - it depends on your boot order ]
rootnoverify (hd1,0)
chainloader +1