Last active
February 4, 2022 07:03
-
-
Save Natetronn/7c3683860741483f0bcbe329e57bbbe2 to your computer and use it in GitHub Desktop.
Linux reboot to Windows and Windows reboot to Linux scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Update the GUID's for Linux and Windows | |
# i.e. replace gnulinux-simple-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX and efi-XXXX-XXXX with your actual GUID's | |
# Add this alias to either .zshrc, .bashrc, .profile etc. Don't forget to source ~/.zshrc etc. or restart | |
alias windows="sudo sed -i -e '/saved_entry=gnulinux-simple-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/c\saved_entry=efi-XXXX-XXXX' /boot/grub/grubenv && sudo reboot" # set menuentry to Windows 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Found this solution after I created my own but, didn't get it to work. Leaving here for reference: | |
:: https://gist.github.com/erm3nda/108ee48cf3f9f2ab6db9e54fe2d6ffdb | |
:: Create a desktop shortcut and point it to this script after editing the GUID's below | |
:: This program needs the following 7 (or 9) things to work: | |
:: 1) The following GRUB setup to remember last menuentry choice: https://askubuntu.com/a/149572/403296 | |
:: 2) sed (pick one): | |
:: - choco install sed - https://community.chocolatey.org/packages/sed | |
:: - http://sourceforge.net/projects/gnuwin32/files//sed/4.2.1/sed-4.2.1-setup.exe/download - http://gnuwin32.sourceforge.net/packages/sed.htm | |
:: 3) dos2unix (pick one): | |
:: - dos2unix via CygUtils - http://downloads.sourceforge.net/gnuwin32/cygutils-1.3.2-setup.exe :: http://gnuwin32.sourceforge.net/packages/cygutils.htm | |
:: - dos2unix - https://sourceforge.net/projects/dos2unix/ | |
:: 4) LinuxFS for Windows by Paragon - https://dl.paragon-software.com/demo/linuxwin_trial.msi :: Trial just slow down speed, is OK for us :: https://www.paragon-software.com/home/linuxfs-windows/ | |
:: - Aside, one could move /boot to its own FAT32 or NTFS partion and rework fstab etc, if you don't want to rely on LinuxFS for ext4 support. | |
:: - Once working remove extmounter and update drive letters and paths accordingly etc. Google how to do this for your particular OS/PC | |
:: 5) Make sure sed, dos2unix and extmounter are in the PATH Env Var by running them in CMD or PowerShell. | |
:: - note: if installing sed via chocolatey, it should already be set via its shimming system, at least in theory. | |
:: 6) Update the following variable values: | |
:: - Replace with your own Windows and Linux menuentry id's respectivly; id's found in /boot/grub/grub.cfg or custom.cfg etc. or in /boot/grub/grubenv saved_entry var after booting into each OS. | |
SET windows=efi-XXXX-XXXX | |
SET linux=gnulinux-simple-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX | |
:: 7) Update disk# & volume# with your own. Use LinuxFS for Windows (or similiar) to find disk# and volume# (partition.) | |
:: - Choose a drive letter (capitalized) that's not already in use or commonly used. | |
SET disk=disk2 | |
SET volume=volume3 | |
SET driveletter=Z | |
:: 8) May need full path to extmounter, if not in PATH System Variable i.e. "C:\Program Files (x86)\Paragon Software\LinuxFS for Windows\extmounter" | |
extmounter /mount %disk% %volume% %driveletter%: | |
:CheckForFile | |
IF EXIST "%driveletter%:/boot/grub/grubenv" GOTO FoundIt | |
GOTO CheckForFile | |
:FoundIt | |
:: sed find and replace - add source link | |
sed -i -e "/saved_entry=%windows%/c\saved_entry=%linux%" %driveletter%:/boot/grub/grubenv | |
:: sed truncate grubenv to required 1024kb - https://unix.stackexchange.com/a/459528/34644 | |
sed -Ez -i -- "s/^(.{1024}).*/\1/" %driveletter%:/boot/grub/grubenv | |
:: dos2unix (d2u) to change line breaks from Windows CR+LF to Unix LF otherwise we get "error: Environment block is too small" | |
:: fix here: https://forum.manjaro.org/t/environment-block-is-too-small/42139 | |
:: To test d2u is working use git-bash and find, see first update here - https://stackoverflow.com/a/46548284/585191 | |
:: Summary CR+LF vs CR vs LF - https://stackoverflow.com/a/39259747/585191 | |
dos2unix %driveletter%:/boot/grub/grubenv | |
GOTO UnMount | |
:UnMount | |
:: 9) May need full path to extmounter, if not in PATH System Variable i.e. "C:\Program Files (x86)\Paragon Software\LinuxFS for Windows\extmounter" | |
extmounter /umount %disk% %volume% | |
echo press enter to reboot | |
pause | |
shutdown -r -t 00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment