Code Monkey home page Code Monkey logo

toggle-wsl's Introduction

Toggle-WSL

A PowerShell 5 script to automate toggling WSL and Hyper-V related virtualization features on Windows 10/11 Pro.

Usage

powershell .\toggle-wsl.ps1

You can make the script easily accessible by creating a shortcut: right click on your desktop -> New -> Shortcut, type powershell <full-path-to-script>\toggle-wsl.ps1 in the Path field. You can now launch the script by double clicking on the shortcut.

If you have the new Windows Terminal installed you can instead type wt powershell <full-path-to-script>\toggle-wsl.ps1 in the Path field.

The script expects to find at least one enabled feature. It will not work if all features are already disabled, as there is no saved state to restore! Keep reading to figure out why.

Why

A reply to this stackoverflow thread explains why this script exists:

VirtualBox and VMware Workstation (and VMware Player) are "level 2 hypervisors". Hyper-V and VMware ESXi are "level 1 hypervisors".
The main difference is that a level 2 hypervisor is an application running inside an existing OS, while a level 1 hypervisor is the OS itself.
This means that when you enable Hyper-V, your Windows 10 "host" becomes a virtual machine. A special one, but nonetheless a virtual machine.
So your question would more aptly be: "Why don't VirtualBox and VMware Workstation work inside a Hyper-V virtual machine?" One can answer because as a VM, the Intel VT-X instruction are no longer accessible from your virtual machine, only the host has access to it.

How it works

The script is meant to be an easy tool to toggle between Hyper-V/Windows Subsystem for Linux and other virtualization software (VMware, VirtualBox, etc...)

The script looks for enabled Windows optional features known to cause problems with other virtualization software. It saves their state to a .json file, then proceeds to disable them and reboot the system. At this point you can use VMware/VirtualBox/others.
When you want to restore features to the precedent state, re-run the script. The script will read the .json file, re-enabling only those features that were previously enabled, and then reboot the system.
NOTE: if WSL is to be enabled, two reboots are required for it to work properly. The script will detect this and will do it for you.

List of supported features

  • Hyper-V
  • Windows Hypervisor Platform
  • Virtual Machine Platform
  • Windows Subsystem for Linux
  • Windows Sandbox

Feedback is welcome! If you find any other feature you believe should be disabled but the script does not, please open an issue and I'll gladly add it to the list.

Changelog

See CHANGELOG.md.

License

This project is licensed under the MIT License - see the LICENSE file for more details

toggle-wsl's People

Contributors

lynxnb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.