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
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.
-
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).
Skip this phase if you already have a swap partition or swapfile larger than your RAM.
sudo dd if=/dev/zero of=/swapfile bs=1M count=32768 status=progress
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
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.
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
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=...
- Edit /etc/mkinitcpio.conf
- Find HOOKS=(...) and add resume after filesystems.
HOOKS=(base udev ... block filesystems resume fsck) NOTE: "resume" must be BETWEEN filesystem & fsck
- Apply Changes:
sudo mkinitcpio -P
-
Edit
/etc/default/grub -
Append the UUID and physical offset from Phase 2 to GRUB_CMDLINE_LINUX_DEFAULT.
-
Update GRUB:
sudo update-grub -
Configure Initramfs: Create/edit
/etc/initramfs-tools/conf.d/resumeand add:
RESUME=UUID=your-swap-partition-uuid
Apply Changes: sudo update-initramfs -u
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).
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
-
Boot into Windows. (Tips: you can just use
switch-to-windowsand make sure it works) -
Open Control Panel -> Hardware and Sound -> Power Options
-
Click "Choose what the power buttons do"
-
Click "Change settings that are currently unavailable" (Shield Icon)
-
UNCHECK "Turn on fast startup"
-
CHECK "Hibernate" (Enables hibernate option in start)
-
Save changes.
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.
-
Open Start Menu.
-
Click Hibernate. (WARNING: DO NOT click Shutdown or Restart)
Result: Windows saves state and powers off. Press Power Button to boot Linux.