Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
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 '11 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 '11 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 '11 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 '11 at 12:01

3 Answers 3

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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