[lxc-users] 2.1.1 lxc-copy consistently does not set hostname in new copy

Adrian Pepper arpepper at uwaterloo.ca
Mon Nov 27 22:35:34 UTC 2017


Under lxc 2.1.1 (Ubuntu 16.04 lxc1 2.1.1-0ubuntu1~ubuntu16.04.1~ppa1)
it has been consistent for me that "lxc-copy -n oldcontainer -N newcontainer"
will create newcontainer such that it has hostname "oldcontainer".

Since oldcontainer is necessarily stopped, I have been starting the
newcontainer, manually editing /etc/hostname and restarting.

This differs from lxc 2.0 versions where newcontainer will have
hostname "newcontainer" when first started.

The tests I include were actually performed while the main host
(my workstation) was in need of a few updates and a reboot.  I
cleaned that up, and repeated the gist of the test after the reboot,
and the problem appeared the same.

Hmm.  At the last minute I looked for a new option which might affect
the new hostname.  I find (man lxc-copy)...

       -K, --keepname
              When  this option is specified the hostname of the original con‐
              tainer will be kept for the copy.

This option seemed to exist in 2.0.8 also.  (also -M, --keepmac)
There doesn't seem to be opposite options.  (This suggests I should
be checking the Mac addresses also, but I think they must have been
newly allocated or real strangeness would result; lxc-ls has no option
to list Mac address?).  Indeed...

   root at scspc578-1604# cd /var/lib/lxc
   root at scspc578-1604# cat */config | grep lxc'.*'hwaddr | sort | uniq -c | sort -n
   root at scspc578-1604# cat */config | grep lxc'.*'hwaddr | grep -v '^#' | sed 's/^.*= *//' | sort | uniq -c | sort -n

