Skip to content

Instantly share code, notes, and snippets.

@slikts
Last active May 9, 2025 22:30
Show Gist options
  • Select an option

  • Save slikts/63abbeb63b72b3f515c70258bfc19a44 to your computer and use it in GitHub Desktop.

Select an option

Save slikts/63abbeb63b72b3f515c70258bfc19a44 to your computer and use it in GitHub Desktop.

Revisions

  1. slikts revised this gist Mar 23, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <p align=center><a href=https://nelabs.dev><img src=https://nelabs.dev/logo.svg width=450 alt=nelabs.dev></a></p>

    # Linuxifying Windows for development

    This guide is for 'linuxing-up' Windows as a development environment; it focuses on setting up [WSL], an Ubuntu [Hyper-V] virtual machine, [wsltty] (a nice terminal emulator) and various tweaks.
  2. slikts revised this gist Nov 4, 2019. 1 changed file with 24 additions and 2 deletions.
    26 changes: 24 additions & 2 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,40 @@
    # Linuxifying Windows for development

    This guide is for 'linuxing-up' Windows as a development environment; it focuses on setting up [WSL], an Ubuntu Hyper-V virtual machine, [wsltty] (a nice terminal emulator) and various tweaks.
    This guide is for 'linuxing-up' Windows as a development environment; it focuses on setting up [WSL], an Ubuntu [Hyper-V] virtual machine, [wsltty] (a nice terminal emulator) and various tweaks.

    [Hyper-V]: https://en.wikipedia.org/wiki/Hyper-V

    ## Rationale

    ### Why use both WSL and a Hyper-V VM
    For the same reason why the upcoming WSL version 2 uses Hyper-V – the [i/o performance] in WSL 1 is several-fold slower than in a VM, which means that build or install processes take longer.

    For the same reason why the upcoming [WSL version 2][wsl2] uses Hyper-V – the [i/o performance] in WSL 1 is several-fold slower than in a VM, which means that build or install processes take longer.

    WSL 2 is currently only available in Windows Insider Preview builds, so it's not suitable for users that aren't keen on being early adopters. Linuxifying Windows stable builds will be significantly more simple once WSL 2 is available.

    Another notable perk of using a Hyper-V VM over WSL 1 is that the VM's state gets automatically saved when powering off the host, reducing disruption to development.

    [wsl2]: https://docs.microsoft.com/en-us/windows/wsl/wsl2-faq

    ### Why Hyper-V over VirtualBox or VMWare Player

    Hyper-V's dynamic memory feature means that a smaller initial amount of memory can be reserved for the guest OS and then automatically increased if required (and also reclaimed later). In comparison, VirtualBox has a "memory ballooning" feature, but it can only re-distribute a fixed amount of memory between guests.

    VirtualBox has better support for graphics acceleration in guests, but it's not required when the guests are used as headless servers.

    ### Hyper-V caveats

    Enabling Hyper-V prevents the use of VMware or VirtualBox versions prior to VirtualBox 6, because Hyper-V is a [Type 1 hypervisor][classification] and reserves direct access to the hardware virtualization technology (VT-x or AMD-V).

    Hyper-V makes Windows run as a virtualized guest, [which adds][perf] a 9–12% CPU overhead and a 6–8% i/o overhead and can make a noticeable difference in resource-constrained scenarios (notably, games).

    [classification]: https://en.wikipedia.org/wiki/Hypervisor#Classification
    [perf]: https://docs.microsoft.com/en-us/biztalk/technical-guides/system-resource-costs-on-hyper-v

    ## WSL and wsltty

    ### Installation

    1. [Chocolatey]
    1. [wsltty]
    ```
    @@ -52,9 +68,11 @@ Install the [Remote Development] extension pack in VS Code and it'll allow to ju
    > `Win+R`, `optionalfeatures`, select Hyper-V.
    ### Creating the VM

    Run Hyper-V Manager, *Quick Create…*, select Ubuntu 19.04, follow the wizard, run the created virtual machine, finish initial setup with default settings.

    ### Networking tweaks

    The virtual machine is only connectable from the host OS by default; to make it connectable from the LAN, an external virtual switch needs to be created:

    > Hyper-V Manager, Actions, *Virtual Switch Manager…*, External, *Create Virtual Switch*, select the NIC connected to LAN.
    @@ -66,11 +84,13 @@ To make the IP static:
    > *Advanced Features* under Network Adapter, select static MAC address radio option.
    ### Autostart

    By default the VM will autostart with the OS only if the VM was running when the OS shut down; to make it autostart always:

    > *Settings…* for the created virtual machine, *Automatic Start Action* under Management, *Always start this virtual machine automatically*.
    ### Sharing files with host OS

    In VM terminal:
    ```
    sudo apt install samba
    @@ -96,6 +116,7 @@ In Windows:
    The same steps to set up SSH connections from Windows could also be repeated within WSL.

    ### Running Ubuntu without desktop environment

    ```
    sudo systemctl set-default multi-user.target
    ```
    @@ -120,3 +141,4 @@ Different icons can be set for the shortcuts to make telling the VM and WSL term
    [Remote Development]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
    [i/o performance]: https://github.com/microsoft/WSL/issues/873
    [WSL]: https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux

  3. slikts revised this gist Jul 28, 2019. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    # Linuxifying Windows for development

    This guide is for 'linuxifying' Windows as a development environment; it focuses on setting up [WSL], an Ubuntu Hyper-V virtual machine, [wsltty] (a nice terminal emulator) and various tweaks.
    This guide is for 'linuxing-up' Windows as a development environment; it focuses on setting up [WSL], an Ubuntu Hyper-V virtual machine, [wsltty] (a nice terminal emulator) and various tweaks.

    ## Rationale

    ### Why use both WSL and a Hyper-V VM
    For the same reason why the upcoming WSL version 2 uses Hyper-V – the [i/o performance] in WSL 1 is several-fold slower than in a VM, which means that build/install processes take longer.
    For the same reason why the upcoming WSL version 2 uses Hyper-V – the [i/o performance] in WSL 1 is several-fold slower than in a VM, which means that build or install processes take longer.

    WSL 2 is currently only available in Windows Insider Preview builds, so it's not suitable for users that aren't keen on being early adopters. Linuxifying Windows stable builds will be significantly more simple once WSL 2 is available.

    Another notable perk of using a Hyper-V VM over WSL 1 is that the VM's state gets automatically saved when powering off the host, reducing disruption to development.

    ### Why Hyper-V over VirtualBox or VMWare Player
    Hyper-V's dynamic memory feature means that a smaller initial amount of memory can be reserved for the guest OS and then automatically increased if required (and also reclaimed later). In comparison, VirtualBox has a "memory ballooning" feature, but it can only re-distribute a fixed amount of memory between guests.

    @@ -106,11 +108,11 @@ Windows shortcut target to automatically connect to a tmux session named 'main'
    ```
    %LocalAppData%\wsltty\bin\mintty.exe --WSL= --configdir="C:\Users\dabas\AppData\Roaming\wsltty" -~ -R o -e tmux new -A -s main
    ```

    Windows shortcut target to automatically connect to a tmux session named 'main' in the VM (replace `VM_HOST_NAME`):
    ```
    %LocalAppData%\wsltty\bin\mintty.exe --WSL= --configdir="C:\Users\dabas\AppData\Roaming\wsltty" -~ -R o -e ssh -t <VM_HOST_NAME> "tmux new -A -s main"
    ```
    Different icons can be set for the shortcuts to make telling the VM and WSL terminals apart easier when both are running.

    [OpenSSH]: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
    [Chocolatey]: https://chocolatey.org/
  4. slikts revised this gist Jul 25, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Linuxifying Windows for development

    This guide is for 'linuxifying' Windows as a development environment; it focuses on setting up WSL, an Ubuntu Hyper-V virtual machine, wsltty (a nice terminal emulator) and various tweaks.
    This guide is for 'linuxifying' Windows as a development environment; it focuses on setting up [WSL], an Ubuntu Hyper-V virtual machine, [wsltty] (a nice terminal emulator) and various tweaks.

    ## Rationale

    @@ -117,3 +117,4 @@ Windows shortcut target to automatically connect to a tmux session named 'main'
    [wsltty]: https://github.com/mintty/wsltty
    [Remote Development]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
    [i/o performance]: https://github.com/microsoft/WSL/issues/873
    [WSL]: https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux
  5. slikts revised this gist Jul 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ For the same reason why the upcoming WSL version 2 uses Hyper-V – the [i/o per
    WSL 2 is currently only available in Windows Insider Preview builds, so it's not suitable for users that aren't keen on being early adopters. Linuxifying Windows stable builds will be significantly more simple once WSL 2 is available.

    ### Why Hyper-V over VirtualBox or VMWare Player
    Hyper-V dynamic memory feature means that a smaller initial amount of memory can be reserved for the guest OS and then automatically increased if required (and also reclaimed later). In comparison, VirtualBox has a "memory ballooning" feature, but it can only re-distribute a fixed amount of memory between guests.
    Hyper-V's dynamic memory feature means that a smaller initial amount of memory can be reserved for the guest OS and then automatically increased if required (and also reclaimed later). In comparison, VirtualBox has a "memory ballooning" feature, but it can only re-distribute a fixed amount of memory between guests.

    VirtualBox has better support for graphics acceleration in guests, but it's not required when the guests are used as headless servers.

  6. slikts revised this gist Jul 25, 2019. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -14,9 +14,6 @@ Hyper-V dynamic memory feature means that a smaller initial amount of memory can

    VirtualBox has better support for graphics acceleration in guests, but it's not required when the guests are used as headless servers.

    #### Note
    Hyper-V is often described as just a type 1 hypervisor (running on bare metal), but it's actually only type 1 in Windows Server; in Windows Pro Hyper-V works as a type 2 hypervisor (runs inside the OS).

    ## WSL and wsltty

    ### Installation
  7. slikts revised this gist Jul 25, 2019. No changes.
  8. slikts revised this gist Jul 25, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -80,10 +80,10 @@ sudo vim /etc/samba/smb.conf
    Uncomment `[homes]` section and change `read only` to `no` under it.
    ```
    sudo systemctl restart nmbd
    smbpasswd -a yourusername
    smbpasswd -a your_username
    ```
    In Windows:
    > This PC, *Computer*, *Map Network Drive*, enter \\\vm_host_name\yourusername
    > This PC, *Computer*, *Map Network Drive*, enter \\\vm_host_name\your_username
    ### VS Code Remote Development

  9. slikts revised this gist Jul 25, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ Hyper-V is often described as just a type 1 hypervisor (running on bare metal),
    choco install wsltty
    ```
    1. WSL
    > `Win+R`, `optionalfeatures.exe`, select Windows Subsystem for Linux.
    > `Win+R`, `optionalfeatures`, select Windows Subsystem for Linux.
    ### wsltty tweaks

    @@ -50,7 +50,7 @@ Install the [Remote Development] extension pack in VS Code and it'll allow to ju
    1. Windows 10 Pro (Home doesn't support Hyper-V), version 1809 or later
    4. Hyper-V enabled in firmware and supported by CPU
    5. Hyper-V
    > `Win+R`, `optionalfeatures.exe`, select Hyper-V.
    > `Win+R`, `optionalfeatures`, select Hyper-V.
    ### Creating the VM
    Run Hyper-V Manager, *Quick Create…*, select Ubuntu 19.04, follow the wizard, run the created virtual machine, finish initial setup with default settings.
    @@ -83,7 +83,7 @@ sudo systemctl restart nmbd
    smbpasswd -a yourusername
    ```
    In Windows:
    > This PC, *Computer*, *Map Network Drive*, enter \\\vm_host_name\username
    > This PC, *Computer*, *Map Network Drive*, enter \\\vm_host_name\yourusername
    ### VS Code Remote Development

  10. slikts revised this gist Jul 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ Hyper-V dynamic memory feature means that a smaller initial amount of memory can

    VirtualBox has better support for graphics acceleration in guests, but it's not required when the guests are used as headless servers.

    #### Hyper-V note
    #### Note
    Hyper-V is often described as just a type 1 hypervisor (running on bare metal), but it's actually only type 1 in Windows Server; in Windows Pro Hyper-V works as a type 2 hypervisor (runs inside the OS).

    ## WSL and wsltty
  11. slikts revised this gist Jul 25, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ This guide is for 'linuxifying' Windows as a development environment; it focuses
    ## Rationale

    ### Why use both WSL and a Hyper-V VM
    For the same reason why the upcoming WSL version 2 uses Hyper-V – the i/o speed in WSL 1 is several-fold slower than in a VM, which means that build/install processes take longer.
    For the same reason why the upcoming WSL version 2 uses Hyper-V – the [i/o performance] in WSL 1 is several-fold slower than in a VM, which means that build/install processes take longer.

    WSL 2 is currently only available in Windows Insider Preview builds, so it's not suitable for users that aren't keen on being early adopters. Linuxifying Windows stable builds will be significantly more simple once WSL 2 is available.

    @@ -119,4 +119,4 @@ Windows shortcut target to automatically connect to a tmux session named 'main'
    [Chocolatey]: https://chocolatey.org/
    [wsltty]: https://github.com/mintty/wsltty
    [Remote Development]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack

    [i/o performance]: https://github.com/microsoft/WSL/issues/873
  12. slikts revised this gist Jul 25, 2019. 1 changed file with 0 additions and 7 deletions.
    7 changes: 0 additions & 7 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -17,13 +17,6 @@ VirtualBox has better support for graphics acceleration in guests, but it's not
    #### Hyper-V note
    Hyper-V is often described as just a type 1 hypervisor (running on bare metal), but it's actually only type 1 in Windows Server; in Windows Pro Hyper-V works as a type 2 hypervisor (runs inside the OS).

    ### Why use Windows at all
    Microsoft has changed tack significantly regarding integration with the *nix world, so Windows is increasingly a viable (or less second-class) option for development targeted at *nix platforms.

    The other two factors tipping the scales towards Windows are Linux desktop fragmentation and the unappealing Mac "pro" lineup.

    In case of the author, macOS and Windows are currently closely familiar, while Linux desktop used to be closely familiar when Unity still existed. Choosing Linux now would require the chore of picking between distros and DEs and then tweaking them, while Mac is ruled out by Apple hardware specifics (a long topic on its own) or the unreliability of Hackintosh, so it leaves using a Windows and Linux hybrid as the most convenient (albeit stigmatized) option.

    ## WSL and wsltty

    ### Installation
  13. slikts revised this gist Jul 25, 2019. No changes.
  14. slikts created this gist Jul 25, 2019.
    129 changes: 129 additions & 0 deletions Linuxifying Windows.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,129 @@
    # Linuxifying Windows for development

    This guide is for 'linuxifying' Windows as a development environment; it focuses on setting up WSL, an Ubuntu Hyper-V virtual machine, wsltty (a nice terminal emulator) and various tweaks.

    ## Rationale

    ### Why use both WSL and a Hyper-V VM
    For the same reason why the upcoming WSL version 2 uses Hyper-V – the i/o speed in WSL 1 is several-fold slower than in a VM, which means that build/install processes take longer.

    WSL 2 is currently only available in Windows Insider Preview builds, so it's not suitable for users that aren't keen on being early adopters. Linuxifying Windows stable builds will be significantly more simple once WSL 2 is available.

    ### Why Hyper-V over VirtualBox or VMWare Player
    Hyper-V dynamic memory feature means that a smaller initial amount of memory can be reserved for the guest OS and then automatically increased if required (and also reclaimed later). In comparison, VirtualBox has a "memory ballooning" feature, but it can only re-distribute a fixed amount of memory between guests.

    VirtualBox has better support for graphics acceleration in guests, but it's not required when the guests are used as headless servers.

    #### Hyper-V note
    Hyper-V is often described as just a type 1 hypervisor (running on bare metal), but it's actually only type 1 in Windows Server; in Windows Pro Hyper-V works as a type 2 hypervisor (runs inside the OS).

    ### Why use Windows at all
    Microsoft has changed tack significantly regarding integration with the *nix world, so Windows is increasingly a viable (or less second-class) option for development targeted at *nix platforms.

    The other two factors tipping the scales towards Windows are Linux desktop fragmentation and the unappealing Mac "pro" lineup.

    In case of the author, macOS and Windows are currently closely familiar, while Linux desktop used to be closely familiar when Unity still existed. Choosing Linux now would require the chore of picking between distros and DEs and then tweaking them, while Mac is ruled out by Apple hardware specifics (a long topic on its own) or the unreliability of Hackintosh, so it leaves using a Windows and Linux hybrid as the most convenient (albeit stigmatized) option.

    ## WSL and wsltty

    ### Installation
    1. [Chocolatey]
    1. [wsltty]
    ```
    choco install wsltty
    ```
    1. WSL
    > `Win+R`, `optionalfeatures.exe`, select Windows Subsystem for Linux.
    ### wsltty tweaks

    1. Install the [Fira Code] font in Windows (contains various special glyphs)
    2. Run wsltty (called "WSL Terminal" in Start Menu)
    3. Right click wsltty window title and select Options
    4. Change theme under Looks (the default theme's blue is too dark to read on black; I use the flat-ui theme)
    5. Under Text, select Fira Code, increase size as required
    6. Under Window, increase the default columns and rows so that the window doesn't need to be resized each time

    [Fira Code]: https://github.com/tonsky/FiraCode

    ### VS Code Remote Development

    Install the [Remote Development] extension pack in VS Code and it'll allow to just seamlessly run `code .` in a directory in WSL, and the launched VS Code instance will use tools like git from within WSL, allow running commands in WSL, etc.

    ## Ubuntu Hyper-V virtual machine

    ### Prerequisites

    1. Windows 10 Pro (Home doesn't support Hyper-V), version 1809 or later
    4. Hyper-V enabled in firmware and supported by CPU
    5. Hyper-V
    > `Win+R`, `optionalfeatures.exe`, select Hyper-V.
    ### Creating the VM
    Run Hyper-V Manager, *Quick Create…*, select Ubuntu 19.04, follow the wizard, run the created virtual machine, finish initial setup with default settings.

    ### Networking tweaks
    The virtual machine is only connectable from the host OS by default; to make it connectable from the LAN, an external virtual switch needs to be created:

    > Hyper-V Manager, Actions, *Virtual Switch Manager…*, External, *Create Virtual Switch*, select the NIC connected to LAN.
    > Hyper-V Manager, *Settings…* for the created virtual machine, *Network Adapter*, select the created external virtual switch as the virtual switch.
    To make the IP static:

    > *Advanced Features* under Network Adapter, select static MAC address radio option.
    ### Autostart
    By default the VM will autostart with the OS only if the VM was running when the OS shut down; to make it autostart always:

    > *Settings…* for the created virtual machine, *Automatic Start Action* under Management, *Always start this virtual machine automatically*.
    ### Sharing files with host OS
    In VM terminal:
    ```
    sudo apt install samba
    sudo vim /etc/samba/smb.conf
    ```
    Uncomment `[homes]` section and change `read only` to `no` under it.
    ```
    sudo systemctl restart nmbd
    smbpasswd -a yourusername
    ```
    In Windows:
    > This PC, *Computer*, *Map Network Drive*, enter \\\vm_host_name\username
    ### VS Code Remote Development

    1. Install the [Remote Development] extension pack in VS Code
    2. Install [Windows OpenSSH Client][OpenSSH]
    3. Run `ssh-keygen -b 4096` from Windows command line and choose the defaults
    4. Copy the contents of `%USERPROFILE%\.ssh\id_rsa.pub` to `~/.ssh/authorized_keys` in the VM
    5. Run `chmod 600 ~/.ssh/authorized_keys` in the VM
    6. Go to Remote-SSH in VS Code, choose `%USERPROFILE%\.ssh\config` and enter the VM host name

    The same steps to set up SSH connections from Windows could also be repeated within WSL.

    ### Running Ubuntu without desktop environment
    ```
    sudo systemctl set-default multi-user.target
    ```

    ## tmux shortcuts

    Run `sudo apt install tmux` in either the VM or WSL.

    Windows shortcut target to automatically connect to a tmux session named 'main' in WSL:
    ```
    %LocalAppData%\wsltty\bin\mintty.exe --WSL= --configdir="C:\Users\dabas\AppData\Roaming\wsltty" -~ -R o -e tmux new -A -s main
    ```

    Windows shortcut target to automatically connect to a tmux session named 'main' in the VM (replace `VM_HOST_NAME`):
    ```
    %LocalAppData%\wsltty\bin\mintty.exe --WSL= --configdir="C:\Users\dabas\AppData\Roaming\wsltty" -~ -R o -e ssh -t <VM_HOST_NAME> "tmux new -A -s main"
    ```

    [OpenSSH]: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
    [Chocolatey]: https://chocolatey.org/
    [wsltty]: https://github.com/mintty/wsltty
    [Remote Development]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack