ラベル LXC の投稿を表示しています。 すべての投稿を表示
ラベル LXC の投稿を表示しています。 すべての投稿を表示

2020/10/13

Plamo Linux 7.2でLXCを使ってみる (その3)

前回までに作ったコンテナではパスワードを変更できません。
そこで新しくPlamo-6.xのコンテナを作成してみて比較してみます。


takahiro@plamovaio:~$ lxc-create --name plamolxc03 --template download -- --dist plamo --release 6.x --arch amd64
Setting up the GPG keyring
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs

---
You just created an Plamolinux 6.x x86_64 (20201013_01:33) container.

takahiro@plamovaio:~$ lxc-start -n plamolxc03

takahiro@plamovaio:~$ lxc-attach -n plamolxc03
bash-4.3# passwd
新しい UNIX パスワードを入力してください:
新しい UNIX パスワードを再入力してください:
passwd: パスワードは正しく更新されました
 
 
呆気なくパスワードの変更ができました。
 
Plamo-7.xとPlamo-6.xでは何か違うのでしょうか? 

Plamo-MLの[plamo:33410] pkgtools7でPlamo-7.xのコンテナが動かないってあるけれど、これが原因なのでしょうか。

Plamo Linux 7.2でLXCを使ってみる その2(失敗)

(2020年10月27日追記)
Plamo LinuxのMLで下記のパスワード変更ができない問題について修正されたとありました。

takahiro@plamovaio:~$ lxc-create -n plamolxc -t download -- --flush-cache -d plamo -r 7.x -a amd64
Flushing the cache...
Setting up the GPG keyring
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs

---
You just created an Plamolinux 7.x x86_64 (20201027_01:33) container.
takahiro@plamovaio:~$ lxc-start -n plamolxc
takahiro@plamovaio:~$ lxc-attach -n plamolxc
bash-4.4# passwd
新しいUNIXパスワード:
新しいUNIXパスワードを再入力してください:
passwd: パスワードは正しく更新されました

パスワードの変更が問題なくできました。

以下の文章は古いです。

(2020年10月27日追記 終わり)

こちらの続きです。
 
コンテナとやらが起動したので使ってみます。
 
$ lxc-attach -n plamolxc02
bash-4.4# id
uid=0(root) gid=0(root) groups=0(root) 
bash-4.4# hostname
plamolxc02

 
無事起動はしているようです…が、パスワードの変更ができません。

bash-4.4# passwd
パスワード: 認証トークン操作エラー
passwd: パスワードは変更されませんでした

こういう時は英語でググってみた方が良いと思うのでLANG=Cの時の
# LANG=C passwd
passwd: Authentication token manipulation error
passwd: password unchanged

ググってみたらこちらの記事を見つけました。
 
pwconvコマンドを実行すれば良いとありますが、コンテナ上のPlamo Linuxにはpwconvコマンドがありません。
母艦のPlamo-7.xにはあります。
 
そこで、Plamo-7.xの shadow-4.8.1-x86_64-B1.txzをコンテナ上のPlamo Linuxにコピーしてインストールしてみます。

母艦上で下記のようにLXCのrootユーザのホームディレクトリにコピーしました。
takahiro@plamovaio:~$ sudo cp shadow-4.8.1-x86_64-B1.txz  ~/.local/share/lxc/plamolxc02/rootfs/root/
 
そしてコンテナ上でインストールします。
 
bash-4.4# cd /root
bash-4.4# ls
shadow-4.8.1-x86_64-B1.txz
bash-4.4# /sbin/installpkg shadow-4.8.1-x86_64-B1.txz
bash: /sbin/installpkg: /sbin/installer/sh: 誤ったインタプリタです: そのようなファイルやディレクトリはありません

エラーになってインストールできない…。
仕方ないので手動でインストールします。

bash-4.4# tar xvf shadow-4.8.1-x86_64-B1.txz -C /
bash-4.4# /usr/sbin/pwconv
bash-4.4# passwd
パスワード: 認証トークン操作エラー
passwd: パスワードは変更されませんでした

駄目でした。

Plamo Linux 7.2でLXCを使ってみる

よく分からずやっています。
真似しないでください
 
とりあえず実行してみた備忘録です。
これから色々調べます。
 
こちらを参考にしました。 
Ubuntu 14.04 LTS での非特権コンテナ
 
 
Plamo Linux 7.x
lxc-4.0.4
という環境です。
 
 
takahiroユーザで非特権コンテナを作成します。
 
まず/etc/subuidと/etc/subgidを作成しるため、以下コマンドを実行しました。

takahiro@plamovaio:~$ sudo usermod -v 100000-165535 -w 100000-165535 takahiro

takahiro@plamovaio:~$ cat /etc/subuid /etc/subgid
takahiro:100000:65536
takahiro:100000:65536

takahiro@plamovaio:~$ echo "takahiro veth lxcbr0 10" | sudo tee -a /etc/lxc/lxc-usernet
takahiro veth lxcbr0 10

