Running local txt2img with stable diffusion

This guide explains how to install stable-diffusion-webui (AUTOMATIC1111) on Qubes OS 4.2.0. It’s meant to be used with an nvidia GPU, but it can run on the CPU.
The GPU I use is the nvidia 4060, I’m not sure if it will work with cards using the legacy driver, I’m also not sure how to make it work with other GPU types.

I have tested SD with and without using a GPU on 3 systems running Qubes OS, and it does work only using the CPU. So if you just want to try SD before you go out and buy a $1000 GPU, you can run it on the CPU, but it is very slow compared to running it on a GPU.

Image generation time (20 steps, 512x512):
i7-8650U (Old laptop CPU): ~6 min
i9-13900K (Desktop CPU): ~1m 45s
nvidia 4060 (GPU) with i9-13900K : >5s

If you don’t have a GPU, you can skip to installing stable-diffusion-webui

GPU passthrough

Follow this guide, it explains how to do passthrough:
I’ll only give a summary of how you configure GPU passthrough, there are already multiple guides going into detail about passthrough.

You are also only going to need CUDA support, which makes passthrough slightly easier.

  1. Find your device ID with lspci.
  2. Hide the device ID from dom0, by adding rd.qubes.hide_pci=ID to grub.
    Generate grub and reboot, grub2-mkconfig -o /boot/grub2/grub.cfg
  3. Check if the device is hidden, sudo lspci -vvn, kernel driver should be pciback.
  4. Use the script to patch qemu-stubdom-linux-rootfs

If you are having issues with passthrough, search the forum.

Installing the CUDA driver

sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo add-apt-repository contrib
sudo apt-get update
sudo apt-get -y install nvidia-kernel-open-dkms
sudo apt-get -y install cuda-drivers

Installing stable-diffusion-webui

Make a qube with 16 GB memory, and 25 GB disk space. If you are using a GPU it needs to be standalone with the kernel supplied by qube, if you used the patch script the name needs to start with gpu_, you also need to install the CUDA driver and pass the GPU.

If you are not using a standalone qube, python3.11-venv need to be installed in the template

sudo apt install python3.11-venv
git clone
cd stable-diffusion-webui
python3 -m venv venv/

If you don’t have a GPU, you need to edit and add --use-cpu all --no-half --no-half-vae --skip-torch-cuda-test to the COMMANDLINE_ARGS

Let the installation complete and there should be a web server running on localhost:7860, it’s installed with the SD v1.5 image model, and should be ready for use.

Stable Diffusion running in Qubes OS (ThinkPad T480)


This is great, thanks!

  1. The way this is written, it appears to involve both standard software installation as well as home directory local software installation. I presume this means it is written to run in a standalone app qube, not a templated one, correct? Ah…I think that’s stated explicitly in the small Linux section of neowutran’s writeup that you linked to. If so, I’d add an explicit statement about that earlier in the text for linux users who might skip over the neowutran link due to the url referencing windows. Edit: hmm, I also see that I missed a reference a bit later in your text. Maybe that’s fine the way it is.

  2. This might be out of scope for your guide but: for the users who might want to run sd-webui on CPU to get a taste whether to dive into GPU passthrough, and who will not (yet) need a standalone qube, can you review and add some clarity with regard to which of the setup steps needs to be run in the template qube vs. the app qube in that case? If the answer is “no, just use a standalone qube”, that’s also fine. :slight_smile:



I didn’t want to go into details about passthrough, but I also didn’t want to leave it out completely. I hope people not familiar with passthrough will use the existing guides and threads, there isn’t anything that makes it different in this case.

I’ve added a note about python3.11-venv should be installed in the template, when not using a standalone qube.


Very cool, thank you! I’ve been meaning to look into how to set it up!

If I were serious about using SD I’d have to get an external GPU, however, as generating an image on my NV41 (i71260P) does take ~5-6 minutes.