|
102 | 102 | * [Can I access applications running in WSL 2 from Windows?](#can-i-access-applications-running-in-wsl-2-from-windows) |
103 | 103 | * [Can I run graphical applications in WSL 2?](#can-i-run-graphical-applications-in-wsl-2) |
104 | 104 | * [Can I use WSL in production scenarios?](#can-i-use-wsl-in-production-scenarios) |
105 | | - |
| 105 | + * [Can I run Docker Engine alongside Docker Desktop?](#can-i-run-docker-engine-alongside-docker-desktop) |
106 | 106 |
|
107 | 107 |
|
108 | 108 | </details> |
@@ -667,25 +667,53 @@ Typically, VHDX files are saved in `C:\Users\<your_user>\AppData\Local\Packages\ |
667 | 667 |
|
668 | 668 | ### Compressing the WSL 2 Virtual Disk |
669 | 669 |
|
670 | | -The WSL 2 virtual disk is a VHDX file that grows as you use Linux. If you delete files, the virtual disk does not automatically shrink; it will retain its size. |
| 670 | +The WSL 2 virtual disk is a VHDX file that grows as you use Linux. If you delete files, the virtual disk does not automatically shrink; it will remain the same size. |
671 | 671 |
|
672 | | -To reduce the size, enable the `sparse` mode in WSL 2, which is automatic virtual disk compression. To enable it, edit the `.wslconfig` file: |
| 672 | +To reduce its size, enable the `sparse` mode in WSL 2, which provides automatic disk compression. To enable it, edit the `.wslconfig` file: |
673 | 673 |
|
674 | 674 | ```conf |
675 | 675 | [wsl2] |
676 | 676 | sparseVhd=true |
677 | 677 | ``` |
678 | 678 |
|
679 | | -This option only applies to new virtual disks. For existing virtual disks, run the command: |
| 679 | +This option will only apply to new virtual disks. |
| 680 | +
|
| 681 | +For existing virtual disks, use the following commands: |
680 | 682 |
|
681 | 683 | ```bash |
682 | 684 | wsl --manage "Ubuntu" --set-sparse true |
683 | 685 | wsl --manage "docker-desktop" --set-sparse true # If using Docker Desktop |
684 | 686 | ``` |
685 | 687 |
|
686 | | -This will convert the virtual disk to sparse mode, enabling automatic compression. |
| 688 | +This will convert the virtual disk to sparse mode, which is automatic disk compression. |
| 689 | +
|
| 690 | +Before running the command, make sure the Linux distribution is stopped by using `wsl --shutdown` to stop all distributions. |
| 691 | +
|
| 692 | +If you have an old distribution and after applying sparse mode the virtual disk hasn't reduced in size, you can compress it manually. |
| 693 | +
|
| 694 | +Use the [wslcompact](https://github.com/okibcn/wslcompact) tool for this process. This tool is an executable for `PowerShell` that exports and imports the virtual disk, forcing WSL to compress it. |
| 695 | +
|
| 696 | +Run the command: |
| 697 | +
|
| 698 | +```bash |
| 699 | +wslcompact -c Ubuntu |
| 700 | +``` |
| 701 | +
|
| 702 | +This will generate a new virtual disk named `ext4.vhdx`, which will be your compressed distribution. When the executable asks to register the disk, press `Y` and then `Enter`. This won't automatically register it; you'll need to do it manually as shown in the backup and restoration section of this tutorial. |
687 | 703 |
|
688 | | -Before running the command, ensure the Linux distribution is stopped by executing `wsl --shutdown` to stop all Linux distributions. |
| 704 | +Remove the old disk with: |
| 705 | +
|
| 706 | +```bash |
| 707 | +wsl --unregister Ubuntu |
| 708 | +``` |
| 709 | +
|
| 710 | +And register the new disk with: |
| 711 | +
|
| 712 | +```bash |
| 713 | +wsl --import Ubuntu C:\path\to\ext4.vhdx |
| 714 | +``` |
| 715 | +
|
| 716 | +> **Warning**: Backup your Linux distribution before compressing it to avoid losing data in case of errors. |
689 | 717 |
|
690 | 718 | ### LAN and VPN Network Mode |
691 | 719 |
|
@@ -797,4 +825,8 @@ Yes, WSL 2 supports graphical applications through the WSLg (Windows Subsystem f |
797 | 825 |
|
798 | 826 | ### Can I use WSL in production scenarios? |
799 | 827 |
|
800 | | -WSL is designed as a development tool and is not recommended for production use. |
| 828 | +WSL is designed as a development tool and is not recommended for production use. |
| 829 | +
|
| 830 | +### Can I run Docker Engine alongside Docker Desktop? |
| 831 | +
|
| 832 | +No, you can only run one at a time. It is possible to have both installed, but only one can be running at any given time. |
0 commit comments