[Lxc-users] Regarding creating a LXC container in fedora 17

Michael H. Warfield mhw at WittsEnd.com
Sun May 19 19:56:39 UTC 2013


On Sun, 2013-05-19 at 09:26 +0530, Shridhar Daithankar wrote:
> On Saturday, May 18, 2013 04:06:30 PM Michael H. Warfield wrote:
> > On Sun, 2013-05-19 at 00:02 +0530, Shridhar Daithankar wrote:
> > > I ran into the same lxc-console issue and managed to solve it by
> > > commenting
> > > out ConditionPathExists line in
> > > /etc/systemd/system/getty.target.wants/getty\@tty1.service
> > > 
> > > first I had to start the container in foreground, login, comment out
> > > aforementioned line and restart it in daemon mode. After that lxc-console
> > > worked.
> > > 
> > > If I changed the systemd unit from the chroot itself, it didn't reflect
> > > somehow. Also the line referred to /dev/tty0 but only /dev/tty and
> > > /dev/tty1 were available in the container.
> > > 
> > > I don't understand systemd enough to comment on the reasons of it working
> > > or not-working. I just experimented around to get a working tty.
> > 
> > Oh, I understand why it's working and that's VERY interesting.  I hadn't
> > dug into that realm of the systemd files as yet.  They're using the mere
> > existence of /dev/tty0 as a logic switch to determine if they are going
> > to start a getty on %I (/dev/tty1 in this case).  Which is yet another
> > case of them burying a magic cookie switch in the logic.  They
> > conditionalize it on a hard coded /dev/tty0 but then start a getty
> > "/sbin/agetty --noclear %I 38400".  the %I is the unit name.  Cute.
> > Cheeky bastards.
> > 
> > So, it basically means that if we create a tty0 under autodev, that
> > should then enable any listed vty consoles we set up using systemd
> > links.  That could be a key to making that work without modifying files
> > in the container but would require a (relatively minor but non trivial)
> > change to the lxc source code, as opposed to merely a template.  I'll
> > run this up the flagpole on the -devel list and with Serge and get their
> > opinions.  This is doable.  I think I'll try this out in my sources
> > first and then post a request for comments over on -devel.  The problem
> > is in the routine "setup_tty" in conf.c that's going to need some
> > massaging to make it 0 based instead of 1 based and adjust for the
> > additional tty count.  :-/

> digging a bit deeper in this and quoting from

> http://www.freedesktop.org/software/systemd/man/systemd-getty-generator.html
> and http://0pointer.de/blog/projects/serial-console.html

> It looks like systemd is generating that unit file on demand during boot(thats 
> why editing it before starting the container did not work for me) and it is 
> looking into /sys/class/tty/console/active which indeed reports tty0 inside a 
> container.

> So the real question is how can lxc/kernel make the container report tty1
> there so that systemd would work out of the box.

> or.. as you have proposed, lxc could expose tty0.

Or, after reading that first document, another idea that comes to mind.
This is one that could be implemented in the lxc-fedora template.  The
idea is based on the section near the bottom of that document titled
"Serial Terminals" and mentions "However, sometimes there's the need to
manually configure a serial getty..."  That can be adapted and used with
getty at .service like this...

cp /lib/systemd/system/getty at .service /etc/systemd/system

Now edit /etc/systemd/system/getty at .service and delete or comment out
the ConditionPathExists=/dev/tty0 line.

Finally...

cd /etc/systemd/system/getty.target.wants/
ln -sf ../getty\@.service getty at tty1.service
ln -sf ../getty\@.service getty at tty2.service
ln -sf ../getty\@.service getty at tty3.service
ln -sf ../getty\@.service getty at tty4.service
...  For the number of vty logins you want up to the number of ttys you
have specified in lxc.tty.

That overrides the getty at .service in /lib/systemd/system/

Tested out with a Fedora 17 container I have running hear now and it
works like a charm.  You do end up with multiple agetty processes
running that way.  I can then use lxc-console to connect to those
consoles.  This would seem to be a cheap and dirty way to get it to
work.

Looks like we could try with some virtual console devices they mention
in that document as well but that recurses back to needing to modify
lxc-start and the autodev logic.

> -- 
> Regards
>  Shridhar
> 

-- 
Michael H. Warfield (AI4NB) | (770) 985-6132 |  mhw at WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 482 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20130519/ff2d4f5f/attachment.pgp>


More information about the lxc-users mailing list