8

I need a few basic bash commands, so I have WSL installed (Ubuntu 18.04).

With cygwin everything I need takes about 150MB. But WSL takes over 1GB !! Not good for my small SSD.

I'm sure there's loads of stuff/junk in there that isn't necessary (or even possible to use). Has anyone managed to reduce the size?

I did sudo apt autoremove but that doesn't help at all (obviously).

UPDATE
The answers below are super, but the above question remains unanswered. Suppose that WSL is being used (for various bash commands) - that is the premise, not wine/cygwin/vm/dualboot/docker/etc.
How would you strip it of stuff that can't be used within Windows anyway? I've read that there is all sorts of dead weight in there that can't be used. For example, if all you need is a collection of bash commands, how do you remove all the GUI and X stuff. Just as an example.

UPDATE2
I accepted one of the good answers below, but it doesn't fully answer the question. I hope in time someone will add to this discussion. I was hoping someone had a list of stuff that can be removed. I know how to remove stuff, what I don't know is what to remove.

5
  • Everything that is included in Ubuntu (or any OS, for that matter) has an aim. If you need an utility, you can't remove it. I think your question is ambiguous because you never specified what you use WSL for. Fabby's answer is the best you can get while you aren't more precise. That is, nobody knows what to remove if they don't know what must be done.
    – cdlvcdlv
    Jul 26, 2019 at 7:39
  • 1
    @cdlvcdlv Most people know what I'm talking about, and besides I clearly explained it in the question. A vanilla install of any OS, including ubuntu, is going to contains lots of junk that can be removed. Windows is not the only one that packages "useful extras" by default. For example, my ubuntu came with all kinds of desktop/graphics/audio/etc. apps that I don't need - junk. I assume most linux users would feel the same way about those extras, else they wouldn't be using linux. ;)
    – lonix
    Jul 26, 2019 at 11:47
  • @lonix I hear you, but I suppose you're interested in answers that suits you. The generic one is Fabby's. And may be (that's not proved) Ubuntu WSL comes with lots of junk but even then remember that "one man's trash is another man's treasure". Just saying you'll get more info if you define what's "trash" and "treasure" for you. BTW why your Ubuntu WSL takes 1GB? The package is just 200MB and people say it's not that big once installed.
    – cdlvcdlv
    Jul 27, 2019 at 9:13
  • @cdlvcdlv I don't remember as it was a long time ago... I'm sure it's much better/smaller now. :)
    – lonix
    Jul 27, 2019 at 10:11
  • Have you looked at cleaning up your Windows' rootfs cache? askubuntu.com/questions/1216741/… This reduced the space used by WSL Ubuntu 18.04 on my Windows 10 C: drive by 62 GB.
    – bhass1
    Mar 15, 2020 at 15:50

3 Answers 3

7

WSL is a full OS, so it takes up more CPU/MEM/DSK than CygWin but less than a VM

So it depends on your use case:

  • if all you need is tail on Windows, you just install the GNU Utilities for Windows.
  • If you need something more advanced, you install CygWin,
  • If you want to have snaps, containers, ... you install WSL
  • if you need all the whistles and bells of both Windows and Ubuntu you go:

    • dual-boot if you have <16G of RAM
      or
    • Virtual Machine with Ubuntu as a host and Windows in a VM if you have lots of RAM (24G or more)
  • if you need only one or a few Windows utilities¹, you install Ubuntu without Windows but with wine
  • If you need Ubuntu, just wipe Windows because Windows takes up much more space on your hard drive than Ubuntu! >:-)

Having said all that, you can always do the following to strip WSL of stuff that you don't need:

apt list --installed
apt purge WhateverYouDontNeed
sudo apt autoremove
sudo apt autoclean

;-)

¹ Definition of "utility": a small application that does not exist under Ubuntu E.g. Notepad++, DNSBench, ... Office is not a utility: it's a hog: go dual-boot ;-)

8
  • An exception to "if you need only one or a few Windows utilities" entry: if you need the latest Microsoft Office, you need dual-boot or VM. Latest MS Office installers don't work properly on Wine at last check (last week). And the "you can always..." section needs the obligatory "But if you don't know what you do or don't need, then you shouldn't be removing things" warnings.
    – Thomas Ward
    May 31, 2018 at 17:29
  • @ThomasWard Clarified! ;-) :P ;-)
    – Fabby
    May 31, 2018 at 17:30
  • dont forget to apt-get clean
    – cmak.fr
    May 31, 2018 at 19:54
  • @cmak.fr Added to answer! thanks for the reminder...
    – Fabby
    May 31, 2018 at 20:53
  • Ok. But the question remains - how to strip WSL of stuff that isn't necessary or usable. A lot of stuff in there is apparently (so I've read) dead weight and can't be used anyway.
    – lonix
    Jun 1, 2018 at 6:41
2

You can use docker images

See https://github.com/RoliSoft/WSL-Distribution-Switcher

They are much smaller and you can install additional apps as needed.

In addition some docker images come with pre-configured tools.

See https://hub.docker.com/explore/

I have used several docker images successfully.

4
  • You need WSL to install docker images, no?
    – Fabby
    May 31, 2018 at 21:00
  • @Fabby - yes, WSL needs to be active in windows.
    – Panther
    May 31, 2018 at 21:38
  • 2
    Ok. But the question remains - how to strip WSL of stuff that isn't necessary or usable. A lot of stuff in there is apparently (so I've read) dead weight and can't be used anyway.
    – lonix
    Jun 1, 2018 at 6:41
  • Remove the large Ubuntu install you have now and in its place use a smaller docker image
    – Panther
    Jun 1, 2018 at 15:35
0

You can use Ubento distro. It is a ultraminimal Ubuntu distro. The .tar file weights about 80 MB. From there you can add just the tools you need or expand it as the full fledged Ubuntu.

In any case, sadly, WSL doesn't have a way to control the size of the vhdx virtual drive images. They grow uncontrolled way beyond the actual data contained. The diskpart, or Optimize-vhd commands require elevated rights and in some cases they can even grow the size of the drive, specially if you have done it after and fstrim / command.

So far the wslcompact script is the most efficient way to optimize the size. leaving a vhdx about 2% over the used space reported by df /

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.