Skip to content

Written tutorial with samples by me on creating a toolset/workflow to seamlessly toggle between Linux and Windows sessions without closing applications.

License

Notifications You must be signed in to change notification settings

CWZMorro/linux-windows-switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Linux & Windows Hibernation Loop

This repository contains the configuration needed to maintain active sessions on both Arch Linux and Windows simultaneously. You can hibernate one OS, boot into the other, and switch back and forth without ever closing your apps.

This repository documents the configuration and scripts required to establish a seamless dual-boot hibernation loop between Linux and Windows on UEFI systems.

Here's a tool version if you don't want to go through the entire process yourself: https://github.com/CWZMorro/swap-OS

Requirements

Firmware: UEFI System (Legacy BIOS is not supported).

Storage: Enough disk space on Linux for a Swapfile equal to your RAM size.

Permissions(obviously): Root/Sudo access on Linux, Administrator access on Windows.

Bootloader: Systemd-boot or GRUB.

Limitations

  • Only supports 2 Operating Systems

    Edit: Read https://github.com/CWZMorro/swap-OS/wiki if you want support for multiple OS

  • Only Arch has been officially tested. Other distros are untested but they should work. (Feel free to try on your own and let me know if there is any problem)

Filesystem Safety (ATTENTION!!): You must never mount your Windows partitions (C: or D:) as Read-Write inside Linux while Windows is hibernated (unless you know you are doing).

Step 1: Swapfile Setup

Skip this phase if you already have a swap partition or swapfile larger than your RAM.

Create the Swapfile (Example for 32GB RAM):

1. Create the empty file (Count = RAM size in MB)

sudo dd if=/dev/zero of=/swapfile bs=1M count=32768 status=progress

2. Set permissions (Critical for security)

sudo chmod 600 /swapfile

3. Format as swap

sudo mkswap /swapfile

4. Activate

sudo swapon /swapfile

Make it Persistent:

Add the following line to /etc/fstab:

(anywhere will do but I put it at the lowest line)

/swapfile none swap defaults 0 0

You can test it by using systemctl hibernate. If your PC turns off, and when you turn it back on, your windows are still open, then it worked.

Step 2: Edit Boot Entry

Run the included helper script to calculate your UUID and physical offset automatically:

chmod +x scripts/get_resume_params.sh

./scripts/get_resume_params.sh

Output Example: resume=UUID=a1b2c3d4-... resume_offset=34816

Step 3: Boot Configuration

Systemd (Arch or if you use systemd)

Edit Boot Entry:

Open your loader config (usually /boot/loader/entries/arch.conf or linux.conf). Append the UUID and physical offset from Phase 2 to the end of the options line.

options root=PARTUUID=... rw resume=UUID=... resume_offset=...

Add Resume Hook:

  1. Edit /etc/mkinitcpio.conf
  2. Find HOOKS=(...) and add resume after filesystems.

HOOKS=(base udev ... block filesystems resume fsck) NOTE: "resume" must be BETWEEN filesystem & fsck

  1. Apply Changes:

sudo mkinitcpio -P

GRUB (Debian/Ubuntu/Mint....)

  1. Edit /etc/default/grub

  2. Append the UUID and physical offset from Phase 2 to GRUB_CMDLINE_LINUX_DEFAULT.

  3. Update GRUB: sudo update-grub

  4. Configure Initramfs: Create/edit /etc/initramfs-tools/conf.d/resume and add:

RESUME=UUID=your-swap-partition-uuid

Apply Changes: sudo update-initramfs -u

GRUB + Dracut (Fedora..)

Edit Boot Args: Edit /etc/default/grub. Append UUID and physical offset from Phase 2 to GRUB_CMDLINE_LINUX

Apply Changes: sudo grub2-mkconfig -o /boot/grub2/grub.cfg (Fedora usually detects resume args automatically for dracut I think).

Step 4: The Switch Script

Create a script at /usr/local/bin/switch-to-windows (or any name you want) with the following content.

#!/bin/bash
# Unmounts Windows drives, sets boot flag, and hibernates.

# 1. SAFETY CHECK: Unmount Windows drives
# If the Windows partition is mounted when you hibernate, the filesystem
# will corrupt. This line forcibly unmounts partitions on the standard NVMe.
# EDIT THIS: Change '/dev/nvme0n1*' to match your Windows drive if different.
sudo umount /dev/nvme0n1* 2>/dev/null

# 2. FIND WINDOWS BOOT ID
# Uses efibootmgr to find the hex code (e.g., 0009) for "Windows Boot Manager"
WIN_ID=$(efibootmgr | grep "Windows Boot Manager" | grep -oP 'Boot\K[0-9A-F]+')

if [ -z "$WIN_ID" ]; then
    echo "Error: Windows Boot Manager entry not found in UEFI."
    exit 1
fi

echo "Windows found at ID: $WIN_ID"
echo "Setting next boot target..."

# 3. SET NEXT BOOT FLAG
# This tells the motherboard to boot Windows ONE time only.
sudo efibootmgr --bootnext $WIN_ID

# 4. HIBERNATE
echo "Hibernating..."
systemctl hibernate

Make it executable:

sudo chmod +x /usr/local/bin/switch-to-windows

Step 5: Windows Configuration

  1. Boot into Windows. (Tips: you can just use switch-to-windows and make sure it works)

  2. Open Control Panel -> Hardware and Sound -> Power Options

  3. Click "Choose what the power buttons do"

  4. Click "Change settings that are currently unavailable" (Shield Icon)

  5. UNCHECK "Turn on fast startup"

  6. CHECK "Hibernate" (Enables hibernate option in start)

  7. Save changes.

How to Use

Switching from Linux -> Windows

Run the script (or bind it to a hotkey):

switch-to-windows

Result: Linux saves state and powers off. Press Power Button to boot Windows.

Switching from Windows → Linux

  1. Open Start Menu.

  2. Click Hibernate. (WARNING: DO NOT click Shutdown or Restart)

Result: Windows saves state and powers off. Press Power Button to boot Linux.

Note: If your time is not sync in windows/linux remember to do so or the time will be inaccurate.

About

Written tutorial with samples by me on creating a toolset/workflow to seamlessly toggle between Linux and Windows sessions without closing applications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages