5

I have a Linux and Windows 7 dual-boot setup on my PC and I would like to configure the OSes so that when working in one OS, I can hibernate (saving the state to disk), reboot, use the other OS, reboot again when done, and resume using the first OS from where I left off. The critical factor here is that I want each of the OSes to reboot after saving their state to disk instead of powering off; otherwise, I have to turn the computer back on in between which is quite annoying. I'm well aware that it is trivial to configure Linux to do this (see this question). However, I don't know how to tell Windows 7 that I would like it to do the same thing: namely, to reboot the PC after it finishes saving its memory contents to disk instead of powering off like it normally would in a hibernation situation.

Is there any way to do this?

4
  • I don't think there is built-in functionality for this in Windows (certainly not from the GUI at least), as it is counter-intuitive for the 99.9% of users who don't dual boot. If you switch OS's regularly, you might want to consider creating a virtual machine for one of them (using VirtualBox or VMware), then the guest OS can be started/stopped as often as you like, and you can work on both host and guest OS at the same time.
    – Spectre
    May 25, 2011 at 15:26
  • 1
    @Spectre: Unfortunately, one of my main reasons for preferring a dual-boot over a VM solution is that I need native 3D graphics performance. I've tried Windows 7 in both VirtualBox and VMware Workstation, but good guest Direct3D support is nonexistent in the former (for DX10+ anyway) and unbearably slow and crashy in the latter (it would seem they got Aero working and left it at that). If VM graphics performance were decent I would switch to a purely VM solution in a snap.
    – jgottula
    May 25, 2011 at 19:25
  • Does this mean that you use the Linux OS most of the time? If you use them about equally or could otherwise stand this, why not put Linux in the VM?
    – Daniel H
    May 26, 2011 at 21:47
  • You're right, using Windows as the host would get around some of the VM limitations, but I use Linux the vast majority of the time (and I'm probably too much of a Linux snob anyway), so I'm really looking for a primarily-Linux, secondarily-Windows solution.
    – jgottula
    May 27, 2011 at 12:01

4 Answers 4

1

You can't do what you want because Windows always assumes there are no other non-Windows operating systems on your machine.

So long as the Windows bootloader (NTLDR or BOOTMGR, regardless) is installed to the MBR, (re)starting the machine after a hibernation will always resume from the hibernation data on disk and will not prompt you to select an OS to boot from. This is because mounting a volume that was mounted in the hibernated OS from any other OS or environment is undefined behavior. At the best case, when you then attempt to boot into the hibernated OS after mounting one of its volumes in Linux or another Windows install will detect the hibernation data as invalid and refuse to boot from it. In the worst case scenario, it'll boot from the hibernation store and there will be an inconsistent filesystem data in memory vs on disk and your volumes may be corrupted beyond repair (and I speak from experience on this one).

As such, Windows (somewhat rightly) assumes that restarting (instead of shutting down) after a hibernation is pointless, as it would simply result in the machine being in the same state it was before hibernation with nothing achieved and 5 minutes of your time lost.

Now, of course, if a non-BOOTMGR/NTLDR bootloader is installed to the MBR you can accomplish a hibernation of Windows and a boot of a different OS (though you must not modify any volumes that were mounted under the now-hibernated OS or else risk severe data loss). But Windows knows nothing of this (whether or not this is purposely ignored is a topic for another day). So the short answer is that we're trying to do isn't possible without a (para)virtualization environment of some sort.

If you're often switching between OSes and trying to go back to where you were, consider using VMware workstation or even ES(I|X) to boot into multiple OSes at once. Else, a KVM solution like the one @WillGunn suggested isn't a bad option.

1

I too have been looking for a clean way to do this and haven't found one yet. I have found a bit of a hack though that others might be interested in...

The key to the hack is the xbootmgr tool from Microsoft. This tool is designed primarily for developers to gather timing information to figure out what's slowing down booting. As an added bonus, it wires the system up to automatically reboot once you hibernate. The tool is part of the Windows Performance Tools which you install via the Windows SDK. At least on my system, it takes the system about a minute to wake back up from the suspend state, which is a little annoying, but it works. YMMV.

As others have mentioned, don't try to mount your NTFS R/W in linux once hibernated.

My experience is with UEFI based booting. This theoretically should work with MBR/BIOS based bootloaders, but you'll have to use GRUB or some other non-windows bootloader in the MBR to avoid the "auto resume" feature of that bootloader (whenever it detects a hibernated system it ignores any other boot options you may have added for Linux.) If you go the grub/MBR route, take a look at the grub-reboot command to pop over to Windows for one boot cycle.

UEFI With Windows Primary

If you spend most of your time in Windows and have it set as your default boot option, you'll need a tool on the windows side to toggle your Linux install to "boot once" - something like EasyUEFI. When you want to hibernate and reboot to Linux you'll toggle it to boot once.

After toggling the boot-once flag, then as admin, run:

xbootmgr -trace hibernate

If you wired it up correctly, you should wind up in your Linux environment exactly one time, and once you reboot again, you'll find yourself back in windows, resumed from your prior hibernated state.

UEFI With Linux Primary

If you spend most of your time in Linux and have it wired up as your primary boot option, you can skip the UEFI tool on the windows side described above. You'll instead use something like efibootmgr. First you need to figure out which boot entry maps to windows. Just run

sudo efibootmgr

And you'll see something like this:

BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0000,0001
Boot0000* ubuntu
Boot0001* Windows Boot Manager

Then to set Windows to boot once, you'd use the number that matches up (0001 in my example) with:

sudo efibootmgr --bootnext 0001

Then go ahead and hibernate/reboot from Linux, and you'll land in windows once, and when you're ready to go back to Linux, run xbootmgr on the windows side to hibernate there and you can happily toggle back and forth between the two.

1
  • I've noticed efibootmgr will stop working after doing this once. I guess it's because the kernel assumes the NVRAM state doesn't change when it hibernates? Apr 30, 2015 at 18:26
0

If your using linux most of the time, but the work you are doing on it is not intensive, you could use a secondary computer with a KVM switch to switch between the two.

Hibernation (S4) writes the contents of your memory to your harddrive. If power is lost, it can restore itself from the hibernation file. You could always force it to have a power loss, ie disconnect it after it finishes shutting down into hibernation and then choose linux on bootup.

1
  • Instead of a physical KVM, you can alternatively use Synergy to share one mouse and keyboard between two machines, and swap monitor sources. I'd advise having a WIRED LAN connection between the two machines, to avoid excessive lag on the client.
    – Stese
    Nov 15, 2018 at 13:09
0

Years have gone past since this question was asked, but I still wanted to write down my "complicated" solution. My setup is as follows:

  1. The computer is booting through grub2 and is booting into Fedora by default.
  2. In fedora I can do a one time grub menu entry change to make the computer reboot next time into windows.
  3. Both windows and Linux can be given the command to hibernate.
  4. To turn on the computer I have a ESP8266 circuit that is connected in parallel to the power button of the computer. The ESP8266 gets its power from the +5V standby of the power supply. A raspberry pi connected to the local network sends it a wifi signal that presses the power button, either a short press for wakeup or a long press for a hard reset.

With this infrastructure in place I can switch operating system and boot both locally and remotely.

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.