參考:
debian wiki lxc
和
raspberry pi 手動 root image
安裝完 lxc, libvirt-bin
用 lxc-checkconfig
說 找步道,所以 follow 他得說明:
modprobe configs 再 run 一次..
pi@raspberrypi:~ $ sudo lxc-checkconfig
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: missing
Network namespace: enabled
Multiple /dev/pts instances: enabled
--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: missing
--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig
lxc-create 會到 debian.org 去找 root image, 但是raspbian 用的是 raspbian.org, 所以會fail:
Cannot check Release signature; keyring file not available /usr/share/keyrings/debian-archive-keyring.pgp
這一篇 有說,要修改 lxc-templete
在 /usr/share/lxc/templates 中新增一個 lxc-raspbian
然後就可以用 lxc-create 來 create 一個 raspbian 的 root image
lxc-raspbian 就從 lxc-debian 改。
就改 MIRROR 就好,把 debian.org 改 raspbian.org
結果 fail,, 一堆不能 download..
E: Couldn't download packages: cpio dash debconf debconf-i18n debianutils dialog diffutils dmsetup dpkg e2fslibs e2fsprogs findutils
gcc-4.6-base gcc-4.7-base gcc-4.8-base gcc-4.9-base gnupg gpgv grep gzip hostname ifupdown init init-system-helpers initramfs-tools
initscripts insserv iproute iproute2 isc-dhcp-client isc-dhcp-common klibc-utils kmod libacl1 libapt-pkg4.12 libattr1 libaudit-common
libaudit1 libblkid1 libbsd0 libbz2-1.0 libc-bin libc6 libcap2 libcap2-bin libcomerr2 libcryptsetup4 libdb5.3 libdbus-1-3 libdebconfclient0
libdevmapper1.02.1 libdns-export100 libdrm2 libedit2 libgcc1 libgcrypt20
直接 root 帳號run lxc-create debian ...
download OK, 最後 ..
W: Failure trying to run: chroot /var/cache/lxc/debian/partial-jessie-armhf mount -t proc proc /proc
W: See /var/cache/lxc/debian/partial-jessie-armhf/debootstrap/debootstrap.log for details
Failed to download the rootfs, aborting.
Failed to download 'debian base'
failed to install debian
lxc_container: container creation template for debian8 failed
去 /var/cache/lxc/debian/下是空的。
這一篇 好像有上面的解答。
他提供一個 lxc-pi, 然後遇到一樣的 mount proc fail 時的解法..
最後還是用手動的,用 debootstrap 建立 root image..
Link
pi@raspberrypi:~ $ sudo mkdir -p /var/lxc/guests/tt2
pi@raspberrypi:~ $ sudo http_proxy="http://myproxy:3128" debootstrap jessie /var/lxc/guests/tt2/fs/ http://archive.raspbian.org/raspbian
然後進去改 password..
pi@raspberrypi:~ $ sudo chroot /var/lxc/guests/tt2/fs/
root@raspberrypi:/# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@raspberrypi:/# exit
做 config 檔
pi@raspberrypi:~ $ sudo vi /var/lxc/guests/tt2/config
內容是..
lxc.utsname = tt2
lxc.tty = 2
lxc.rootfs = /var/lxc/guests/tt2/fs
create:
pi@raspberrypi:~ $ sudo lxc-create -f /var/lxc/guests/tt2/config -n tt2
啟動..
pi@raspberrypi:~ $ sudo lxc-start -n tt2
systemd 215 running in system mode. (+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR)
Detected virtualization 'lxc'.
Detected architecture 'arm'.
Welcome to Raspbian GNU/Linux 8 (jessie)!
Set hostname to .
Cannot add dependency job for unit dbus.socket, ignoring: Unit dbus.socket failed to load: No such file or directory.
Cannot add dependency job for unit display-manager.service, ignoring: Unit display-manager.service failed to load: No such file or directory.
[ OK ] Reached target Remote File Systems (Pre).
....
....
[ OK ] Started Update UTMP about System Runlevel Changes.
Raspbian GNU/Linux 8 raspberrypi console
raspberrypi login: root
Password:
Linux raspberrypi 4.4.11+ #888 Mon May 23 20:02:58 BST 2016 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@raspberrypi:~#
要退出的話,好像要 poweroff -- 跟正常電腦關機一樣...
-d run 在背景用 lxc-console 的話沒有反應。
只能 run 在前景。
升級到 stretch 後,default 變成 daemon mode,所以反而要加 '-F' 指定開在 foreground mode