- Proceed at your own risk: This guide involves system-level changes (Virtualization, Drivers, Network Ports). While tested and safe, I am not responsible for data loss or system instability.
- Storage Warning: This setup requires approximately 60GB to 70GB of free disk space before downloading AI models. Ensure you have space!
Perform these steps in Command Prompt (CMD).
1. Configure Resource Limits (.wslconfig) We do this first to ensure the new installation respects your RAM limits immediately.
- Press
Win + R, type%UserProfile%, and press Enter. - Create a file named
.wslconfig(ensure the file extension is not.txt). - Paste the following configuration:
[wsl2]
memory=12GB
processors=4
# swap=8GB
[experimental]
sparseVhd=true
autoMemoryReclaim=gradualmemory: availible RAM.
processors: availible processor cores.
sparseVhd and autoMemoryReclaim: make the virtual disk shrinkable, freeing space when something is deleted.
2. Clean up previous installations (Optional) If you have an existing Ubuntu instance, unregister it to start fresh. Warning: This deletes all files inside Linux.
wsl --unregister UbuntuTip: Check %LocalAppData%\Temp and delete wsl-crashes or large temp files to reclaim space.
3. Install WSL (Ubuntu)
wsl --install -d UbuntuRestart your computer if prompted. Create your username/password when the terminal opens.
Open your Ubuntu terminal (WSL) for these steps.
1. Configure System Settings (Isolation Mode) We will disable Windows interoperability to prevent file system conflicts.
sudo nano /etc/wsl.confPaste exactly this: (Tip: To paste text into the Linux terminal, simply Right-Click your mouse)
[automount]
enabled = false
mountFsTab = true
[interop]
enabled = false
appendWindowsPath = falsethis settings is meant to prevent linux from easily access windows file system.
To save and exit: Press Ctrl+X, then type y, then press Enter.
2. Restart WSL to Apply Settings The new config file require a full restart of WSL to take effect.
- Exit from Ubuntu terminal
exit- After exiting you run this on cmd (terminal) to stop WSL
wsl --shutdown- Then open WSL again
wsl3. Update System Packages
sudo apt-get update && sudo apt-get upgrade -y1. Install Docker Engine
# Add keys
sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin2. Install NVIDIA Container Toolkit
# Add repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Install toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
# Configure and Restart
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart dockerRun this once to download the image and create the container named colab_local.
# Port Mapping Explanation:
# 9000 -> 8080 (Jupyter Notebook Interface)
# 8188 -> 8188 (ComfyUI Default)
# 7865 -> 7865 (Fooocus - optional)
# 7860 -> 7860 (A1111/Forge - optional)
sudo docker run --gpus=all -d \
-p 127.0.0.1:9000:8080 \
-p 127.0.0.1:8188:8188 \
-p 127.0.0.1:7865:7865 \
-p 127.0.0.1:7860:7860 \
--name colab_local \
us-docker.pkg.dev/colab-images/public/runtime- Open your browser and go to: https://colab.research.google.com/
- Click New Notebook (or open your existing
comfy-ui-setup.ipynb). - Click the arrow next to "Connect" (top right) and select Connect to a local runtime.
- Important: Look at your browser's address bar (right side usually). You will see an icon that looks like a Router or Signal Bar. Click it and Allow the connection to localhost.
- Get your connection URL from Ubuntu:
sudo docker logs --since=3m colab_localCopy the URL from the logs:
Look for the line starting with http://127.0.0.1:9000...
Example:
http://127.0.0.1:9000/?token=d44d0b0f34174fd561623ca9058a3089df5230c5bbd5b7c2
Paste this into the Colab "Backend URL" box and click Connect.
Use the cells below inside your Google Colab Notebook or use one provided .
Run this cell first. It handles the cloning of the repository and installation of requirements.
#@title Environment Setup
OPTIONS = {}
USE_GOOGLE_DRIVE = False #@param {type:"boolean"}
UPDATE_COMFY_UI = True #@param {type:"boolean"}
WORKSPACE = 'ComfyUI'
OPTIONS['USE_GOOGLE_DRIVE'] = USE_GOOGLE_DRIVE
OPTIONS['UPDATE_COMFY_UI'] = UPDATE_COMFY_UI
if OPTIONS['USE_GOOGLE_DRIVE']:
!echo "Mounting Google Drive..."
%cd /
from google.colab import drive
drive.mount('/content/drive')
WORKSPACE = "/content/drive/MyDrive/ComfyUI"
%cd /content/drive/MyDrive
![ ! -d $WORKSPACE ] && echo -= Initial setup ComfyUI =- && git clone https://github.com/comfyanonymous/ComfyUI
%cd $WORKSPACE
if OPTIONS['UPDATE_COMFY_UI']:
!echo -= Updating ComfyUI =-
!git pull
!echo -= Install dependencies =-
!pip install xformers!=0.0.18 -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu121 --extra-index-url https://download.pytorch.org/whl/cu118 --extra-index-url https://download.pytorch.org/whl/cu117Run this cell.
try:
USE_GOOGLE_DRIVE
except NameError:
%cd /content/ComfyUI
else:
if USE_GOOGLE_DRIVE == True:
%cd /content/$WORKSPACE
else:
%cd /content/ComfyUIThen uncomment the models you want to use and run the cell.
# ==============================================================================
# 1. CHECKPOINTS (BASE MODELS)
# ==============================================================================
# --- SDXL (Standard) ---
# Reference: https://comfyanonymous.github.io/ComfyUI_examples/sdxl/
# !wget -c https://huggingface.co/RunDiffusion/Juggernaut-XL-v8/resolve/main/juggernautXL_v8Rundiffusion.safetensors -P ./models/checkpoints/
# !wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -P ./models/checkpoints/
# --- SD 1.5 (Standard & Anime) ---
# !wget -c https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly-fp16.safetensors -P ./models/checkpoints/
# !wget -c https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/anything-v3-fp16-pruned.safetensors -P ./models/checkpoints/
# ==============================================================================
# 2. FLUX MODELS (Next Gen)
# ==============================================================================
# !wget -c https://huggingface.co/city96/FLUX.1-dev-gguf/resolve/main/flux1-dev-Q4_0.gguf -P ./models/diffusion_models/FLUX1/
# !wget -c https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors -P ./models/text_encoders/FLUX1/
# ==============================================================================
# 3. SUPPORT MODELS
# ==============================================================================
# --- Upscalers (ESRGAN) ---
# !wget -c https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P ./models/upscale_models/
# !wget -c https://huggingface.co/sberbank-ai/Real-ESRGAN/resolve/main/RealESRGAN_x4.pth -P ./models/upscale_models/
# --- ControlNet Preprocessors ---
# !cd custom_nodes && git clone https://github.com/Fannovel16/comfy_controlnet_preprocessors; cd comfy_controlnet_preprocessors && python install.pyRun this final cell to start the server.
# Go to the correct folder after instalation
try:
USE_GOOGLE_DRIVE
except NameError:
%cd /content/ComfyUI
else:
if USE_GOOGLE_DRIVE == True:
%cd /content/$WORKSPACE
else:
%cd /content/ComfyUI
!python main.py --listen 0.0.0.0
# If you are running on the same device you are accessing you can use localhost instead of 0.0.0.0 to prevent browser warnings, so access the link bellow
# http://localhost:8188/to stop running see bellow
Open Command Prompt (CMD).
wslIn the Ubuntu terminal:
sudo docker start colab_localRun this to see the logs and copy the token URL (port 9000) for Google Colab.
sudo docker logs --since=3m colab_local(Copy the http://127.0.0.1:9000/?token=... link and paste it into Colab)
Only do this if you want to run ComfyUI manually via terminal instead of using the Colab Notebook cells.
1. Access the container shell:
sudo docker exec -it colab_local /bin/bash2. Navigate and start ComfyUI:
cd /content/ComfyUI
python main.py --listen 0.0.0.0If you are running ComfyUI in the terminal (Step 4):
- Press
Ctrl + Cto stop the ComfyUI. - Exit the container shell:
exit
To shut down docker and wsl:
- Stop the container:
sudo docker stop colab_local
- Exit Ubuntu:
exit - Shutdown WSL:
wsl --shutdown
Use this if you want to completely wipe your Linux environment and start over.
Phase 1: Remove Linux Distribution
- Open Command Prompt (Admin).
- Check installed distros:
wsl --list --verbose - Unregister (Delete) the distro:
wsl --unregister Ubuntu - Verify removal:
wsl --list --verbose
Phase 2: Uninstall Applications
- Go to Windows Settings > Apps > Installed Apps.
- Search for Ubuntu and click Uninstall.
- (Optional) Uninstall Docker Desktop if you installed the Windows version.
Phase 3: Deep File Cleanup
- Press
Win + R, type%LocalAppData%\Packages, and delete folders starting withCanonicalGroupLimited.Ubuntu. - Press
Win + R, type%LocalAppData%\Temp, and delete thewsl-crashesfolder.
Phase 4: Disable Windows Features (Optional) Only do this if you never want to use WSL again.
-
Open Turn Windows features on or off.
-
Uncheck Windows Subsystem for Linux and Virtual Machine Platform.
-
Restart your PC.