takahiro@plamovaio:~$ echo "session optional        pam_cgfs.so -c all" | sudo tee -a /etc/pam.d/system-session 
session optional        pam_cgfs.so -c all

ここで再起動しました。ログアウトしてログインだとだめでした。


次に$HOME/.config/lxc/default.confを作成します。
参考にしたサイトではlxc.id_mapになっていましたが、これだとlxc-create実行時にエラーになってしまいます。
 
こちらを見たところlxc.idmapになっていたので、私の方もそうしましたところエラーにはならなくなりました。
lxcのバージョンによって違うのでしょうか?
まだ調べていません。
 
takahiro@plamovaio:~$ cd
takahiro@plamovaio:~$ mkdir -p .config/lxc
takahiro@plamovaio:~$ cp /etc/lxc/default.conf .config/lxc/
takahiro@plamovaio:~$ vim .config/lxc/default.conf
takahiro@plamovaio:~$ cat .config/lxc/default.conf
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx

lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536


コンテナを作成します。

takahiro@plamovaio:~$ lxc-create --name plamolxc02 --template download -- --dist plamo --release 7.x --arch amd64
Setting up the GPG keyring
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs

---
You just created an Plamolinux 7.x x86_64 (20201013_01:33) container.
 
takahiro@plamovaio:~ lxc-ls --fancy
NAME       STATE   AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED
plamolxc02 STOPPED 0         -      -    -    true         


コンテナを起動します…が、エラーに。

takahiro@plamovaio:~$ lxc-start -n plamolxc02
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/lxccontainer.c: wait_on_daemonized_start: 849 Received container state "ABORTING" instead of "RUNNING"
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 308 The container failed to start
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 311 To get more details, run the container in foreground mode
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 313 Additional information can be obtained by setting the --logfile and --logpriority options

takahiro@plamovaio:~$ sudo /etc/rc.d/init.d/lxc start
  *  Starting LXC autoboot containers: 
takahiro@plamovaio:~$ lxc-start -n plamolxc02
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/lxccontainer.c: wait_on_daemonized_start: 849 Received container state "ABORTING" instead of "RUNNING"
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 308 The container failed to start
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 311 To get more details, run the container in foreground mode
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 313 Additional information can be obtained by setting the --logfile and --logpriority options

takahiro@plamovaio:~$ sudo /etc/rc.d/init.d/lxcfs start
  *  Starting... LXCFS
takahiro@plamovaio:~$ lxc-start -n plamolxc02
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/lxccontainer.c: wait_on_daemonized_start: 849 Received container state "ABORTING" instead of "RUNNING"
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 308 The container failed to start
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 311 To get more details, run the container in foreground mode
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 313 Additional information can be obtained by setting the --logfile and --logpriority options

takahiro@plamovaio:~$ sudo /etc/rc.d/init.d/cgroupfs-mount start
     Mounting cgroupfs hierarchymount: /sys/fs/cgroup/systemd: cgroup は /sys/fs/cgroup にマウント済みです.
takahiro@plamovaio:~$ lxc-start -n plamolxc02
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/lxccontainer.c: wait_on_daemonized_start: 849 Received container state "ABORTING" instead of "RUNNING"
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 308 The container failed to start
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 311 To get more details, run the container in foreground mode
lxc-start: plamolxc02: /Plamo-src/plamo/16_virtualization/lxc/lxc-4.0.4/src/lxc/tools/lxc_start.c: main: 313 Additional information can be obtained by setting the --logfile and --logpriority options

ここでやっとログファイルを見てみようという気に。
takahiro@plamovaio:~ lxc-start -n plamolxc02 --logfile /tmp/lxc-start.log --logpriority DEBUG


/tmp/lxc-start.logを見ると、次のようなエラーがあります。
 
lxc-4.0.4/src/lxc/start.c:print_top_failing_dir:98 - Permission denied - Could not access /home/takahiro/.local/share. Please grant it x access, or add an ACL for the container root

良いのか分かりませんが、chmod +x しろというエラーのようです。
してみます。

takahiro@plamovaio:~$ ls -l /home/takahiro/.local/
合計 8,192
drwxr-xr-x  3 takahiro users 4,096 10月  6日  22:19 lib/
drwx------ 11 takahiro users 4,096 10月 13日  18:58 share/

takahiro@plamovaio:~$ chmod +x /home/takahiro/.local/share
 
takahiro@plamovaio:~$ ls -l /home/takahiro/.local/
合計 8,192
drwxr-xr-x  3 takahiro users 4,096 10月  6日  22:19 lib/
drwx--x--x 11 takahiro users 4,096 10月 13日  18:58 share/

再度lxc-startを実行します。
takahiro@plamovaio:~$ lxc-start -n plamolxc02
takahiro@plamovaio:~$

何のエラーもなく起動しました。

takahiro@plamovaio:~$ lxc-ls --fancy
NAME       STATE   AUTOSTART GROUPS IPV4      IPV6 UNPRIVILEGED
plamolxc02 RUNNING 0         -      10.0.3.66 -    true