Header RSS Feed
 
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Do not try to auto-mount containers logical volume during lxc-create
Tuesday - Oct 13th 2015 - by - (0 comments)

For a fully automated deployment using LXC (Linux Containers), I tried to automate the mounting of the containers logical volume at the end of the LXC template:

# If LVM was used, mount it
if [[ -n $(cat $config  | egrep '^lxc.rootfs' | grep dev) ]]; then
  lxclv=$(egrep '^lxc.rootfs' $config | awk -F'=' '{print $2}' | sed 's/ //')
  echo mount -v $lxclv $path/rootfs
  mount -v $lxclv $path/rootfs
  echo "$lxclv $path/rootfs  ext4  defaults  0  0" >> /etc/fstab
fi

Without loosing too many words at the begin: It doesn't work.

As soon as the LXC is created, the rootfs (/var/lib/mytestlxc/rootfs) is empty, although it appears mounted in the mount command:

mount | grep mytestlxc
/dev/mapper/vglxc-mytestlxc on /var/lib/lxc/mytestlxc/rootfs type ext4 (rw)

Even stranger when I try to unmount the supposedly mounted lv:

umount /var/lib/lxc/mytestlxc/rootfs
umount: /var/lib/lxc/mytestlxc/rootfs: not mounted

The LXC template is called by lxc-create (therefore its a child process). Once lxc-create finishes the job, it unmounts the containers logical volume.
Why? During the creation of an LXC container, the rootfs is written into a temporary mounted location:

[...]
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fc45ff1fb90) = 13264
wait4(13264, File descriptor 3 (/var/lib/lxc/mytestlxc/partial) leaked on lvcreate invocation. Parent PID 13264: lxc-create
  Logical volume "mytestlxc" created
[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 13264
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=13264, si_status=0, si_utime=0, si_stime=0} ---
[...]
Copy /var/cache/lxc/trusty/rootfs-amd64 to /usr/lib/x86_64-linux-gnu/lxc ...
Copying rootfs to /usr/lib/x86_64-linux-gnu/lxc ...
[...]

 At the end of lxc-create the "partial" file system is unlinked again:

[...]
close(3)                                = 0
unlink("/var/lib/lxc/mytestlxc/partial") = 0
exit_group(0)                           = ?
+++ exited with 0 +++

To solve this in the automation task, I now mount the LV right after the lxc-start command:

lxc-create -n mytestlxc -B lvm --vgname=vglxc --fstype=ext4 --fssize=2G -t ubuntu-ck && lxc-start -n mytestlxc -d && mount /dev/vglxc/mytestlxc /var/lib/lxc/mytestlxc/rootfs && echo "/dev/vglxc/mytestlxc /var/lib/lxc/mytestlxc/rootfs" >> /etc/fstab


 

Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6939 Days
until Death of Computers
Why?