Install Stable Diffusion, an image generation AI. In this case, we will install Ubuntu on Proxmox, which allows GPU pass-through, and run the Stable Diffusion Web UI. Note that this article itself explains how to install in a Proxmox environment, but the installation will be performed in Ubuntu in VirtualBox.
However, VirtualBox does not allow GPU pass-through without special settings, so even if the web screen is displayed correctly, image generation may not work properly. We recommend that you take this into consideration and build your environment with Proxmox. Although the installation procedure itself is the same, we recommend setting up with Proxmox if you want to generate images using a GPU.
First, to prepare a Linux environment, download the ISO file from the official Ubuntu website. At this time, choose the lightweight “Ubuntu Server” instead of the desktop version, which is a CUI (Character User Interface) environment where you type in commands. Stable Diffusion Web UI installation is a simple copy-and-paste operation, so this is sufficient.
Next, install Ubuntu Server in VirtualBox using the downloaded ISO file. First, create a new virtual machine and specify the ISO file you just downloaded in the “ISO Image” field.
The memory size has been changed to 8 GB, but no other settings have been changed. Disk space is left at the default of 25GB, and network settings are also left as is. Let’s start the virtual machine with these settings.
After a few moments, the Ubuntu setup wizard will appear on a separate screen. Here, you can select the keyboard layout, but please choose Japanese.
For the installation type, select “minimal”. This is not selected by default, so press the space key to set it to “minimal”.
Next, the network connection, proxy, mirror address, and storage settings are fine as they are, so proceed directly to the next step.
Entering user information is very important. Be sure to enter it correctly and do not forget it. This information will be needed later when you log into the system. Also, for OpenSSH and other popular software, you can proceed with the default settings. The installation process may take a little while, but don’t be impatient.
Here is where beginners can easily get tripped up. That is that in VirtualBox’s CUI (command line interface) environment, normal copy and paste is not possible. Rest assured, however, there is a way to make this possible.
First, VirtualBox has a useful feature called “port forwarding”. This allows communication between the host machine (your PC) and the guest machine (the virtual machine). Specifically, it allows data sent to a specific port on the host machine to be automatically forwarded to a specific port on the guest machine. This configuration allows the host machine to directly access applications in the guest machine (e.g., a web server).
To configure port forwarding, first go to “Settings” in VirtualBox and select “Network”. Then click on the “Add Port Forwarding Rule” button. Here, enter the IP address of your Windows PC for Host IP. This will allow communication between the host and the guest, and will also allow copy and paste in the CUI screen.
Go to Configuration, then Network and enter the port forwarding rules.
Enter the IP address of the Windows PC in Host IP.
If you do not know the IP address of the host PC, you can check it by following these steps
- Open a command prompt.
First, open the Windows Start menu, type “cmd” in the search bar, and click on “Command Prompt” that appears. - Enter the command to check IP address
Once the command prompt opens, type the following command and press enteripconfig
- Confirm IP address
This command will display information such as the current system’s IP address, subnet mask, and default gateway. Usually, look for the item “IPv4 address” in the displayed information, and the number next to it is the IP address of the host PC. Enter this IP address in the “Host IP” field in the port forwarding configuration described earlier.
ipconfig
has several options, each of which is used to display different information. For example, here are some common options
ipconfig /all
: Displays detailed information about all network interfaces. This includes MAC addresses (physical addresses), DHCP and DNS server information, etc.ipconfig /release
: Releases the current IP address of a network interface that uses DHCP to obtain addresses.ipconfig /renew
: Obtain a new or updated IP address for a network interface to be addressed using DHCP.
Next, enter the IP address of the virtual machine (Ubuntu) for guest IP. If the IP address of the virtual machine is unknown, you can check it with the following command
- Open a terminal
Open a terminal on Ubuntu. This can be easily opened by pressing the “Ctrl Alt T” key. - Enter the command to check the IP address
Once the terminal opens, type the following command and press enterip a
This command displays information about all network interfaces on the system. Specifically, it displays the IP address (both IPv4 and IPv6), broadcast address, and MAC address for each interface. Usually, the numeric sequence following “inet” under items beginning withens
oreth
is the IP address of the virtual machine. If you are a beginner and have difficulty understanding this information, theip a
command is very useful for checking the status of your network, but watch it carefully because it can display a lot of results. Check slowly to avoid confusion when finding the desired information. - Host Port and Guest Port Settings
Next, for the host port in the port forwarding configuration, enter a port number that is not in use on your Windows PC. This is to access the guest machine (Ubuntu) using a specific port number on the host machine. Choose a port number that is not used by any other application, for example, 2222. For the guest port, enter “22,” which is the standard port number for SSH connections actually used in Linux. This will allow SSH connections from the host machine to the guest machine. Note that even if you did not choose to install OpenSSH Server when you installed Ubuntu before, you can still use this setting to connect later without any problems.
When configuring port forwarding, a “Windows Security Important Warning” may appear. In this case, select “Allow”. This will ensure smooth communication with the virtual machine through port forwarding.
Next, now that port forwarding has been configured, make an SSH connection to the virtual machine. Here, we will use an SSH client called TeraTerm, which is an easy-to-use SSH client that runs on Windows and is recommended for beginners.
- Launching TeraTerm
First, start TeraTerm. After launching, a screen for entering connection information will appear in the “Host” field. - Enter connection information
In the “Host” field, enter the IP address of the Windows PC that you have just confirmed. Also, in the “TCP Port” field, enter “2222”, which was set earlier for port forwarding. This will allow you to connect to the virtual machine through the specific port on the host machine. - Enter the user name and passphrase
If the connection is successful, you will be prompted to enter a user name and passphrase. Here, enter the user name and passphrase that you created during the Ubuntu installation. If entered correctly, you will be connected to the virtual machine’s terminal and will be able to control it remotely.
After completing this step, you will have remote access to the Ubuntu server. You are now ready to proceed to the next step.
Now that copy and paste is enabled, we will install Docker and Docker Compose. First, let’s refer to the official Docker documentation as we proceed.
The official documentation is here: Docker Official Installation Guide
- Install the required packages
First, install the packages necessary for apt to access repositories over HTTPS. Enter the following command in the terminal and execute it:
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
Here, using sudo
allows you to temporarily run the command with administrative privileges, enabling safe operation without the need to switch to the root user.
- Add the official Docker GPG key
Next, add the official Docker GPG key, which is necessary to verify the authenticity of packages. Execute the following command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Add the stable repository
Next, add the Docker stable repository to your system, which will allow you to install the stable version of Docker.
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
- Update the package list and install Docker
Finally, update the package list and install Docker.
sudo apt-get update
sudo apt-get install docker-ce
With this, the Docker installation is complete. After the installation is finished, run the docker --version
command to check the installed version of Docker.
Next, install Docker Compose. Again, refer to the official site and the link (GitHub) provided there.
- Official Documentation: Docker Compose Installation Guide
- Release page: GitHub Releases – Docker Compose
Check and Install the Latest Version
First, check the latest version on the GitHub releases page. As of the time of writing this article, the latest version is v2.18.1. Enter the following command in the terminal to install Docker Compose. The curl
command will download the binary file and place it in the appropriate directory.
sudo curl -L https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
By specifying -o /usr/local/bin/docker-compose
, the file is saved in the specified directory with normal user privileges.
Add Execution Permissions to the Binary
Next, grant execution permissions to the downloaded Docker Compose binary. This ensures that Docker Compose operates correctly.
sudo chmod +x /usr/local/bin/docker-compose
Check Docker Compose Version
Finally, to verify that the installation was successful, display the Docker Compose version using the following command.
docker-compose --version
With this, Docker and Docker Compose are now ready for the installation of the Stable Diffusion Web UI. Before proceeding, make sure the installation was successful.
Prepare for Stable Diffusion Web UI Installation
Next, follow the instructions provided on the Stable Diffusion Web UI GitHub page to continue with the installation process. However, note that AMD GPUs are currently not supported, so proceed only if you are using an NVIDIA GPU.
https://github.com/AbdBarho/stable-diffusion-webui-docker
Clone and move repositories
First, clone (copy) the Stable Diffusion Web UI repository and download it to your environment. Then, move it to the automatically created directory.
git clone https://github.com/AbdBarho/stable-diffusion-webui-docker.git
cd stable-diffusion-webui-docker
This
command will download the project source code from GitHub and save it in a directory called “stable-diffusion-webui-docker”. The next step is to download the project source code from GitHub and save it in the directory “stable-diffusion-webui-docker.
Download and validate the necessary model files
Next, by executing specific commands in the repository, Stable Diffusion downloads the model files necessary for it to operate properly and automatically verifies their integrity. This data download is only required the first time, for a total of approximately 12 GB of data.
sudo docker compose --profile download up --build
Here, the sudo
command is used with normal user privileges to temporarily obtain and execute the necessary privileges.-The --profile download
option instructs to use a specific profile to download the model files, while the up --build
option performs the download and build.
UI Execution Settings
Next, actually launch the Stable Diffusion Web UI. This time, we select the CPU-optimized UI ( auto-cpu)
to run on VirtualBox.
sudo docker compose --profile auto-cpu up --build
This command will launch the Stable Diffusion Web UI using the CPU, and since GPU pass-through is not available in the VirtualBox environment, it is configured to run on the CPU so that it will work within the virtual environment.
However, an error occurred.
=> ERROR [auto-cpu internal] load build definition from Dockerfile 0.0s
=> ERROR [auto-cpu internal] load .dockerignore 0.0s
[auto-cpu internal] load build definition from Dockerfile: ERROR [auto-cpu internal] load build definition from Dockerfile 0.0s => ERROR
[auto-cpu internal] load .dockerignore: failed to solve: failed to read dockerignore
failed to solve: failed to read dockerfile: failed to prepare as qtnl1bob5ac4n92psrozckpy4: write /var/lib/docker/overlay2/qtnl1bob5ac4n92 psrozckpy4/link: no space left on device
Checking for errors and disk space
When attempting to run Stable Diffusion Web UI, an error occurred. Investigating this error revealed a disk space problem. First, let’s check the current disk usage of the file system.
df -h
root@ubuntu:~/stable-diffusion-webui-docker# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 796M 788K 795M 1% /run
/dev/mapper/ubuntu–vg-ubuntu–lv 12G 12G 0 100% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 2.0G 130M 1.7G 8% /boot
tmpfs 796M 4.0K 796M 1% /run/user/1000
The above output shows that /dev/mapper/ubuntu--vg-ubuntu--lv
is using 100% of the disk space. This is the cause of the error, as the disk space is insufficient to store the required files and data.
Causes and Workarounds for Disk Space Problems
You may have noticed that in the VirtualBox settings you have set the disk space to 25GB, but in reality only 12GB is allocated. This is due to the fact that you selected LVM (Logical Volume Manager) when installing Ubuntu; LVM allows for flexible disk management, but it may not allocate the full capacity correctly during the initial setup.
The easiest way to avoid this problem is to avoid selecting LVM when installing Ubuntu; by setting up the entire disk as a single large partition without LVM, the full capacity will be allocated and problems due to lack of disk space can be avoided.
If you have already chosen LVM, there are several ways to deal with this
Manually expand the size of LVM
It is possible to expand disk space while still using LVM, but this method is a bit more complicated and requires knowledge of LVM. This can be a bit of a difficult task for beginners.
Reinstall Ubuntu anew.
When doing so, choose the option to use the entire disk instead of selecting LVM. This will treat the entire virtual disk as a single partition, with the full 25 GB available.
The installer can create one large partition to use the entire disk.
I should have unchecked Set up this disk as an LVM group.
Check unallocated physical volumes
First, check to see if there are any unallocated physical volumes available. This is to determine the current disk space situation and to obtain the information needed to allocate additional space.
sudo pvs
When you run this command, you may see the following results
root@ubuntu:~/stable-diffusion-webui-docker# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a– <23.00g 11.50g
Here we see that the physical volume /dev/sda3
exists in a volume group called ubuntu-vg
with a total capacity of about 23 GB, of which about 11.5 GB is unallocated. We can now allocate additional space.
Delete unused Docker objects
Next, delete all unused Docker objects to free up disk space. This will clean up unneeded data and free up more space.
sudo docker system prune
This command removes all unused containers, networks, volumes, and images to free up disk space. It is a good idea to verify what you are deleting before executing and make backups if necessary.
Adding Unallocated Space to a Logical Volume
Next, unallocated space is added to the logical volume. This expands the disk space and allows you to store the files you need.
sudo lvextend -l 100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
This command adds all unallocated space to /dev/mapper/ubuntu--vg-ubuntu--lv
. This will make the maximum disk space available.
Resizing the file system
Finally, resize the file system to fit the newly allocated space. This allows the system to recognize and utilize the added disk space.
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
This command will expand the file system to the new disk size and make it available without error.
Handling Disks and Partitions in Linux
In Linux, there is no direct equivalent to the Windows D drive. However, in Linux, additional disks or partitions can be mounted at any location to accomplish a similar purpose. For example, a new disk can be mounted in a directory such as /mnt/data
and used as an area for data storage, just like the D drive.
Rechecking unallocated physical volumes
First, check to see if all unallocated physical volumes were used in the previous step. Again, run the following command to check if any unallocated space remains.
sudo pvs
When executed, the following results are displayed
PV VG Fmt Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a– <23.00g 0
Now, if you can see that PFree
is 0
, it means that all unallocated space has been added to the logical volume. The disk space issue should now be resolved and the Stable Diffusion Web UI should install successfully.
Configure port forwarding and check with a browser
Next, configure port forwarding settings to access the Stable Diffusion Web UI in a browser. The port number we will use this time is 7860
, but this is a setting within VirtualBox, so we will configure port forwarding between the host and guest to allow access from outside.
Open VirtualBox Settings
First, open the settings of the virtual machine you are using in the VirtualBox management interface.
Network Settings Port Forwarding
Navigate to the “Network” section and add a port forwarding rule. Please configure the following settings:
- Host Port: 5555
- Guest Port: 7860
- Guest IP: 192.168.x.x (the IP address of the virtual machine)
This will forward access from port 5555 on the host machine to port 7860 on the virtual machine.
Access via Browser
Once port forwarding is set up, open your host machine’s browser and enter the following URL to access the Stable Diffusion Web UI.
http://192.168.x.x:5555/
Here, replace 192.168.x.x
with the IP address of your virtual machine. If the page is displayed in your browser, it confirms that the installation was successful and that the Stable Diffusion Web UI is functioning correctly.