Skip to content

Commit 0d5f4e5

Browse files
committed
config/containers-and-vms/chroot: create more detailed chroot guide
- based on the section of installation/musl - remove proot - add xchroot and bwrap - mention flatpak and OCI containers supercedes: - closes #300 - closes #610
1 parent 2b32fc8 commit 0d5f4e5

File tree

4 files changed

+118
-25
lines changed

4 files changed

+118
-25
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
- [External Applications](./config/external-applications.md)
6666
- [Printing](./config/print/index.md)
6767
- [Containers and Virtual Machines](./config/containers-and-vms/index.md)
68+
- [Chroots and Containers](./config/containers-and-vms/chroot.md)
6869
- [libvirt](./config/containers-and-vms/libvirt.md)
6970
- [LXC](./config/containers-and-vms/lxc.md)
7071
- [OpenPGP](./config/openpgp.md)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Creating and using chroots and containers
2+
3+
chroots and containers can be set up and used for many purposes, including:
4+
5+
- running glibc software on musl (and vice versa)
6+
- running software in a more controlled or sandboxed environment
7+
- creating a rootfs for bootstrapping a system
8+
9+
## Chroot Creation
10+
11+
### xvoidstrap
12+
13+
[`xvoidstrap(1)`](https://man.voidlinux.org/xvoidstrap.1) (from `xtools`) can be
14+
used to create the chroot:
15+
16+
```
17+
# mkdir <chroot_dir>
18+
# XBPS_ARCH=<chroot_arch> xvoidstrap <chroot_dir> base-voidstrap <other_pkgs>
19+
```
20+
21+
`<other_pkgs>` is only needed if you want to pre-install other packages in the
22+
chroot.
23+
24+
### Manual Method
25+
26+
Alternatively, this process can be done manually.
27+
28+
Create a directory that will contain the chroot, then install a base system in
29+
it via the `base-voidstrap` package:
30+
31+
```
32+
# mkdir -p "<chroot_dir>/var/db/xbps/keys"
33+
# cp -a /var/db/xbps/keys/* "<chroot_dir>/var/db/xbps/keys"
34+
# XBPS_ARCH=<chroot_arch> xbps-install -S -r <chroot_dir> -R <repository> base-voidstrap <other_pkgs>
35+
```
36+
37+
The `<repository>` may [vary depending on
38+
architecture](../../xbps/repositories/index.md#the-main-repository).
39+
40+
`<other_pkgs>` is only needed if you want to pre-install other packages in the
41+
chroot.
42+
43+
## Chroot Usage
44+
45+
### xchroot
46+
47+
[`xchroot(1)`](https://man.voidlinux.org/xchroot.1) (from `xtools`) can be used
48+
to automatically set up and enter the chroot.
49+
50+
### Manual Method
51+
52+
Alternatively, this process can be done manually.
53+
54+
If network access is required, copy `/etc/resolv.conf` into the chroot;
55+
`/etc/hosts` may need to be copied as well.
56+
57+
Several directories then need to be mounted as follows:
58+
59+
```
60+
# mount -t proc none <chroot_dir>/proc
61+
# mount -t sysfs none <chroot_dir>/sys
62+
# mount --rbind /dev <chroot_dir>/dev
63+
# mount --rbind /run <chroot_dir>/run
64+
```
65+
66+
Use [chroot(1)](https://man.voidlinux.org/chroot.1) to change to the new root,
67+
then run programs and do tasks as usual. Once finished with the chroot, unmount
68+
the chroot using [umount(8)](https://man.voidlinux.org/umount.8). If any
69+
destructive actions are taken on the chroot directory without unmounting first,
70+
you may need to reboot to repopulate the affected directories.
71+
72+
### Alternatives
73+
74+
#### Bubblewrap
75+
76+
[bwrap(1)](https://man.voidlinux.org/bwrap.1) (from the `bubblewrap` package)
77+
has additional features like the ability for sandboxing and does not require
78+
root access.
79+
80+
`bwrap` is very flexible and can be used in many ways, for example:
81+
82+
```
83+
$ bwrap --bind <chroot_dir> / \
84+
--dev /dev \
85+
--proc /proc \
86+
--bind /sys /sys \
87+
--bind /run /run \
88+
--ro-bind /etc/resolv.conf /etc/resolv.conf \
89+
--ro-bind /etc/passwd /etc/passwd \
90+
--ro-bind /etc/group /etc/group \
91+
<command>
92+
```
93+
94+
In this example, you will not be able to add or edit users or groups. When
95+
running graphical applications with Xorg, you may need to also bind-mount
96+
`~/.Xauthority` or other files or directories.
97+
98+
The [bwrap(1) manpage](https://man.voidlinux.org/bwrap.1) and the [Arch Wiki
99+
article](https://wiki.archlinux.org/title/Bubblewrap#Usage_examples) contain
100+
more examples of `bwrap` usage.
101+
102+
#### Flatpak
103+
104+
[Flatpak](../external-applications.md#flatpak) is a convenient option for
105+
running many applications, including graphical or proprietary ones, on both
106+
glibc and musl systems.
107+
108+
#### Application Containers
109+
110+
If a more integrated and polished solution is desired, Void also [provides OCI
111+
containers](https://github.com/void-linux/void-docker/pkgs/container/void-linux)
112+
that work with tools like [docker](https://www.docker.com) and
113+
[podman](https://man.voidlinux.org/podman.1). These containers do not require
114+
the creation of a chroot directory before usage.

src/config/containers-and-vms/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ software available on Void.
55

66
## Section Contents
77

8+
- [Chroots and Containers](./chroot.md)
89
- [libvirt](./libvirt.md)
910
- [LXC](./lxc.md)

src/installation/musl.md

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,5 @@ compatibility.
2929

3030
### glibc chroot
3131

32-
Software requiring glibc can be run in a glibc chroot.
33-
34-
Create a directory that will contain the chroot, and install a base system in it
35-
via the `base-voidstrap` package. If network access is required, copy
36-
`/etc/resolv.conf` into the chroot; `/etc/hosts` may need to be copied as well.
37-
38-
Several directories then need to be mounted as follows:
39-
40-
```
41-
# mount -t proc none <chroot_dir>/proc
42-
# mount -t sysfs none <chroot_dir>/sys
43-
# mount --rbind /dev <chroot_dir>/dev
44-
# mount --rbind /run <chroot_dir>/run
45-
```
46-
47-
Use [chroot(1)](https://man.voidlinux.org/chroot.1) to change to the new root,
48-
then run glibc programs as usual. Once you've finished using it, unmount the
49-
chroot using [umount(8)](https://man.voidlinux.org/umount.8).
50-
51-
#### PRoot
52-
53-
An alternative to the above is [proot(1)](https://man.voidlinux.org/proot.1), a
54-
user-space implementation of chroot, mount --bind, and binfmt_misc. By
55-
installing the `proot` package, unprivileged users can utilize a chroot
56-
environment.
32+
Software requiring glibc can be run in a glibc
33+
[chroot](../config/containers-and-vms/chroot.md).

0 commit comments

Comments
 (0)