Mounting another disk as ext4 in WSL2

Here we learn how to create a virtual disk meant to be mounted in WSL.

Introduction

On my development machine, I run various WSL (now WSL2) instances. I needed to have a common disk that would store all the code and can be mounted on the different instances.

While this could’ve been done by regular folders as well, the performance of the NT file system is abysmal when it comes to a large number of tiny files (node_modules anyone?). This meant that that this common disk had to be an ext4 disk.

Outline

  • Windows: Create a file.
  • WSL: Format the file as ext4.
  • WSL: Mount the file as a disk.

Steps

Create a file

A dummy file can be created on windows using fsutil.

fsutil file createNew <call-this-file-whatever-you-want> <size-in-bytes>

For this example, the file we’ll use will be called development.ext4 with a size of 16GB

fsutil file createNew development.ext4 17179869184

Format the file as ext4

Now, this (empty) file needs to be formatted as ext4. In WSL, this can be done by the following command:

mkfs.ext4 -b 1024 <location-for-development.ext4>

This formats the empty file as a virtual disk with an ext4 file system with a block size of 1024.

(Optional) Remove reserved blocks:

tune2fs -m 0 <location-for-development.ext4>

(Optional) Increase throughput:

tune2fs -o journal_data_writeback <location-for-development.ext4>

Mount the file as a disk

Now, the file simply needs to be mounted inside WSL as a disk. This can be done using the following command:

sudo mount -t ext4 <location-for-development.ext4> <mount-point>

For me, the mount point was /projects, hence the command above becomes

sudo mount -t ext4 <location-for-development.ext4> /projects

With this, the file will be mounted at /projects, and now can be treated as a regular file/disk.

Conclusion

This works for me. However, I can’t get this to automount via fstab due to limitations with WSL. For the time being, I’ve created an entry in /etc/fstab in WSL, and mounting it using the windows task scheduler using:

sudo mount --all

Now, when I need to back up my projects, backing up a single file (development.ext4) is going to be a lot simpler than backing up multiple individual files (a VCS is a better fit for that anyway)

Hope this helps someone, cheers!

How to be a Search Engine Guru

The year was 1990. Archie, a simple FTP indexer was introduced to the world.  Later, Veronica & Jughead joined the pack.

These can safely be called as the first search engines that were introduced to computer users (they were pretty sparse and specific back then).

Fast forward 20 years.

Today, and I think I speak for many users around the world as well, one of the first things I do, when I open my browser, is open Google (I mean it’s already there, my homepage. Well, you know what I mean). Heck, I’m not even finished typing and it starts displaying results, and pretty relevant at that!

But, even though Google and the others are constantly improving their algorithms to improve the quality & relevancy of their results, intelligent searches are still a big problem.

What I mean is, that at the end of the day, the search engine is still robotic and non-intelligent. It works on a set of rules. And given that this set of rules is expanding, even as we speak, guessing what the user wants to search (and the exact result he’s expecting) is gonna take a considerable amount of time.

But let’s not get into the mechanics of that. This article focuses on building better search terms or query strings so that searches deliver the most desired result possible. Let’s face it, 99% people don’t care how many updates does Google release in a year, or whether they’re on Dominic, Caffeine, Vince, Panda (recently Penguin) or the fact that Google aims at each page being rendered in under half a second, they want relevant results.

So, here’s what you can do to make your searches worthwhile:

  1. Use exact phrases when looking for something specific : Using the EXACT phrase while searching for things like error message, slogan, quote, etc. generally gives a higher and to the point result.
  2. Be easy on the grammar : Grammar is necessary for humans to comprehend language. But when it comes to search, grammar is not necessarily required. In fact, results can be quite different when omitting purely grammatical words. This is because each extra word, is extra works for the search engine .. ie .. it’ll take into account that word too. (Weird example, but works .. I’ll come up with a better one soon)
  3. Structure your query : To get relevant results, it is important that you structure your query in some way. The search engine works on patterns. So make one that gives the most satisfactory result, and save yourself some headache.
    For example, I usually like to keep the subject keyword and the beginning of the query. I’ve found that this filters results quickly, and even helps auto-complete to get relevant results.
  4. The search engine is a computer program, treat it that way : While semantic searches are on their way, at the end of the day, like I said earlier, the search engine is still a computer program. If you ask it something like “What is the correct way to do push ups”, it won’t go through a bunch of fitness columns. It will search for articles that have a similar title, or have this in the article body. So don’t ask questions from search engines and expect accurate answers. If you ARE getting them, it’s probably because someone has written about it somewhere, not because the search engine understands it.
  5. Look for alternatives : Personally, I’ve almost always used Google. And although it still remains my first choice in search engines, recently I’ve started looking into alternatives. Some quite popular, like Bing, some not so popular, like Duck Duck Go. The quality and relevancy of the results is varied across all these search engines.

I’ll add more points here as I come across some more patterns.

I’d also like to state that the intent of this article was to focus on improving search results and hence improve user experience and save sometime while doing that. I hope it is taken in that spirit.

Take Care !