Skip to content
Utku Üstüner edited this page Oct 6, 2022 · 1 revision

Tweaks For WSL

I'll help you set up WSL and add storage from another drive to WSL so you won't fill up your Windows drive.

Installing WSL

  1. First things first, if you don't have WSL installed open up a terminal and type wsl --install

    • This will enable Virtual Machine Platform (cut down version of hyper-v) and Windows Subsystem for Linux. If command fails enable these manually.
    • After those are complete it'll download and install Ubuntu. Again, if it failed install it from windows store manually.
  2. Once you're back on desktop a terminal window will open and ask you to create a user. Do that and you're done.

If you didn't read any of the GSI building guides linked above, GO DO THAT.

After you've totally read those guides you can use ready-distro.sh to ready your ubuntu instance for building.

Adding Storage To WSL

Now that WSL is installed let's add that drive. For the next part you don't have to install Hyper-V but it'll make things simpler if you do.

  1. Enable Hyper-V from "Turn Windows features on or off" menu and restart when prompted to.

  2. After reboot, search for Hyper-V Manager in the search and open up the app.

  3. On the right side of app click New, then Hard Disk. Click Next and choose the options that suits you the best.

    • I recommend VHDX and Dynamically expanding.
    • The location of this file is important because there is no point in placing it in C drive.
    • At last part you select size for this file, if you selected Dynamic VHDX it'll be the maximum size. Not the initial one.
  4. Click Finish and go to the vhdx location. Open up a powershell terminal as admin and type this : Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path ./ext4.vhdx -PassThru | Get-Disk).Number)"

    • It should print something like this : \\.\PhysicalDrive2
  5. Type this wsl --mount \\.\PhysicalDriveX --bare but switch X with the number it gave you.

  6. Now open your ubuntu instance and type lsblk

    • It should give you list of drives. There is a high chance that your virtual drive will be sdc or sdd. Figure it out with the size of it.
  7. Now type sudo mkfs -t ext4 /dev/sdX and change X with yours.

    • If you've done it correctly your .vhdx file should increase in size to about 3gb when the process is done.

Next is to make it mount to a folder of your choosing.

  1. Type sudo blkid and note down UUID of your drive.

  2. Modify your fstab with sudo nano /etc/fstab and add the following line to end: UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /home/username/foldername ext4 defaults,nofail 0 0

    • Xs will be your UUID. I mounted it in my home directory but you can mount to somewhere else like /mnt/vhdx.
    • Make sure to create the folder you're mounting to.
    • WSL already mounts it in /mnt/PhysicalDriveX so it's better to put it somewhere memorable.
  3. Type sudo mount -a to apply fstab changes.

  4. Wherever you mount it to you won't have RW access so to change that type sudo chown $USER:$USER /home/username/foldername

Now if you've done it correctly, whatever you put inside this folder will occupy space in the drive which has the vhdx file.

  1. To move this vhdx file you need to unmount it with wsl --unmount \\.\PhysicalDriveX .

    • If you still can't move it open Disk Management by right clicking Windows logo and right click the drive with blue logo from bottom. Click Detach VHD. Now you should be able to move it freely.
  2. After you've moved it type the command with Write-Output from above and mount it with wsl --mount \\.\PhysicalDriveX

Everytime you reboot you have to mount it again with the command above. To overcome this you can edit Windows Terminal profile of Ubuntu.

In my oppinion clone my repo to the vhdx mount point and set OUT_DIR to a folder in your home folder. That way repo will be ready to use when you switch OS.

Clone this wiki locally