--- title: Ubuntu Desktop emoji: ๐Ÿง colorFrom: indigo colorTo: blue sdk: docker pinned: false --- # ๐Ÿง Ubuntu Desktop on Hugging Face Spaces A browser-accessible **Ubuntu 24.04 XFCE Desktop** running on a free Hugging Face Docker Space โ€” inspired by Android Termux + PRoot-Distro workflows, adapted for cloud deployment with zero manual setup. --- ## โœจ What You Get | Feature | Detail | |---|---| | **Desktop** | Ubuntu 24.04 + XFCE4, accessible from any browser | | **VNC** | TigerVNC (Xvnc) at 1280ร—720, 16-bit colour, 24 FPS | | **Browser Access** | noVNC via WebSocket โ€” no VNC client needed | | **Persistent Storage** | All data stored in `/data` โ€” survives Space restarts | | **Dashboard** | Flask app with live CPU / RAM / disk stats + log viewer | | **Browser** | Firefox ESR pre-installed | | **Free CPU Tier** | Optimised for low RAM + CPU (โ‰ˆ 400 MB idle) | --- ## ๐Ÿš€ Deployment to Hugging Face Spaces ### Prerequisites - A [Hugging Face](https://huggingface.co) account - Git installed locally (or use the HF web UI) ### Step 1 โ€” Create a new Space 1. Go to **huggingface.co/new-space** 2. Choose **Docker** as the Space SDK 3. Set hardware to **CPU Basic** (free tier) 4. Enable **Persistent Storage** in the Space settings (required for `/data`) ### Step 2 โ€” Upload the files Either use the HF web editor to paste each file, or clone the Space repo and push: ```bash git clone https://huggingface.co/spaces// cd # Copy all project files here cp -r /path/to/hf-ubuntu-space/* . git add . git commit -m "Initial Ubuntu Desktop Space" git push ``` ### Step 3 โ€” Wait for the build The first build takes **5โ€“8 minutes** (downloading Ubuntu + XFCE packages). Watch the **Build Logs** tab in the Space UI. ### Step 4 โ€” Access your desktop Once the Space shows **Running**, click the **App** tab, or open: ``` https://-.hf.space ``` Click **๐Ÿ–ฅ Launch Desktop** to open the noVNC browser desktop. --- ## ๐Ÿ–ฅ Browser Desktop Access | URL | Purpose | |---|---| | `https://โ€ฆhf.space/` | Launcher page (recommended) | | `https://โ€ฆhf.space/vnc/vnc.html` | noVNC direct (raw interface) | | `https://โ€ฆhf.space/dashboard` | System stats dashboard | The launcher page auto-detects your Space's hostname and builds the correct WebSocket URL for noVNC โ€” this is important because HF Spaces use Cloudflare proxying where the port is always 443 externally. ### Mobile browsers noVNC works on mobile. Use the scale/resize button (โคข) in the noVNC toolbar to fit the 1280ร—720 desktop to your screen. --- ## ๐Ÿ’พ Persistent Storage All state lives under `/data` (Hugging Face's persistent volume): ``` /data/ โ”œโ”€โ”€ home/ โ† ubuntu user home (~/.bashrc, Desktop, etc.) โ”œโ”€โ”€ workspace/ โ† your project files (persists forever) โ”œโ”€โ”€ downloads/ โ† browser and wget downloads โ”œโ”€โ”€ firefox/ โ† Firefox profile (bookmarks, passwords, etc.) โ”œโ”€โ”€ xfce/ โ† XFCE session config, wallpaper, themes โ”œโ”€โ”€ vnc/ โ† VNC server state + xstartup โ”œโ”€โ”€ logs/ โ† all service logs โ””โ”€โ”€ cache/ โ† app-level cache ``` > **Note:** You must enable **Persistent Storage** in your Space settings. > Without it `/data` is ephemeral and resets on every restart. --- ## โš™๏ธ PRoot-Distro Similarities This Space simulates the Termux + PRoot-Distro workflow: | Termux / PRoot | This Space | |---|---| | `pkg install proot-distro` | Base Docker layer | | `proot-distro install ubuntu` | `FROM ubuntu:24.04` in Dockerfile | | `proot-distro login ubuntu` | Container starts automatically | | `~` (Termux home) | `/data/home` (persisted) | | Internal storage | `/data/workspace` | The key difference is that this runs Docker natively (not PRoot), giving full kernel-level isolation without the overhead of a userspace chroot. --- ## ๐Ÿ”ง Configuration ### Environment variables (set in Space settings) | Variable | Default | Description | |---|---|---| | `VNC_PASSWORD` | _(empty)_ | Set a VNC password (optional; localhost-only anyway) | | `RESOLUTION` | `1280x720` | Desktop resolution | | `COLOR_DEPTH` | `16` | VNC colour depth (16 or 24) | ### Changing resolution Edit `supervisord.conf`, update the Xvnc command: ```ini command=Xvnc :1 -geometry 1920x1080 -depth 24 ... ``` --- ## ๐Ÿ›  Troubleshooting ### Desktop doesn't load / black screen 1. Open the **Dashboard** โ†’ check all services show **Running** 2. Check **Xvnc** and **XFCE4** logs for errors 3. Try restarting XFCE4 from the dashboard restart button ### "Failed to connect to server" in noVNC - Make sure you're using the **launcher page** (`/`) not a hard-coded URL - The WebSocket path must be `/websockify` โ€” check the URL bar in noVNC shows the correct host ### Space keeps sleeping HF free CPU Spaces sleep after ~15 min of no browser traffic. This is expected. Wake it by opening the Space URL. Your `/data` files are always preserved. ### High memory usage XFCE4 uses ~300โ€“400 MB at idle. With Firefox open, expect 800 MB+. The free CPU tier has 16 GB RAM, so this is fine. If you see OOM kills, close unused browser tabs in the desktop. ### Logs All logs are in `/data/logs/` and viewable from the Dashboard log viewer: ``` /data/logs/supervisord.log /data/logs/xvnc.log / xvnc_err.log /data/logs/xfce4.log / xfce4_err.log /data/logs/websockify.log /data/logs/dashboard.log /data/logs/nginx.log / nginx_error.log ``` --- ## ๐Ÿ— Architecture ``` Browser (HTTPS :443) โ”‚ โ–ผ nginx :7860 (HF Spaces default port) โ”œโ”€ / โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Launcher HTML (auto-builds WSS URL) โ”œโ”€ /vnc/ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ noVNC static assets โ”œโ”€ /websockify โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ WebSocket proxy โ”€โ”€โ–บ websockify :6080 โ”‚ โ”‚ โ”‚ Xvnc :5901 โ”‚ XFCE4 session โ”œโ”€ /dashboard โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Flask app :5000 โ””โ”€ /api/ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Flask REST API :5000 ``` --- ## ๐Ÿ“„ Licence MIT โ€” use freely, no warranties.