Brute force booting Windows under UEFI using GRUB2

Share your own howto's etc. Not for support questions!

Brute force booting Windows under UEFI using GRUB2

Postby edbarx » 2017-04-15 17:47

Sometimes one has to use MS Windows, especially, if one happens to be still a student. This howto is intended for those who want GRUB2 to boot Windows using brute force. Sincerely, I never used GRUB2 in non-brute force ways. For this reason, I edit the file /boot/grub/grub.cfg. Please, be aware this is normally discouraged, but if you happen to be in a desperate situation requiring Windows for your work, the method I am going to describe worked for me to boot MS Windows 8.1 under UEFI with secure boot disabled although it should also boot MS Windows in secure boot. I am saying MS Windows should be booted even in secure boot because we are going to call its primary bootloader directly. If you have overwritten the Windows primary bootloader that is found under /EFI/Microsoft/Boot/ in the EFI System FAT32 Partition, this method cannot be used.

The Method:
Suppose your EFI System (FAT32) Partition is /dev/sda1 and the Windows primary bootloader is bootmgfw.efi. To boot Windows, all you need to do is:
  1. Start or reboot the machine.
  2. At GRUB2's menu, press 'e' to enter the Edit Mode.
  3. Delete all text.
  4. Type the magic spells:
    Code: Select all
    set root='(hd0,gpt1)'

    And in the case of an MBR formatted disk:
    Code: Select all
    set root='(hd0,msdos1)'

    Be aware that lately the syntax for the set root command has changed. If my memory serves me right, the brackets have been removed. Consult your grub.cfg under /boot/grub/ to learn which version is used in your case.
    Code: Select all
    chainloader /EFI/Microsoft/Boot/bootmgfw.efi
  5. Press either Ctrl + x OR F10 to boot.

That is it!

I am using this method to boot MS Windows 8.1. All I did was include the magic spell in grub.cfg. To do that one must duly follow the syntax rules, otherwise, GRUB2 may fail to load a menu.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5361
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: Brute force booting Windows under UEFI using GRUB2

Postby phenest » 2017-04-16 15:44

Why would you do this instead of a permanent Grub entry?
Dell XPS 17 L702X i7 2860QM 2.5GHz - 32GB RAM - 4G WWAN - Pioneer TD05-BDR
NEC Spirit 550 P4 3.6GHz HT - 2GB RAM - nVidia 7600GT - Pioneer BDR-209DBK
ASUS P8P67 EVO i7 3770K - 32GB RAM - 2x nVidia 660GTX SLI'd
User avatar
phenest
 
Posts: 1147
Joined: 2010-03-09 09:38
Location: The Matrix

Re: Brute force booting Windows under UEFI using GRUB2

Postby edbarx » 2017-04-16 17:02

phenest wrote:Why would you do this instead of a permanent Grub entry?

Sometimes it is for the lolz, other times it is for the geeky feeling, but very often, it is out of sheer necessity. GRUB* sometimes, has the habit of playing roughly.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5361
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: Brute force booting Windows under UEFI using GRUB2

Postby ruffwoof » 2017-04-16 18:48

edbarx wrote:
phenest wrote:Why would you do this instead of a permanent Grub entry?

Sometimes it is for the lolz, other times it is for the geeky feeling, but very often, it is out of sheer necessity. GRUB* sometimes, has the habit of playing roughly.

I for one appreciated your post. Thanks edbarx.

I have grub4dos installed to my MBR (and on a USB also) ... one of the entries looks like this
Code: Select all
# menu.lst
color white/blue black/cyan white/black cyan/black
timeout 5
default 1

title Debian
  find --set-root /jessieamd64lxde
  configfile /boot/grub/menu.lst
  commandline

i.e. chains to the Debian grub menu.lst (the find command is just a empty file (jessieamd64lxde) located on the partition purely for grub to find).

Primarily because I run Debian frugally i.e. just a /live/filesystem.squashfs copy of the main installed version
Code: Select all
title Debian Jessie LIVE
find --set-root /jessieamd64lxde
kernel /boot/vmlinuz-3.16.0-4-amd64 boot=live showmounts
initrd /boot/initrd.img-3.16.0-4-amd64

