<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WSL &#8211; Made For Cloud</title>
	<atom:link href="https://madeforcloud.com/category/wsl/feed/" rel="self" type="application/rss+xml" />
	<link>https://madeforcloud.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 24 Dec 2024 06:03:54 +0000</lastBuildDate>
	<language>en-AU</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>Compacting WSL hard disk</title>
		<link>https://madeforcloud.com/2024/12/24/compacting-wsl-hard-disk/</link>
					<comments>https://madeforcloud.com/2024/12/24/compacting-wsl-hard-disk/#respond</comments>
		
		<dc:creator><![CDATA[gocallag]]></dc:creator>
		<pubDate>Tue, 24 Dec 2024 06:03:54 +0000</pubDate>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[WSL]]></category>
		<guid isPermaLink="false">https://madeforcloud.com/?p=233</guid>

					<description><![CDATA[Like many people I am an extensive user of WSL and Linux under Windows in general. It&#8217;s the only real option I have at work and it&#8217;s quite a reasonable proposition. That being said though, the WSL vhdx files can grow as you&#8217;re doing Linux work and while you can (and should) clean up side&#8230;<p><a class="more-link" href="https://madeforcloud.com/2024/12/24/compacting-wsl-hard-disk/" title="Continue reading &#8216;Compacting WSL hard disk&#8217;">Continue reading <span class="meta-nav">&#8594;</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p>Like many people I am an extensive user of WSL and Linux under Windows in general. It&#8217;s the only real option I have at work and it&#8217;s quite a reasonable proposition.</p>



<p>That being said though, the WSL vhdx files can grow as you&#8217;re doing Linux work and while you can (and should) clean up side the Linux environment it&#8217;s not reflected back to windows as free space.</p>



<p>So how do you compact your WSL file?</p>



<ol class="wp-block-list">
<li>Shutdown your WSL system.<br><br><code>wsl.exe --list --verbose   # note the verbose is required to get the state</code> <br><img fetchpriority="high" decoding="async" width="600" height="93" class="wp-image-235" style="width: 600px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-163339.png" alt="Output from wsl.exe to show running WSL environment" srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-163339.png 757w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-163339-300x46.png 300w" sizes="(max-width: 600px) 100vw, 600px" /><br><br><code>wsl.exe --terminate Ubuntu-24.04</code><br><img decoding="async" width="600" height="137" class="wp-image-238" style="width: 600px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-163855.png" alt="This shows the output of the wsl command with the instance being terminated" srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-163855.png 750w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-163855-300x68.png 300w" sizes="(max-width: 600px) 100vw, 600px" /><br></li>



<li>Shrink the disk using <strong>diskpart</strong><br><br><code>diskpart</code><br><br><img decoding="async" width="600" height="226" class="wp-image-239" style="width: 600px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164232.png" alt="The diskpart dialogue is displayed" srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164232.png 617w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164232-300x113.png 300w" sizes="(max-width: 600px) 100vw, 600px" /><br><br>You need to <strong>select</strong> the vhdx file for your WSL instance.  The VHDX file is typically found in your <strong>AppData</strong> folder. In my case it was this.<br><br><img loading="lazy" decoding="async" width="800" height="158" class="wp-image-240" style="width: 800px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716.png" alt="Windows explorer show the location of my VHDX file" srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716.png 1500w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716-300x59.png 300w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716-1024x202.png 1024w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716-768x152.png 768w" sizes="auto, (max-width: 800px) 100vw, 800px" /><br><br>I copy the VHDX file location as a path.<br><br><img loading="lazy" decoding="async" width="800" height="407" class="wp-image-241" style="width: 800px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164903.png" alt="The easiest way to get the full filename + path is to use explorer to copy as path" srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164903.png 1045w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164903-300x153.png 300w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164903-1024x521.png 1024w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164903-768x391.png 768w" sizes="auto, (max-width: 800px) 100vw, 800px" /><br><br>DISKPART> <code>select vdisk file="C:\Users\geoff\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu24.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx"</code><br><br><img loading="lazy" decoding="async" width="800" height="66" class="wp-image-242" style="width: 800px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165237.png" alt="Output from selecting the vdisk in diskpart
" srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165237.png 1662w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165237-300x25.png 300w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165237-1024x84.png 1024w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165237-768x63.png 768w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165237-1536x127.png 1536w" sizes="auto, (max-width: 800px) 100vw, 800px" /><br></li>



<li>Compact the vdisk<br><br>DISKPART> <code>compact vdisk</code><br><br><img loading="lazy" decoding="async" width="800" height="168" class="wp-image-243" style="width: 800px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165742.png" alt="output of diskpart compact " srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165742.png 600w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165742-300x63.png 300w" sizes="auto, (max-width: 800px) 100vw, 800px" /><br></li>



<li>The results.<br><br>BEFORE<br><br><img loading="lazy" decoding="async" width="800" height="158" class="wp-image-240" style="width: 800px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716.png" alt="Explorer vhdx filesize before compact" srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716.png 1500w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716-300x59.png 300w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716-1024x202.png 1024w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-164716-768x152.png 768w" sizes="auto, (max-width: 800px) 100vw, 800px" /><br><br>AFTER<br><br><img loading="lazy" decoding="async" width="800" height="175" class="wp-image-244" style="width: 800px;" src="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165909.png" alt="Explorer vhdx file size after compact" srcset="https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165909.png 1078w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165909-300x66.png 300w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165909-1024x224.png 1024w, https://madeforcloud.com/wp-content/uploads/2024/12/Screenshot-2024-12-24-165909-768x168.png 768w" sizes="auto, (max-width: 800px) 100vw, 800px" /><br><br>As you can see, i&#8217;ve freed up nearly 6Gb.<br></li>
</ol>
]]></content:encoded>
					
					<wfw:commentRss>https://madeforcloud.com/2024/12/24/compacting-wsl-hard-disk/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Getting WSL2 just right</title>
		<link>https://madeforcloud.com/2024/06/30/getting-wsl2-just-right/</link>
					<comments>https://madeforcloud.com/2024/06/30/getting-wsl2-just-right/#respond</comments>
		
		<dc:creator><![CDATA[gocallag]]></dc:creator>
		<pubDate>Sun, 30 Jun 2024 04:03:35 +0000</pubDate>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[WSL]]></category>
		<guid isPermaLink="false">https://madeforcloud.com/?p=223</guid>

					<description><![CDATA[Recent changes to WSL2 by Microsoft have made using Linux on Windows even more comfortable. I&#8217;ll describe some of the options and their use below. Firstly, do you have WSL2 installed? If not, then this will help https://learn.microsoft.com/en-us/windows/wsl/install-manual#step-1&#8212;enable-the-windows-subsystem-for-linux In order to best use WSL, you of course need to have a distribution installed. Ubuntu is&#8230;<p><a class="more-link" href="https://madeforcloud.com/2024/06/30/getting-wsl2-just-right/" title="Continue reading &#8216;Getting WSL2 just right&#8217;">Continue reading <span class="meta-nav">&#8594;</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p>Recent changes to WSL2 by Microsoft have made using Linux on Windows even more comfortable. I&#8217;ll describe some of the options and their use below.</p>



<p>Firstly, do you have WSL2 installed?  If not, then this will help <a href="https://learn.microsoft.com/en-us/windows/wsl/install-manual#step-1---enable-the-windows-subsystem-for-linux">https://learn.microsoft.com/en-us/windows/wsl/install-manual#step-1&#8212;enable-the-windows-subsystem-for-linux</a></p>



<p>In order to best use WSL, you of course need to have a distribution installed. Ubuntu is one of the easiest and most common to install.</p>



<pre class="wp-block-code"><code>wsl --list --online           #check what distros are available
wsl --install -d Ubuntu-24.04 #latest at the time of writing</code></pre>



<p>Now that you have a distro installed, we have something to configure. There are 2 configuration files that customise the distribution experience under WSL2.  <strong>wsl.conf and .wslconfig</strong></p>



<p><strong>wsl.conf </strong>contains per-distribution settings, whereas<strong> .wslconfig</strong> configures global settings for the WSL2 environment.</p>



<p><strong>wsl.conf</strong> is stored in the /etc directory within the distribution.</p>



<p><strong>.wslconfig</strong> is stored in your %UserProfile% folder.</p>



<h1 class="wp-block-heading">.wslconfig</h1>



<p>The .wslconfig file is in .ini format with the GA features found under section <strong>[wsl2]</strong>. There is also an <strong>[experimental]</strong> section for unreleased options. </p>



<p><strong>Note: </strong>All options may not be available to you as they are Windows OS and WSL version dependent. You can reasonably assume if you are running Windows 11, 22H2 or higher that most of the options described below are available to you. This is not the complete list, just the one&#8217;s I have found to be quite useful</p>



<h2 class="wp-block-heading">GA features that I find useful</h2>



<p>Accessible via the <strong>[wsl2] </strong>section of the .wslconfig file</p>



<figure class="wp-block-table"><table><tbody><tr><td>Key</td><td>Value</td><td>Notes</td></tr><tr><td>memory</td><td>memory size (Mb, Gb)</td><td>Default is 50% of the windows memory. <strong>I find it useful to constrain the memory (in conjunction with the experimental memory release features below)</strong></td></tr><tr><td>processors</td><td>number</td><td>Default is the same as present in windows</td></tr><tr><td>localhostForwarding</td><td>true/false</td><td>Default is true, this allows your WSL2 application to be accessible via localhost:port</td></tr><tr><td>nestedVirtualization</td><td>true/false</td><td>Allow nesting inside WSL2, Windows 11+</td></tr><tr><td>networkingMode</td><td>string, NAT, mirrored</td><td>The default is NAT, mirrored turns on mirrored networking mode. <strong>Mirrored mode is a great addition for many of my use cases.</strong></td></tr><tr><td>firewall</td><td>true / false</td><td>Hyper-V firewall can filter WSL network traffic</td></tr><tr><td>dnsTunneling</td><td>false</td><td>see the experimental section</td></tr><tr><td></td><td></td><td></td></tr></tbody></table><figcaption class="wp-element-caption">Some of the GA features</figcaption></figure>



<h2 class="wp-block-heading">Experimental (though very useful) features</h2>



<p>Accessible via <strong>[experimental]</strong> section of the .wslconfig file.</p>



<figure class="wp-block-table"><table><tbody><tr><td>Key</td><td>Value</td><td>Notes</td></tr><tr><td>autoMemoryReclaim</td><td>disabled</td><td>Default is disabled, but options list gradual and dropcache can dramatically return memory outside wsl2. <strong>I default to gradual.</strong></td></tr><tr><td>sparseVHD</td><td>false</td><td>When set to true new VHD&#8217;s are created as sparse saving considerable disk with all the overprovisioning issues. <strong>By default, i&#8217;m using sparse, but then again i&#8217;ve been using sparse filesystems for many years</strong></td></tr><tr><td>useWindowsDnsCache</td><td>false</td><td>If you have dnsTunneling turned on then this option allows you to use or ignore what windows dns may&#8217;ve cached</td></tr><tr><td>hostAddressLoopback</td><td>false</td><td>if networkingMode is set to mirrored then the loopback 127.0.0.1 address can be used to access the host and the container depending on where the listening resource may be running &#8211; windows or wsl2. <strong>This is a great option if you want better sharing between windows and wsl2 distro. For example, i&#8217;ve had a mongo client on windows and mongo in wsl2 ubuntu</strong>. </td></tr></tbody></table><figcaption class="wp-element-caption">Some of the Experimental features</figcaption></figure>



<h1 class="wp-block-heading">wsl.conf</h1>



<p>As I mentioned above the <strong>/etc/wsl.conf</strong> within the distribution controls some interesting behaviours, especially on distro launch.</p>



<h2 class="wp-block-heading">[boot]</h2>



<pre class="wp-block-code"><code>systemd=true</code></pre>



<p>Solves the problem where you&#8217;re reliant on systemd resources within your WSL2 distro.<strong> I normally have it turned on.</strong></p>



<h2 class="wp-block-heading">[automount]</h2>



<figure class="wp-block-table"><table><tbody><tr><td>Key</td><td>Value</td><td>Notes</td></tr><tr><td>enabled</td><td>true / false</td><td>Allows windows fixed drives to be automatically mounted under /mnt (or where the root key points). <strong>I have this enabled by default</strong></td></tr><tr><td>root</td><td>/mnt</td><td>Where the mounts occur for auto mounted systems</td></tr><tr><td>mountFsTab</td><td>true/false</td><td>Allow the /etc/fstab to be processed at WSL distro boot time. Great to get those SMB/NFS mounts going. <strong>I have this set to true as I use a lot of NFS in my test environment.</strong></td></tr></tbody></table></figure>



<p>Some things to note.</p>



<p>Windows disks are mounted using Drvfs and are by default case sensitive. You can override this behaviour for all or single drives. More information is available at <a href="https://devblogs.microsoft.com/commandline/per-directory-case-sensitivity-and-wsl/">Per-directory case sensitivity and WSL &#8211; Windows Command Line (microsoft.com)</a></p>



<h2 class="wp-block-heading">[network]</h2>



<figure class="wp-block-table"><table><tbody><tr><td>Key</td><td>Value</td><td>Notes</td></tr><tr><td>generateHosts</td><td>true/false</td><td>wsl will generate an appropriate /etc/hosts file based on the windows environment.<strong> I generally set this to true (the default).</strong></td></tr><tr><td>generateResolvConf</td><td>true/false</td><td>wsl will generate an appropriate list of dns resolvers. <strong>I generally set this to true (the default).</strong></td></tr><tr><td>hostname</td><td>string</td><td>This sets the hostname to be used within the distro. <strong>The default is the windows hostname, but this is useful if you run multiple WSL instances.</strong></td></tr></tbody></table></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://madeforcloud.com/2024/06/30/getting-wsl2-just-right/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
