Skip to content

Commit 923cb75

Browse files
milantracygvisor-bot
authored andcommitted
Document how to snapshot rootfs tar and start a sandbox with the tar file.
PiperOrigin-RevId: 820083428
1 parent a730d6c commit 923cb75

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

g3doc/user_guide/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,11 @@ doc(
120120
permalink = "/docs/user_guide/systemd/",
121121
weight = "91",
122122
)
123+
124+
doc(
125+
name = "rootfs_snapshot",
126+
src = "rootfs_snapshot.md",
127+
category = "User Guide",
128+
permalink = "/docs/user_guide/rootfs_snapshot/",
129+
weight = "92",
130+
)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Rootfs Snapshot
2+
3+
[TOC]
4+
5+
gVisor allows users to snapshot changes made to the root filesystem and save
6+
them to a tar file. These changes in the tar file can then be applied to a new
7+
sandbox upon creation.
8+
9+
## Prerequisite
10+
11+
* Rootfs must be overlayfs whose upper layer is tmpfs (this is the default
12+
rootfs configuration)
13+
14+
## How to snapshot
15+
16+
The snapshotting function is available via `runsc` commands. To run the command,
17+
you will start a gVisor container, create a directory and a new file at rootfs:
18+
19+
```
20+
$ docker run --rm -it --runtime=runsc alpine
21+
/ # mkdir dir
22+
/ # echo "hello world" > dir/file
23+
```
24+
25+
To take a snapshot of the rootfs change, you will use `runsc tar rootfs-upper`
26+
command, the tar file will be saved to the path that is specified in `--file`
27+
flag:
28+
29+
```
30+
$ sudo runsc --root=/var/run/docker/runtime-runc/moby tar rootfs-upper --file /tmp/rootfs.tar ddcbc9293778154db0f31068342adb5b1c08087ca94bfcef9070d23b44fbf2e8
31+
```
32+
33+
You can observe the tar file as:
34+
35+
```
36+
$ tar -tvf /tmp/rootfs.tar
37+
drwxr-xr-x 0/0 0 2025-10-10 23:27 ./
38+
drwx------ 0/0 0 2025-10-10 23:27 ./root/
39+
-rw------- 0/0 41 2025-10-10 23:27 ./root/.ash_history
40+
drwxr-xr-x 0/0 0 2025-10-10 23:27 ./dir/
41+
-rw-r--r-- 0/0 12 2025-10-10 23:27 ./dir/file
42+
```
43+
44+
You could also observe the file data from the tar file as:
45+
46+
```
47+
$ tar -xf /tmp/rootfs.tar ./dir/file -O
48+
hello world
49+
```
50+
51+
## How to start a container with the tar file
52+
53+
To start a new gVisor sandbox with the tar file we just get, you will need
54+
provide the annotation to OCI runtime spec, the key is
55+
`dev.gvisor.tar.rootfs.upper`, the value is the path to the tar file.
56+
57+
### Start with Docker
58+
59+
Since the tar file path is provided via OCI spec's annotation, it is compatible
60+
with Docker client when the runtime is gVisor. You can pass the annotation via
61+
Docker commad and observe the file change as:
62+
63+
```
64+
$ docker run --rm --runtime=runsc --annotation "dev.gvisor.tar.rootfs.upper"="/tmp/rootfs.tar" alpine cat /dir/file
65+
hello world
66+
```
67+
68+
### Start with OCI
69+
70+
You can add annotation to the bundle's `config.json` as:
71+
72+
```json
73+
"annotations": {
74+
"dev.gvisor.tar.rootfs.upper": "/tmp/rootfs.tar"
75+
},
76+
```
77+
78+
Then you can start a new sandbox and observe the file changes from the previous
79+
sandbox:
80+
81+
```
82+
$ sudo runsc run -detach=true alpine
83+
$ sudo runsc exec alpine cat /dir/file
84+
hello world
85+
```
86+
87+
> Please make sure you kill and delete the sandbox after the experiment.
88+
89+
## Limitation
90+
91+
* Snapshotting is only supported for single-container sandboxes.

website/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ docs(
165165
"//g3doc/user_guide:observability",
166166
"//g3doc/user_guide:platforms",
167167
"//g3doc/user_guide:production",
168+
"//g3doc/user_guide:rootfs_snapshot",
168169
"//g3doc/user_guide:runtime_monitoring",
169170
"//g3doc/user_guide:systemd",
170171
"//g3doc/user_guide:tpu",

0 commit comments

Comments
 (0)