[lxc-users] lxc-create try rsync data to device instead mount point

mxs kolo kolomaxes at gmail.com
Mon Jul 7 08:51:52 UTC 2014


HI all

I try create lxc with lvm+xfs with template centos.
But template lxc-centos accidentally trying copy centos to raw device:

[root at node01 mkozin]# lxc-create --template centos   -n mk1   -B lvm
--vgname data --fstype xfs --fssize 15G  -- --release=6 --arch=x86_64
--repo http://centos-mirror.rbc.ru/pub/centos/
File descriptor 3 (/var/lib/lxc/mk1/partial) leaked on lvcreate
invocation. Parent PID 17960: lxc-create
WARNING: xfs signature detected on /dev/data/mk1 at offset 0. Wipe it? [y/n] y
  Wiping xfs signature on /dev/data/mk1.
  Logical volume "mk1" created
Host CPE ID from /etc/os-release: cpe:/o:centos:centos:7
dnsdomainname: No address associated with hostname
Checking cache download in /var/cache/lxc/centos/x86_64/6/rootfs ...
Cache found. Updating...
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: centos-mirror.rbc.ru
 * extras: centos-mirror.rbc.ru
 * updates: centos-mirror.rbc.ru
base

          | 3.7 kB     00:00
extras

          | 3.4 kB     00:00
updates

          | 3.4 kB     00:00
Setting up Update Process
No Packages marked for Update
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
0 package files removed
Update finished
Copy /var/cache/lxc/centos/x86_64/6/rootfs to /dev/data/mk1 ...
Copying rootfs to /dev/data/mk1 ...mkdir: cannot create directory Б: File exists
rsync: ERROR: cannot stat destination "/dev/data/mk1/": Not a directory (20)
rsync error: errors selecting input/output files, dirs (code 3) at
main.c(565) [Receiver=3.0.9]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at
io.c(605) [sender=3.0.9]
.....

This part of template "lxc-centos" set rootfs path:
 if [ -z "$rootfs_path" ]; then
    rootfs_path=$path/rootfs
    # check for 'lxc.rootfs' passed in through default config by lxc-create
    if grep -q '^lxc.rootfs' $path/config 2>/dev/null ; then
        rootfs_path=$(sed -e '/^lxc.rootfs\s*=/!d' -e 's/\s*#.*//' \
            -e 's/^lxc.rootfs\s*=\s*//' -e q $path/config)
    fi
fi

In my case:
[root at node01 mkozin]# grep rootfs /var/lib/lxc/mk1/config
lxc.rootfs = /dev/data/mk1

Because rootfs set as  /dev/data/mk1

I prepare workaround, but not sure that it's correct way:
[root at node01 mkozin]# diff -uN
/usr/share/lxc/templates/lxc-centos.ORIG
/usr/share/lxc/templates/lxc-centos
--- /usr/share/lxc/templates/lxc-centos.ORIG    2014-07-07
12:39:32.430333034 +0400
+++ /usr/share/lxc/templates/lxc-centos 2014-07-07 12:40:09.431646303 +0400
@@ -843,9 +843,15 @@
             -e 's/^lxc.rootfs\s*=\s*//' -e q $path/config)
     fi
 fi
+
+# fix rootfs and mount workaround:
+rootfs_path="/var/lib/lxc/$utsname/rootfs"
+mount /dev/data/$utsname  $rootfs_path
+
 config_path=$path
 cache=$cache_base/$release

+
 revert()
 {
     echo "Interrupted, so cleaning up"


With fixed lxc-centos,  lxc created correctly:
[root at node01 mkozin]# lxc-create --template centos   -n mk1   -B lvm
--vgname data --fstype xfs --fssize 15G  -- --release=6 --arch=x86_64
--repo http://centos-mirror.rbc.ru/pub/centos/
File descriptor 3 (/var/lib/lxc/mk1/partial) leaked on lvcreate
invocation. Parent PID 18149: lxc-create
WARNING: xfs signature detected on /dev/data/mk1 at offset 0. Wipe it? [y/n] y
  Wiping xfs signature on /dev/data/mk1.
  Logical volume "mk1" created
Host CPE ID from /etc/os-release: cpe:/o:centos:centos:7
dnsdomainname: No address associated with hostname
Checking cache download in /var/cache/lxc/centos/x86_64/6/rootfs ...
Cache found. Updating...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos-mirror.rbc.ru
 * extras: centos-mirror.rbc.ru
 * updates: centos-mirror.rbc.ru
Setting up Update Process
No Packages marked for Update
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
0 package files removed
Update finished
Copy /var/cache/lxc/centos/x86_64/6/rootfs to /var/lib/lxc/mk1/rootfs ...
Copying rootfs to /var/lib/lxc/mk1/rootfs ...
Storing root password in '/var/lib/lxc/mk1/tmp_root_pass'
Expiring password for user root.
passwd: Success

Container rootfs and config have been created.
Edit the config file to check/enable networking setup.

The temporary root password is stored in:

        '/var/lib/lxc/mk1/tmp_root_pass'


The root password is set up as expired and will require it to be changed
at first login, which you should do as soon as possible.  If you lose the
root password or wish to change it without starting the container, you
can change it from the host by running the following command (which will
also reset the expired flag):

        chroot /var/lib/lxc/mk1/rootfs passwd


We can check that rootfs prepared correctly:
[root at node01 mkozin]# mount -t xfs /dev/data/mk1 /media/
[root at node01 mkozin]# mount | grep /media
/dev/mapper/data-mk1 on /media type xfs
(rw,relatime,attr2,inode64,sunit=1024,swidth=2048,noquota)
[root at node01 mkozin]# du -sh /media
384M    /media

umount /media and start lxc:

[root at node01 mkozin]# lxc-info  -n mk1
Name:           mk1
State:          RUNNING
PID:            18337
CPU use:        0.27 seconds
Memory use:     13.53 MiB
KMem use:       0 bytes
Link:           veth1FAYMA
 TX bytes:      1.97 KiB
 RX bytes:      1.60 KiB
 Total bytes:   3.57 KiB

It's bug in lxc-centos template or someone incorrect set lxc.rootfs
in  lxc config ?

b.r.
 Maxim Kozin


More information about the lxc-users mailing list