> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-33-linux-jails/di-33.3-jie-ubuntu-jail.md).

# 33.3 Ubuntu Jail

The method for creating an Ubuntu Jail is the same as for Debian. This example uses Ubuntu 22.04 (Jammy).

## Build the Base System

Create the Ubuntu Jail root directory and install the system using debootstrap:

```sh
# Create the Ubuntu Jail root directory
# mkdir -p /usr/jails/ubuntu

# Install Ubuntu Jammy system into the Jail using debootstrap, specifying the mirror
# debootstrap jammy /usr/jails/ubuntu https://mirrors.ustc.edu.cn/ubuntu/
```

## Manage Mount Files

Create the **/etc/fstab.ubuntu** file with the following content:

```ini
devfs      /usr/jails/ubuntu/dev      devfs       rw                      0  0
tmpfs      /usr/jails/ubuntu/dev/shm  tmpfs       rw,size=1g,mode=1777    0  0
fdescfs    /usr/jails/ubuntu/dev/fd   fdescfs     rw,linrdlnk             0  0
linprocfs  /usr/jails/ubuntu/proc     linprocfs   rw                      0  0
linsysfs   /usr/jails/ubuntu/sys      linsysfs    rw                      0  0
/tmp       /usr/jails/ubuntu/tmp      nullfs      rw                      0  0
```

## Manage the Jail Configuration File

Add the Ubuntu configuration to the **/etc/jail.conf** file:

```ini
ubuntu {                               # Jail name
  host.hostname = "ubuntu";             # Set the Jail's hostname
  mount.fstab = "/etc/fstab.ubuntu";    # fstab file used by the Jail
  path = "/usr/jails/ubuntu";           # Jail root directory path
  devfs_ruleset = 4;                     # devfs mount ruleset
  enforce_statfs = 1;                    # Set mount point visibility
  allow.mount;                          # Allow mounting file systems
  allow.mount.devfs;                     # Allow mounting devfs
  exec.start = "/bin/true";              # Command executed at startup
  exec.stop = "/bin/true";               # Command executed at shutdown
  persist;                               # Keep the Jail alive even without processes
  allow.raw_sockets;                      # Allow raw sockets
  interface = "lo1";                      # Specify the network interface
  ip4.addr = 192.168.5.2;                 # Assign IPv4 address
  ip6 = "disable";                        # Disable IPv6
}
```

## Allow Network Access

Add the Jail's address to the `jails` table in the pf firewall to allow the Jail to access the network:

```sh
# pfctl -t jails -T add 192.168.5.2
```

## Start the Ubuntu Jail Instance

Start the instance:

```sh
# jail -c ubuntu
```

If `jail_enable=YES` has already been set in **/etc/rc.conf**, you can also use:

```sh
# service jail start ubuntu
```

For boot-time startup settings, refer to the Debian Jail. Run the following command to add the ubuntu Jail to the startup list:

```sh
# sysrc jail_list+=ubuntu
```

## Update the Ubuntu System

The process is the same as for the Debian Jail; simply replace `debian` with `ubuntu` in the commands. Refer to other relevant chapters in this book.

## References

* FreeBSD Chinese Handbook. 12.3. Linux User Space\[EB/OL]. \[2026-03-25]. <https://handbook.bsdcn.org/di-12-zhang-linux-er-jin-zhi-jian-rong-ceng/12.3.-linux-yong-hu-kong-jian.html>. A tutorial in the Chinese handbook on building a complete Linux user space environment.
* Ubuntu Documentation. Install Firefox on Linux\[EB/OL]. \[2026-04-17]. <https://support.mozilla.org/en-US/kb/install-firefox-linux>. Firefox is distributed as a snap by default in Ubuntu 22.04, but can also be installed as a deb package via PPA.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-33-linux-jails/di-33.3-jie-ubuntu-jail.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
