如何构建镜像¶
纯根文件系统¶
$ distrobuilder build-dir --help
Build plain rootfs
Usage:
distrobuilder build-dir <filename|-> <target dir> [flags]
Flags:
-h, --help help for build-dir
--keep-sources Keep sources after build (default true)
--sources-dir Sources directory for distribution tarballs (default "/tmp/distrobuilder")
--with-post-files Run post-files actions
Global Flags:
--cache-dir Cache directory
--cleanup Clean up cache directory (default true)
--debug Enable debug output
--disable-overlay Disable the use of filesystem overlays
-o, --options Override options (list of key=value)
-t, --timeout Timeout in seconds
--version Print version number
要构建纯根文件系统,请运行 distrobuilder build-dir
。该命令将镜像定义文件和输出目录作为位置参数。运行 build-dir
对于希望同时构建 LXC 和 Incus 镜像的情况非常有用。在这种情况下,只需运行
distrobuilder build-dir def.yaml /path/to/rootfs
distrobuilder pack-lxc def.yaml /path/to/rootfs /path/to/output
distrobuilder pack-incus def.yaml /path/to/rootfs /path/to/output
LXC 镜像¶
$ distrobuilder build-lxc --help
Build LXC image from scratch
The compression can be set with the --compression flag. I can take one of the
following values:
- bzip2
- gzip
- lzip
- lzma
- lzo
- lzop
- xz (default)
- zstd
For supported compression methods, a compression level can be specified with
method-N, where N is an integer, e.g. gzip-9.
Usage:
distrobuilder build-lxc <filename|-> [target dir] [--compression=COMPRESSION] [flags]
Flags:
--compression Type of compression to use (default "xz")
-h, --help help for build-lxc
--keep-sources Keep sources after build (default true)
--sources-dir Sources directory for distribution tarballs (default "/tmp/distrobuilder")
Global Flags:
--cache-dir Cache directory
--cleanup Clean up cache directory (default true)
--debug Enable debug output
--disable-overlay Disable the use of filesystem overlays
-o, --options Override options (list of key=value)
-t, --timeout Timeout in seconds
--version Print version number
运行 build-lxc
子命令会创建一个 LXC 镜像。它输出两个文件 rootfs.tar.xz
和 meta.tar.xz
。构建镜像后,根文件系统将被销毁。
可以使用 pack-lxc
子命令从现有根文件系统创建镜像。根文件系统之后不会被删除。
Incus 镜像¶
$ distrobuilder build-incus --help
Build Incus image from scratch
Depending on the type, it either outputs a unified (single tarball)
or split image (tarball + squashfs or qcow2 image). The --type flag can take one of the
following values:
- split (default)
- unified
The compression can be set with the --compression flag. I can take one of the
following values:
- bzip2
- gzip
- lzip
- lzma
- lzo
- lzop
- xz (default)
- zstd
For supported compression methods, a compression level can be specified with
method-N, where N is an integer, e.g. gzip-9.
Usage:
distrobuilder build-incus <filename|-> [target dir] [--type=TYPE] [--compression=COMPRESSION] [--import-into-incus] [flags]
Flags:
--compression Type of compression to use (default "xz")
-h, --help help for build-incus
--import-into-incus[="-"] Import built image into Incus
--keep-sources Keep sources after build (default true)
--sources-dir Sources directory for distribution tarballs (default "/tmp/distrobuilder")
--type Type of tarball to create (default "split")
--vm Create a qcow2 image for VMs
Global Flags:
--cache-dir Cache directory
--cleanup Clean up cache directory (default true)
--debug Enable debug output
--disable-overlay Disable the use of filesystem overlays
-o, --options Override options (list of key=value)
-t, --timeout Timeout in seconds
--version Print version number
运行 build-incus
子命令会创建一个 Incus 镜像。如果使用 --type=split
,它会输出两个文件。元数据 tarball 的名称始终为 incus.tar.xz
。创建容器镜像时,第二个文件将为 rootfs.squashfs
。创建 VM 镜像时,第二个文件将为 disk.qcow2
。如果使用 --type=unified
,则会创建一个名为 <image.name>.tar.xz
的统一 tarball。有关镜像名称的更多信息,请参见 镜像部分。
如果设置了 --compression
,则 tarball 将使用提供的压缩方式而不是 xz
。
设置 --vm
将创建一个用于虚拟机的 qcow2
镜像。
如果设置了 --import-into-incus
,则生成的镜像将导入到 Incus 中。它基本上运行 lxc image import <image>
。默认情况下,它不会创建别名。这可以通过将其称为 --import-into-incus=<alias>
来更改。
构建镜像后,根文件系统将被销毁。
可以使用 pack-incus
子命令从现有根文件系统创建镜像。根文件系统之后不会被删除。