suggests the Mac addresses are not being retained.  (First command allowed
visual verification, and search for anomalies; second confirmed further).
(Each Mac address occurs only once; I don't need to reproduce mine here).

Okay...

   root at scspc578-1604:/var/lib/lxc# cat */config | grep lxc'.*'hwaddr | sort | uniq -c | sort -n | grep -v '^  *1 '
      3 #lxc.net.1.hwaddr = 00:16:3e:77:52:20
   root at scspc578-1604:/var/lib/lxc# cat */config | grep lxc'.*'hwaddr | grep -v '^#' | sed 's/^.*= *//' | sort | uniq -c | sort -n | grep -v '^  *1 '
   root at scspc578-1604:/var/lib/lxc# 

So, anyway, it almost looks like "-K" has effectively become the default.



Adrian Pepper
arpepper at uwaterloo.ca

(You'd really better have a plain-text mail client for the following...)

==============  Demo using Ubuntu 16.04 lxc1 2.1.1 (Start) ================
root at scspc578-1604:~# lxc-create -n test1 -t ubuntu -- -b cscf-adm
Checking cache download in /var/cache/lxc/xenial/rootfs-amd64 ... 
Copy /var/cache/lxc/xenial/rootfs-amd64 to /var/lib/lxc/test1/rootfs ... 
Copying rootfs to /var/lib/lxc/test1/rootfs ...
Generating locales (this might take a while)...
  en_CA.UTF-8... done
Generation complete.
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX root at scspc578-1604 (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX root at scspc578-1604 (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX root at scspc578-1604 (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX root at scspc578-1604 (ED25519)
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.

Current default time zone: 'Etc/UTC'
Local time is now:      Mon Nov 27 19:18:35 UTC 2017.
Universal Time is now:  Mon Nov 27 19:18:35 UTC 2017.


##
# Log in as user cscf-adm
##

root at scspc578-1604:~# 
root at scspc578-1604:~# lxc-start -n test1
root at scspc578-1604:~# lxc-attach -n test1
root at test1:~# exit
exit
root at scspc578-1604:~# lxc-stop -n test1
root at scspc578-1604:~# lxc-copy -n test1 -N test2
root at scspc578-1604:~# lxc-copy --version
2.1.1
root at scspc578-1604:~# lxc-start -n test2
root at scspc578-1604:~# lxc-attach -n test2
root at test1:~# cat /etc/hostname
test1
root at test1:~# echo test2 > /etc/hostname
root at test1:~# exit
exit
root at scspc578-1604:~# lxc-stop -n test2
root at scspc578-1604:~# lxc-start -n test2
root at scspc578-1604:~# lxc-attach -n test2
root at test2:~# cat /etc/hostname
test2
root at test2:~# exit
exit
root at scspc578-1604:~# lxc-stop -n test2
root at scspc578-1604:~# lxc-start -n test1
root at scspc578-1604:~# lxc-attach -n test1
root at test1:~# hostname
test1
root at test1:~# exit
exit
root at scspc578-1604:~# lxc-stop -n test1
root at scspc578-1604:~# lxc-destroy -n test1
Destroyed container test1
root at scspc578-1604:~# lxc-destroy -n test2
Destroyed container test2
root at scspc578-1604:~# dpkg-query --list | grep ' lxc1'
ii  lxc                                         2.1.1-0ubuntu1~ubuntu16.04.1~ppa1            all          Transitional package for lxc1
ii  lxc1                                        2.1.1-0ubuntu1~ubuntu16.04.1~ppa1            amd64        Linux Containers userspace tools
root at scspc578-1604:~# 
==============  Demo using Ubuntu 16.04 lxc1 2.1.1 (End) ==================

I had occasion to create a nested lxc container host (2.0.8, Ubuntu 16.04)
to do a demo for a colleague.

Within that container, lxc-copy seems to work as it did before.
To wit...

==============  Demo using Ubuntu 16.04 lxc1 2.0.8 (Start) ================
root at u1604lxcdemo:~# lxc-create -n test3 -t ubuntu --  -b cscf-adm
Checking cache download in /var/cache/lxc/xenial/rootfs-amd64 ... 
Copy /var/cache/lxc/xenial/rootfs-amd64 to /var/lib/lxc/test3/rootfs ... 
Copying rootfs to /var/lib/lxc/test3/rootfs ...
Generating locales (this might take a while)...
  en_CA.UTF-8... done
Generation complete.
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX root at u1604lxcdemo (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX root at u1604lxcdemo (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX root at u1604lxcdemo (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX root at u1604lxcdemo (ED25519)
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.

Current default time zone: 'Etc/UTC'
Local time is now:      Mon Nov 27 19:28:35 UTC 2017.
Universal Time is now:  Mon Nov 27 19:28:35 UTC 2017.


##
# Log in as user cscf-adm
##

root at u1604lxcdemo:~# lxc-start -n test3
root at u1604lxcdemo:~# lxc-attach -n test3
root at test3:/# hostname
test3
root at test3:/# cat /etc/hostname
test3
root at test3:/# exit
exit
root at u1604lxcdemo:~# lxc-stop -n test3
root at u1604lxcdemo:~# lxc-copy -n test3 -N test4
root at u1604lxcdemo:~# lxc-start -n test4
root at u1604lxcdemo:~# lxc-attach -n test4
root at test4:/# hostname
test4
root at test4:/# cat /etc/hostname
test4root at test4:/# exit
exit
root at u1604lxcdemo:~# 
root at u1604lxcdemo:~# lxc-create --version
2.0.8
root at u1604lxcdemo:~# dpkg-query --list | grep ' lxc1'
ii  lxc                            2.0.8-0ubuntu1~16.04.2                     all          Transitional package for lxc1
ii  lxc1                           2.0.8-0ubuntu1~16.04.2                     amd64        Linux Containers userspace tools
root at u1604lxcdemo:~# 
==============  Demo using Ubuntu 16.04 lxc1 2.0.8 (End) ==================


I manually XXX'd out RSA fingerprints above, since they don't pertain
to the issue.


Adrian.



More information about the lxc-users mailing list