パッケージの更新 でパッケージを更新しておきます。
apt install でパッケージを追加します。
root@max3xx-devel:/# apt install lxc lxc-templates lxc-utils Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: arch-test binutils binutils-aarch64-linux-gnu binutils-common bridge-utils busybox-static cloud-image-utils debootstrap dirmngr distro-info dns-root-data dnsmasq-base fakechroot fakeroot genisoimage gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm ibverbs-providers libaio1 libassuan0 libbinutils libboost-iostreams1.74.0 libboost-thread1.74.0 libctf-nobfd0 libctf0 libcurl3-gnutls libdaxctl1 libdistro-info-perl libdpkg-perl libfakechroot libfakeroot libfile-fcntllock-perl libfuse3-3 libgdbm-compat4 libgdbm6 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 libiscsi7 libksba8 liblxc-common liblxc1 libmpdec3 libndctl6 libnpth0 libnuma1 libpam-cgfs libperl5.34 libpmem1 libpmemobj1 libpython3-stdlib libpython3.10-stdlib librados2 librbd1 librdmacm1 liburing2 lxcfs media-types mmdebstrap perl perl-modules-5.34 pinentry-curses python3 python3.10 qemu-block-extra qemu-utils rsync uidmap uuid-runtime Suggested packages: binutils-doc mtools squid-deb-proxy-client debian-archive-keyring dbus-user-session pinentry-gnome3 tor shunit2 wodim cdrkit-doc parcimonie xloadimage scdaemon debian-keyring gcc | c-compiler patch git bzr fuse3 gdbm-l10n qemu-user-static btrfs-tools lvm2 lxctl apt-transport-tor binfmt-support dpkg-dev genext2fs perl-doc proot qemu-user squashfs-tools-ng libterm-readline-gnu-perl | libterm-readline-perl-perl make libtap-harness-archive-perl pinentry-doc python3-doc python3-tk python3-venv python3.10-venv python3.10-doc python3-braceexpand The following packages will be REMOVED: busybox The following NEW packages will be installed: arch-test binutils binutils-aarch64-linux-gnu binutils-common bridge-utils busybox-static cloud-image-utils debootstrap dirmngr distro-info dns-root-data dnsmasq-base fakechroot fakeroot genisoimage gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm ibverbs-providers libaio1 libassuan0 libbinutils libboost-iostreams1.74.0 libboost-thread1.74.0 libctf-nobfd0 libctf0 libcurl3-gnutls libdaxctl1 libdistro-info-perl libdpkg-perl libfakechroot libfakeroot libfile-fcntllock-perl libfuse3-3 libgdbm-compat4 libgdbm6 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 libiscsi7 libksba8 liblxc-common liblxc1 libmpdec3 libndctl6 libnpth0 libnuma1 libpam-cgfs libperl5.34 libpmem1 libpmemobj1 libpython3-stdlib libpython3.10-stdlib librados2 librbd1 librdmacm1 liburing2 lxc lxc-templates lxc-utils lxcfs media-types mmdebstrap perl perl-modules-5.34 pinentry-curses python3 python3.10 qemu-block-extra qemu-utils rsync uidmap uuid-runtime 0 upgraded, 81 newly installed, 1 to remove and 3 not upgraded. Need to get 31.5 MB of archives. After this operation, 138 MB of additional disk space will be used. Do you want to continue? [Y/n]
Do you want to continue? [Y/n] Get:1 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 busybox-static arm64 1:1.30.1-7ubuntu3 [920 kB] Get:2 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 media-types all 7.0.0 [25.5 kB] Get:3 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libmpdec3 arm64 2.5.1-2build2 [89.0 kB] Get:4 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libpython3.10-stdlib arm64 3.10.6-1~22.04.2ubuntu1 [1828 kB] .... Setting up liblxc1 (1:5.0.0~git2209-g5a7b9ce67-0ubuntu1) ... Setting up lxc-utils (1:5.0.0~git2209-g5a7b9ce67-0ubuntu1) ... Created symlink /etc/systemd/system/multi-user.target.wants/lxc-monitord.service → /lib/systemd/system/lxc-monitord.s ervice. Created symlink /etc/systemd/system/multi-user.target.wants/lxc-net.service → /lib/systemd/system/lxc-net.service. Created symlink /etc/systemd/system/multi-user.target.wants/lxc.service → /lib/systemd/system/lxc.service. Setting up lxc dnsmasq configuration. Setting up lxc (1:5.0.0~git2209-g5a7b9ce67-0ubuntu1) ... Setting up lxc-templates (3.0.4-5) ... Setting up liblxc-common (1:5.0.0~git2209-g5a7b9ce67-0ubuntu1) ... Processing triggers for dbus (1.12.20-2ubuntu4.1) ... Processing triggers for initramfs-tools (0.136ubuntu6.7) ... Processing triggers for libc-bin (2.35-0ubuntu3.1) ... root@max3xx-devel:/#
MA-X3xx の動作環境でうまく動作しない部分1)と、テンプレート2)が壊れている部分を修正したパッケージを、入れ替える形でインストールします。
File | STAT | SHA1SUM | Note |
---|---|---|---|
lxc-templates_3.0.4-5_arm64.deb | 2023/04/13 14:04 84.9 KB | 62fabf8ed0fe11d7f2d957e512822ae3f6db6aba | Alpine Linux テンプレート修正 |
lxc-utils_5.0.0_git2209-g5a7b9ce67-0ubuntu1_arm64.deb | 2023/04/13 14:04 443.4 KB | 61df5c3fa823ac6f37a2743483258ad89caad916 | dnsmasq, iptables 変更 |
LXC の仮想環境は /var/lib/lxc 以下に配置されるため、起動時に eMMC/SD/SSD など3)の領域を /var/lib/lxc に mount する設定をしておきます。
root@max3xx-devel:/etc/systemd/system# nano -w var-lib-lxc.mount
[Unit] Description=LXC eMMC [Mount] What=/dev/mmcblk0p2 Where=/var/lib/lxc Type=ext4 Options=noatime [Install] WantedBy=multi-user.target
※ What の部分を mount するデバイスに応じて変更してください。
.mount ファイルを保存したら、自動で mount するように設定しておきます。
root@max3xx-devel:/etc/systemd/system# systemctl enable var-lib-lxc.mount Created symlink /etc/systemd/system/multi-user.target.wants/var-lib-lxc.mount → /etc/systemd/system/var-lib-lxc.mount. root@max3xx-devel:/etc/systemd/system#
ファームウェアの作成 の手順でファームウェアを作成し、実機のファームウェアを更新します。
user1@max3xx-devel:~/work$ sudo ./build_firm.sh -k ../src/linux-kernel -r max3xx_jammy_rootfs -o firmware/lxc_firmware.img
.... adding: k3-am642-centurysys-metis-ext-02.dtbo (deflated 77%) adding: k3-am642-centurysys-metis-mod-01.dtbo (deflated 52%) adding: k3-am642-centurysys-metis-mod-02.dtbo (deflated 52%) * Firmware filename: /home/user1/work/firmware/lxc_firmware.img Archive: /home/user1/work/firmware/lxc_firmware.img Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 1404928 Stored 1404928 0% 2023-04-13 10:37 f4443553 kmod.img 4231352 Stored 4231352 0% 2023-04-13 10:38 01c418ba initramfs.img 113537024 Stored 113537024 0% 2023-04-13 10:37 829762e9 rootfs.img 17172488 Defl:N 7284572 58% 2023-04-13 10:37 1fb808bf kernel.img 143194 Defl:N 32634 77% 2023-04-13 10:37 3f4db7a3 .config 54817 Defl:N 12585 77% 2023-04-13 10:37 70571b03 k3-am642-centurysys-metis-00.dtb 55231 Defl:N 12691 77% 2023-04-13 10:37 9cf86377 k3-am642-centurysys-metis-01.dtb 7132 Defl:N 1662 77% 2023-04-13 10:37 b006b511 k3-am642-centurysys-metis-ext-01.dtbo 7838 Defl:N 1834 77% 2023-04-13 10:37 24ce757a k3-am642-centurysys-metis-ext-02.dtbo 579 Defl:N 280 52% 2023-04-13 10:37 045db4c9 k3-am642-centurysys-metis-mod-01.dtbo 579 Defl:N 280 52% 2023-04-13 10:37 045db4c9 k3-am642-centurysys-metis-mod-02.dtbo -------- ------- --- ------- 136615162 126519842 7% 11 files done. please remove working directory '/home/user1/work/build_1681349838' manually. user1@max3xx-devel:~/work$
user1@max3xx-devel:~/work$ ls -l firmware/ total 216328 -rw-r--r-- 1 root root 94987000 Apr 12 18:00 firmware.img -rw-r--r-- 1 root root 126521792 Apr 13 10:38 lxc_firmware.img <---- 通常より 30MiB ほど大きい user1@max3xx-devel:~/work$
LXC インストール済みファームウェア に置いてあります。
ファームウェアを更新して再起動し、実機に SSH でログインします。
LXC はテンプレートから作成するのが簡単なので、テンプレート一覧を確認してみます。
root@metis:~# ls /usr/share/lxc/templates/ lxc-alpine lxc-centos lxc-fedora lxc-oci lxc-plamo lxc-sparclinux lxc-voidlinux lxc-altlinux lxc-cirros lxc-fedora-legacy lxc-openmandriva lxc-pld lxc-sshd lxc-archlinux lxc-debian lxc-gentoo lxc-opensuse lxc-sabayon lxc-ubuntu lxc-busybox lxc-download lxc-local lxc-oracle lxc-slackware lxc-ubuntu-cloud
MA-X3xx のアーキテクチャ4) では使用できないテンプレート5)も含まれていますが、Alpine Linux や本体と同じ Ubuntu などが使えます。
試しに、軽量の Alpine Linux のテンプレートを使用してコンテナを作成してみます。
root@metis:~# lxc-create -n alpine -t alpine -- -r edge Obtaining an exclusive lock... done ==> Fetching and/or verifying APK keys alpine-devel@lists.alpinelinux.org-4a6a0840.rsa.pub: OK alpine-devel@lists.alpinelinux.org-5243ef4b.rsa.pub: OK alpine-devel@lists.alpinelinux.org-524d27bb.rsa.pub: OK alpine-devel@lists.alpinelinux.org-5261cecb.rsa.pub: OK alpine-devel@lists.alpinelinux.org-58199dcc.rsa.pub: OK alpine-devel@lists.alpinelinux.org-58cbb476.rsa.pub: OK alpine-devel@lists.alpinelinux.org-58e4f17d.rsa.pub: OK alpine-devel@lists.alpinelinux.org-5e69ca50.rsa.pub: OK alpine-devel@lists.alpinelinux.org-60ac2099.rsa.pub: OK alpine-devel@lists.alpinelinux.org-6165ee59.rsa.pub: OK alpine-devel@lists.alpinelinux.org-61666e3f.rsa.pub: OK alpine-devel@lists.alpinelinux.org-616a9724.rsa.pub: OK alpine-devel@lists.alpinelinux.org-616abc23.rsa.pub: OK alpine-devel@lists.alpinelinux.org-616ac3bc.rsa.pub: OK alpine-devel@lists.alpinelinux.org-616adfeb.rsa.pub: OK alpine-devel@lists.alpinelinux.org-616ae350.rsa.pub: OK alpine-devel@lists.alpinelinux.org-616db30d.rsa.pub: OK Obtaining an exclusive lock... done ==> Installing Alpine Linux in /var/lib/lxc/alpine/rootfs (1/25) Installing alpine-baselayout-data (3.4.0-r0) (2/25) Installing musl (1.2.3_git20230322-r3) (3/25) Installing busybox (1.36.0-r7) Executing busybox-1.36.0-r7.post-install (4/25) Installing busybox-binsh (1.36.0-r7) (5/25) Installing alpine-baselayout (3.4.0-r0) Executing alpine-baselayout-3.4.0-r0.pre-install Executing alpine-baselayout-3.4.0-r0.post-install (6/25) Installing ifupdown-ng (0.12.1-r2) (7/25) Installing libcap2 (2.68-r2) (8/25) Installing openrc (0.46-r4) Executing openrc-0.46-r4.post-install (9/25) Installing mdev-conf (4.4-r0) (10/25) Installing busybox-mdev-openrc (1.36.0-r7) (11/25) Installing alpine-conf (3.15.1-r2) (12/25) Installing alpine-keys (2.4-r1) (13/25) Installing alpine-release (3.18_alpha20230329-r0) (14/25) Installing ca-certificates-bundle (20230106-r1) (15/25) Installing libcrypto3 (3.1.0-r3) (16/25) Installing libssl3 (3.1.0-r3) (17/25) Installing ssl_client (1.36.0-r7) (18/25) Installing zlib (1.2.13-r1) (19/25) Installing apk-tools (2.14.0_rc1-r0) (20/25) Installing busybox-openrc (1.36.0-r7) (21/25) Installing busybox-suid (1.36.0-r7) (22/25) Installing scanelf (1.3.7-r1) (23/25) Installing musl-utils (1.2.3_git20230322-r3) (24/25) Installing libc-utils (0.7.2-r4) (25/25) Installing alpine-base (3.18_alpha20230329-r0) Executing busybox-1.36.0-r7.trigger OK: 13 MiB in 25 packages ==> Container's rootfs and config have been created Edit the config file /var/lib/lxc/alpine/config to check/enable networking setup. The installed system is preconfigured for a loopback and single network interface configured via DHCP. To start the container, run "lxc-start -n alpine". The root password is not set; to enter the container run "lxc-attach -n alpine". root@metis:~#
コンテナのリストを確認してみます。
root@metis:~# lxc-ls --fancy NAME STATE AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED alpine STOPPED 0 - - - false root@metis:~#
作成したコンテナを起動してみます。
root@metis:~# lxc-start -n alpine root@metis:~#
起動したようです。DHCP でアドレスを取得するまで少し時間をおいてから、再びコンテナのリストを確認してみます。
root@metis:~# lxc-ls --fancy NAME STATE AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED alpine RUNNING 0 - 10.0.3.197 - false root@metis:~#
状態が “RUNNING”、アドレス 10.0.3.197 で起動していることが確認できました。