[lxc-users] 2.1.1 lxc-copy consistently does not set hostname in new copy
Adrian Pepper
arpepper at uwaterloo.ca
Wed Dec 6 22:09:48 UTC 2017
Should I be reporting this somewhere else?
(I thought I remembered other people making similar observations, but cannot
find the thread in my lxc-users mbox; were the reports perhaps done by
some other method?)
Or do you want some supplementary information I have not given?
The problem I reported in the enclosed message seems to carry-forward
to 18.04 containers doing nesting (running under Ubuntu 16.04, kernel
4.4.0-101-generic)
My first attempt to create an 18.04 container which would allow nesting
failed, but then I created an 18.04 container using the "-t download"
template, and it seems to be able to do nesting.
However, within that nested lxc environment, it is consistently the
case that /etc/hostname does not get set to the new (-N) name. Sorry,
I'd created a few extraneous containers before doing the explicit
demo. But notice how "lxc-copy -n test1 -N test5" does not set
/etc/hostname in the new container, in contrast to the later
"lxc-copy -n lxctest1 -N lxctest3" done on a parallel Ubuntu 16.04
container, configured to allow nesting, but without the ppas to get lxc
2.1.1 (so it is lxc 2.0.8).
root at u1804dltest-1:~# lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6
test1 STOPPED 0 - - -
test2 STOPPED 0 - - -
test3 STOPPED 0 - - -
test4 STOPPED 0 - - -
root at u1804dltest-1:~# lxc-copy -n test1 -N test5
root at u1804dltest-1:~# lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6
test1 STOPPED 0 - - -
test2 STOPPED 0 - - -
test3 STOPPED 0 - - -
test4 STOPPED 0 - - -
test5 STOPPED 0 - - -
root at u1804dltest-1:~# cd /var/lib/lxc
root at u1804dltest-1:/var/lib/lxc# find . -name hostname | grep /etc/
./test3/rootfs/etc/hostname
./test5/rootfs/etc/hostname
./test4/rootfs/etc/hostname
./test1/rootfs/etc/hostname
./test2/rootfs/etc/hostname
root at u1804dltest-1:/var/lib/lxc# grep '^' ` !! `
grep '^' ` find . -name hostname | grep /etc/ `
./test3/rootfs/etc/hostname:test1
./test5/rootfs/etc/hostname:test1
./test4/rootfs/etc/hostname:test1
./test1/rootfs/etc/hostname:test1
./test2/rootfs/etc/hostname:test1
root at u1804dltest-1:/var/lib/lxc# uname -r
4.4.0-101-generic
root at u1804dltest-1:/var/lib/lxc# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Bionic Beaver (development branch)
Release: 18.04
Codename: bionic
root at u1804dltest-1:/var/lib/lxc# lxc-copy --version
2.1.1
root at u1804dltest-1:/var/lib/lxc# grep addr */config
test1/config:lxc.net.0.hwaddr = 00:16:3e:1f:a2:79
test2/config:lxc.net.0.hwaddr = 00:16:3e:ba:28:3c
test3/config:lxc.net.0.hwaddr = 00:16:3e:32:5a:5b
test4/config:lxc.net.0.hwaddr = 00:16:3e:09:5b:bd
test5/config:lxc.net.0.hwaddr = 00:16:3e:2f:39:8e
root at u1804dltest-1:/var/lib/lxc# dpkg-query --list | grep lxc1
ii liblxc1 2.1.1-0ubuntu1 amd64 Linux Containers userspace tools (library)
ii lxc 2.1.1-0ubuntu1 all Transitional package for lxc1
ii lxc1 2.1.1-0ubuntu1 amd64 Linux Containers userspace tools
root at u1804dltest-1:/var/lib/lxc#
In the above case I did not bother to correct /etc/hostname for the
intervening test2 ... test4. I'll likely delete most of these
containers and nested containers soon.
root at u1604lxcdemo:/var/lib/lxc# find . -name hostname | grep /etc/
./lxctest2/rootfs/etc/hostname
./lxctest1/rootfs/etc/hostname
root at u1604lxcdemo:/var/lib/lxc# grep '^' ` find . -name hostname | grep /etc/ `
./lxctest2/rootfs/etc/hostname:lxctest2
./lxctest1/rootfs/etc/hostname:lxctest1
root at u1604lxcdemo:/var/lib/lxc# lxc-copy -n lxctest1 -N lxctest3
root at u1604lxcdemo:/var/lib/lxc# grep '^' ` find . -name hostname | grep /etc/ `
./lxctest2/rootfs/etc/hostname:lxctest2
./lxctest3/rootfs/etc/hostname:lxctest3
./lxctest1/rootfs/etc/hostname:lxctest1
root at u1604lxcdemo:/var/lib/lxc# uname -r
4.4.0-101-generic
root at u1604lxcdemo:/var/lib/lxc# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
root at u1604lxcdemo:/var/lib/lxc# lxc-copy --version
2.0.8
root at u1604lxcdemo:/var/lib/lxc#
root at u1604lxcdemo:/var/lib/lxc# dpkg-query --list | grep lxc1
ii liblxc1 2.0.8-0ubuntu1~16.04.2 amd64 Linux Containers userspace tools (library)
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:/var/lib/lxc# grep addr */config
lxctest1/config:lxc.network.hwaddr = 00:16:3e:32:ff:a9
lxctest2/config:lxc.network.hwaddr = 00:16:3e:20:44:56
lxctest3/config:lxc.network.hwaddr = 00:16:3e:b6:76:03
root at u1604lxcdemo:/var/lib/lxc#
In contrast, in the above nested Ubuntu 16.04 container, /etc/hostname gets
set as I expect, as indicated. (The bare metal host is Ubuntu 16.04
running lxc 2.1.1 and exhibits the behaviour of keeping the old hostname
also).
I can work around the problem by manually setting the name, but wonder
if all identity has then been appropriately modified. (MAC addresses
do seem to be new; is there any other identity information which should
be validated?).
The 2.1.1 man page still suggests the hostname should get changed to the
new container name by the lxc-copy command itself.
Adrian Pepper
arpepper at uwaterloo.ca
> From lxc-users-bounces at lists.linuxcontainers.org Mon Nov 27 17:35:52 2017
> From: Adrian Pepper <arpepper at uwaterloo.ca>
> To: lxc-users at lists.linuxcontainers.org
> Message-Id: <20171127223534.A3B634C04B0 at ubuntu1404-104.cs.uwaterloo.ca>
> Date: Mon, 27 Nov 2017 17:35:34 -0500 (EST)
> Subject: [lxc-users] 2.1.1 lxc-copy consistently does not set hostname in
> new copy
>
> 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