Grub not loading after upgrade from Vista to Windows 7

 On my work laptop, I dual-boot Windows Vista Enterprise (in case it's necessary at a customer site) and Gentoo (if I get to do things my way ;-) ). I recently decided to upgrade Vista to Windows 7, which worked just fine (after installing a meeljon updates - it had been a while).

As expected, Windows 7 obliterated my MBR. Bye-bye GRUB, Gentoo LiveCD to the rescue!

In the livecd I mounted my / (on /dev/sda3), /proc and /dev to /mnt/gentoo and chrooted in:

# mount /dev/sda3 /mnt/gentoo

# mount -t proc none /mnt/gentoo/proc

# mount -o bind /dev /mnt/gentoo/dev

# chroot /mnt/gentoo /bin/bash

Now run grub, let it re-write itself to the MBR and everything's happyhappy-joyjoy again, right?

# grub

grub> root (hd0,2)

grub> setup (hd0)

grub> quit

# reboot

Right after POST, I get greeted by a blinking cursor, and that's it. No GRUB, no message, nothing. Just that blinking cursor, mocking me. Back to the livecd, and chrooting into my gentoo installation once again. I used to use grub-install, so I decided to try that again (important: after chrooting - it's not necessary but the command is different!)

# grub-install /dev/sda

/dev/sda does not have any corresponding BIOS drive

Apparently GRUB doesn't have a proper device map. Time to refresh it:

# grub-install --recheck /dev/sda

/dev/root: not found or not a block device

This one is new ... df -h reveals that / is mounted as /dev/root, instead of the expected /dev/sda3 and that /dev/root does not exist (of course - that bind command I used right before chrooting? /dev/root didn't exist in the livecd environment). A symlink ought to fix this:

# ln -s /dev/sda3 /dev/root

# grub-install /dev/sda

One reboot later my grub is back where it's always been, offering me the choice between Gentoo and Windows 7.

 Permalink

Shutting down Windows from Linux

I had to do some research on how to remotely shut down a Windows computer from a Linux host and decided to share :-)

My test environment: 

  • Gentoo linux running on my laptop
  • Windows XP SP3 running in a VirtualBox guest

The command (you need Samba installed on your Linux machine):

net rpc shutdown -t 10 -f -C "Remote shutdown initiated" -I 192.168.56.2 -U Erik

Broken down, that becomes:

  • -t 10 to give users 10 seconds to hit Ctrl-S
  • -f to force applications to quit without asking the user to save (so they can't get in the way of the shutdown)
  • -C "Remote shutdown initiated" is the message that should be displayed to any logged-in users
  • -I 192.168.56.2 the IP address at which the machine to shut down is located. In my case, the host-only network adapter
  • -U Erik is my username on the Windows machine. Works also as <hostname>\<username> (don't forget to escape the backslash if your shell requires it!) or as <workgroup>\<username>
  • If you like, you can add -r to reboot the machine instead of shutting it down.

If you don't want to be asked for your password, append it to your username with a % sign, like so: -U <username>%<password>

Of course, with Windows being involved, this doesn't work right out of the box ;-) In my case, after being asked for the password the net rpc command reported "Shutdown of remote machine succeeded". The Windows XP machine didn't shut down. It didn't even show me a message. A little Wireshark magic ended up revealing the error code "WERR_ACCESS_DENIED" being sent across the wire. (note to self: maybe a newer version of samba will actually do something with this error?)

Long story short: the solution is to have file sharing enabled, but to disable simple file sharing. To do so, open Explorer, go to Tools -> Folder options -> View (yes, it's the most logical place to put this </sarcasm>) and uncheck "Use simple file sharing" (all the way at the bottom of the list).

 Permalink
1-2/2