as that way I boot the exact same system each and every time (and it runs quicker because its all overlaid in memory), but I fall back to booting full (read/write as per the previous case) to apply updates/make changes before recreating a new filesystem.squashfs again

cd /live
mksquashfs /mnt/sda1 filesystem.squashfs -e live

Very much like having a updateable liveCD Debian Jessie.

Whilst running from a squashfs has decompression overheads, generally the system decompresses quicker than IO so a half sized (compressed) system + decompression time is quicker than reading the full uncompressed into memory. Also all writes are written to memory rather than disk, so a lot quicker on that front. But all changes are of course lost at shutdown/reboot ... unless you make it a persistent session (set the partition label to 'persistence' or create a persistence filesystem file ... along with the required / union in persistence.conf file in the root folder of that persistence space).

I also use that grub4dos menu.lst to boot other frugals (such as Puppy Linux or similar) ... which can be handy as 'admin' type function. DebianDog is one of my first preferences for that
Code: Select all
title DebianDog only saves if run save2flash
find --set-root /MAIN/DD/live/jessie-i486.sgn
kernel /MAIN/DD/live/vmlinuz1 init=/bin/systemd from=/MAIN/DD noauto changes=EXIT:/MAIN/DD/live
initrd /MAIN/DD/live/initrd1.xz

I also have a debian jessie inside a filesystem file that's on a NTFS partition and with a relatively minor change to initrd.img that can be booted read/write so all changes persist. Along with a relatively small grub4dos USB (mine's a 64MB allocated size) and the single main filesystem file stored in the cloud, you can download that single file to a Windows PC's NTFS filesystem and boot it using the USB.
Code: Select all
title READ/WRITE
find --set-root /ntfsusb
kernel /vmlinuz-3.16.0-4-amd64 boot=live config nofastboot persistence persistence-storage=file persistence-label=ntfsper quickreboot noprompt showmounts live-media-path=/live/ config rw
initrd /initrd.img-amended-xz0-compressed

I run firefox and skype in a restricted shell that's mostly cut-off by file/folder permissions around that. Having the main filesystem in a (read only) squashfs is yet another layer of protection. I did try virtualisation (virtualbox) for running the browser ...etc, but found that to be slow.
ruffwoof
 
Posts: 69
Joined: 2016-08-20 21:00

Re: Brute force booting Windows under UEFI using GRUB2

Postby phenest » 2017-04-16 21:35

ruffwoof wrote:I for one appreciated your post. Thanks edbarx.

My comment was just a query.

@ edbarx:
Do you have a magic spell book? I'd have to write that down before I could use it. It's a shame Grub can't detect stuff at the Grub prompt. And it's a shame it doesn't have a Dvorak keyboard layout. It takes me longer these days to remember where the Qwerty keys are/were.
Dell XPS 17 L702X i7 2860QM 2.5GHz - 32GB RAM - 4G WWAN - Pioneer TD05-BDR
NEC Spirit 550 P4 3.6GHz HT - 2GB RAM - nVidia 7600GT - Pioneer BDR-209DBK
ASUS P8P67 EVO i7 3770K - 32GB RAM - 2x nVidia 660GTX SLI'd
User avatar
phenest
 
Posts: 1147
Joined: 2010-03-09 09:38
Location: The Matrix

Re: Brute force booting Windows under UEFI using GRUB2

Postby edbarx » 2017-04-17 07:50

phenest wrote:Do you have a magic spell book?

Oh, come on. Life is too short to take it so seriously. A little humour shouldn't hurt anyone.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5361
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: Brute force booting Windows under UEFI using GRUB2

Postby phenest » 2017-04-17 12:02

I'm sorry. I don't understand your response.
Dell XPS 17 L702X i7 2860QM 2.5GHz - 32GB RAM - 4G WWAN - Pioneer TD05-BDR
NEC Spirit 550 P4 3.6GHz HT - 2GB RAM - nVidia 7600GT - Pioneer BDR-209DBK
ASUS P8P67 EVO i7 3770K - 32GB RAM - 2x nVidia 660GTX SLI'd
User avatar
phenest
 
Posts: 1147
Joined: 2010-03-09 09:38
Location: The Matrix


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable