Skip to content

Commit b0d55d5

Browse files
Cody RoseboroughIRCody
Cody Roseborough
authored andcommitted
Modify getting-started to use devmapper snapshottter
Signed-off-by: Cody Roseborough <[email protected]>
1 parent b502eaf commit b0d55d5

File tree

1 file changed

+80
-8
lines changed

1 file changed

+80
-8
lines changed

docs/getting-started.md

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ state = "/run/firecracker-containerd"
136136
[grpc]
137137
address = "/run/firecracker-containerd/containerd.sock"
138138
[proxy_plugins]
139-
[proxy_plugins.firecracker-naive]
139+
[proxy_plugins.firecracker-devmapper]
140140
type = "snapshot"
141-
address = "/var/run/firecracker-containerd/naive-snapshotter.sock"
141+
address = "/var/run/firecracker-containerd/devmapper-snapshotter.sock"
142142

143143
[debug]
144144
level = "debug"
@@ -150,6 +150,76 @@ from the same version of containerd as `firecracker-containerd`, which ensures t
150150
binaries are in sync with one another. While other builds of `ctr` may work with
151151
`firecracker-containerd`, use of `firecracker-ctr` will ensure compatibility.
152152

153+
### Prepare and configure snapshotter
154+
155+
The devmapper snapshotter requires a thinpool to exist.
156+
Below is a script to create a thinpool as well as an example config file.
157+
158+
`Note: The configuration with loopback devices is slow and not intended for use in production.`
159+
160+
<details>
161+
<summary>Script to setup thinpool with dmsetup.</summary>
162+
163+
```bash
164+
#!/bin/bash
165+
166+
# Sets up a devicemapper thin pool with loop devices in
167+
# /var/lib/firecracker-containerd/snapshotter/devmapper
168+
169+
set -ex
170+
171+
DIR=/var/lib/firecracker-containerd/snapshotter/devmapper
172+
POOL=fc-dev-thinpool
173+
174+
if [[ ! -f "${DIR}/data" ]]; then
175+
touch "${DIR}/data"
176+
truncate -s 100G "${DIR}/data"
177+
fi
178+
179+
if [[ ! -f "${DIR}/metadata" ]]; then
180+
touch "${DIR}/metadata"
181+
truncate -s 2G "${DIR}/metadata"
182+
fi
183+
184+
DATADEV="$(losetup --output NAME --noheadings --associated ${DIR}/data)"
185+
if [[ -z "${DATADEV}" ]]; then
186+
DATADEV="$(losetup --find --show ${DIR}/data)"
187+
fi
188+
189+
METADEV="$(losetup --output NAME --noheadings --associated ${DIR}/metadata)"
190+
if [[ -z "${METADEV}" ]]; then
191+
METADEV="$(losetup --find --show ${DIR}/metadata)"
192+
fi
193+
194+
SECTORSIZE=512
195+
DATASIZE="$(blockdev --getsize64 -q ${DATADEV})"
196+
LENGTH_SECTORS=$(bc <<< "${DATASIZE}/${SECTORSIZE}")
197+
DATA_BLOCK_SIZE=128 # see https://www.kernel.org/doc/Documentation/device-mapper/thin-provisioning.txt
198+
LOW_WATER_MARK=32768 # picked arbitrarily
199+
THINP_TABLE="0 ${LENGTH_SECTORS} thin-pool ${METADEV} ${DATADEV} ${DATA_BLOCK_SIZE} ${LOW_WATER_MARK} 1 skip_block_zeroing"
200+
echo "${THINP_TABLE}"
201+
202+
if ! $(dmsetup reload "${POOL}" --table "${THINP_TABLE}"); then
203+
dmsetup create "${POOL}" --table "${THINP_TABLE}"
204+
fi
205+
```
206+
</details>
207+
208+
<details>
209+
<summary>Snappshotter config file example.</summary>
210+
211+
```json
212+
{
213+
"base_image_size": "10GB",
214+
"root_path": "/var/lib/firecracker-containerd/snapshotter/devmapper",
215+
"pool_name": "fc-dev-thinpool"
216+
}
217+
```
218+
219+
</details>
220+
221+
A reasonable location for this file is at `/etc/firecracker-dm-snapshotter/config.json`.
222+
153223
### Configure containerd runtime plugin
154224

155225
The runtime expects a JSON-formatted configuration file to be located either in
@@ -210,10 +280,12 @@ configuration file has the following fields:
210280
Start the containerd snapshotter
211281

212282
```bash
213-
$ ./naive_snapshotter \
214-
-address /var/run/firecracker-containerd/naive-snapshotter.sock \
215-
-path /tmp/fc-snapshot
283+
$ ./devmapper_snapshotter \
284+
-address /var/run/firecracker-containerd/devmapper-snapshotter.sock \
285+
-path /tmp/fc-snapshot \
286+
-config /etc/firecracker-dm-snapshotter/config.json
216287
```
288+
`note: The path for -config needs to match the location used when configuring the devmapper snapshotter.`
217289

218290
In another terminal, start containerd
219291

@@ -226,15 +298,15 @@ Pull an image
226298

227299
```bash
228300
$ sudo firecracker-ctr --address /run/firecracker-containerd/containerd.sock images \
229-
pull --snapshotter firecracker-naive \
301+
pull --snapshotter firecracker-devmapper\
230302
docker.io/library/busybox:latest
231303
```
232304

233305
And start a container!
234306

235307
```bash
236308
$ sudo firecracker-ctr --address /run/firecracker-containerd/containerd.sock \
237-
run --snapshotter firecracker-naive --runtime aws.firecracker \
309+
run --snapshotter firecracker-devmapper --runtime aws.firecracker \
238310
--rm --tty --net-host \
239311
docker.io/library/busybox:latest busybox-test
240312
```
@@ -249,7 +321,7 @@ $ sudo firecracker-ctr --address /run/firecracker-containerd/containerd.sock \
249321
$ sudo firecracker-ctr --address /run/firecracker-containerd/containerd.sock \
250322
namespaces label fc \
251323
containerd.io/defaults/runtime=aws.firecracker \
252-
containerd.io/defaults/snapshotter=firecracker-naive
324+
containerd.io/defaults/snapshotter=firecracker-devmapper
253325

254326
$ sudo firecracker-ctr --address /run/firecracker-containerd/containerd.sock \
255327
-n fc \

0 commit comments

Comments
 (0)