Skip to content

Instantly share code, notes, and snippets.

@wallnerryan
Last active August 29, 2015 14:25
Show Gist options
  • Save wallnerryan/162d0f7ef64fed7afa57 to your computer and use it in GitHub Desktop.
Save wallnerryan/162d0f7ef64fed7afa57 to your computer and use it in GitHub Desktop.
LXC on Pi with mounts for data
(Check Kernel)
--------------
CONFIG=/home/pi/linux/.config lxc-checkconfig
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: required
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled
--- Control groups ---
Cgroup: enabled
Cgroup namespace: required
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
--- Misc ---
Veth pair device: enabled
Macvlan: missing
Vlan: missing
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/local/bin/lxc-checkconfig
(Mounted CGroups)
---------------
You should see the cgroup mount in fstab, and available cgroups after running mount -a
root@raspberrypi:/opt/lxc/lxc# vi /etc/fstab
root@raspberrypi:/opt/lxc/lxc# mount -a
root@raspberrypi:/opt/lxc/lxc# mount
/dev/root on / type ext4 (rw,noatime,data=ordered)
.
.
lxc on /sys/fs/cgroup type cgroup (rw,relatime,cpuset,cpu,cpuacct,blkio,devices,freezer,net_cls)
(Containers live in /var/lxc/guests)
----------------------------------
(Creat a container)
-------------------
root@raspberrypi:/opt/lxc/lxc# lxc-create -t debian -n test
root@raspberrypi:/opt/lxc/lxc# lxc-start -n test -d
root@raspberrypi:/opt/lxc/lxc# lxc-ls
test
root@raspberrypi:/opt/lxc/lxc# lxc-info -n test
Name: test
State: RUNNING
PID: 14196
CPU use: 1.09 seconds
BlkIO use: 5.70 MiB
root@raspberrypi:/opt/lxc/lxc# lxc-console -n test
Connected to tty 1
Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself
root@test:~#
root@test:~#
root@test:~# hostname
test
root@raspberrypi:/opt/lxc/lxc# ls /usr/local/var/lib/lxc/test/
config rootfs
(We can add mounts to containers by editing the 'config' file like the below:)
(This can act as mechanism for adding data into containers)
----------------------------------------------------------------------------
root@raspberrypi:/opt/lxc/lxc# vi /usr/local/var/lib/lxc/test/config
add
lxc.mount.entry=/mnt/data /usr/local/var/lib/lxc/test/rootfs/mount_point none bind 0 0
root@raspberrypi:/opt/lxc/lxc# mkdir /usr/local/var/lib/lxc/test/rootfs/srv/mount_point
root@raspberrypi:/opt/lxc/lxc# mkdir /mnt/data
root@raspberrypi:/opt/lxc/lxc# touch /mnt/data/hi
root@raspberrypi:/opt/lxc/lxc# lxc-stop -n test
root@raspberrypi:/opt/lxc/lxc# lxc-start -n test
root@raspberrypi:/opt/lxc/lxc# lxc-attach -n test
root@test:/# ls mount_point/
hi
( We would then tar up the rootfs with the mounted data directory and config and move it to anoher pi running this )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment