Ask Your Question

How to properly set up an linux resource container (LXC)

asked 2011-11-20 20:28:26 -0500

tjw344 gravatar image

updated 2011-12-16 00:17:13 -0500

Can someone point me in a direction to a guide or something. I looked around and found one, but I am not sure it is correct anymore because I think lxc has made some changes recently. I am using fedora 16 and yum installed lxc-*. How do I proceed? I'd like to say that when I try to mkdir /cgroup and mount it at boot in fstab, fedora does not properly boot and enters recovery mode. Any suggestions?

# /etc/fstab
# Created by anaconda on Fri Dec  9 13:18:53 2011
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
UUID=ca1e6904-73dc-4fc9-b611-ba8f010580de   /       ext4    defaults            1 1
UUID=EA83-296C                  /boot/efi   vfat    umask=0077,shortname=winnt  0 0
UUID=3950db3c-7107-4deb-a38c-0d5979761451   /home       ext4    defaults            1 2
UUID=afddf429-813c-4d92-97d8-afbd5ad11ec6   swap        swap    defaults            0 0
#cgroup                     /cgroup     cgroup  defaults            0 0

cgorups is commented out because fedora 16 won't boot if its not. Also, if I try to mount cgroup this is what it looks like:

[root@xxxxxx-fedora ~]# mount cgroup
mount: cgroup already mounted or /sys/fs/cgroup/perf_event busy
mount: according to mtab, cgroup is already mounted on /sys/fs/cgroup/perf_event

Already created cgroup with:

mkdir -p /cgroup
edit retag flag offensive close merge delete


The most up to date information is on the LXC mailing list. if you need help with cgroups, post your /etc/fstab. The documentation on lxc is both fragmented and lagging.

bodhi.zazen gravatar imagebodhi.zazen ( 2011-12-15 23:21:18 -0500 )edit

The most up to date information is on the LXC mailing list.

bodhi.zazen gravatar imagebodhi.zazen ( 2011-12-15 23:21:18 -0500 )edit

I think you are getting the correct impression, lots of people with lost of custom personal scripts.

bodhi.zazen gravatar imagebodhi.zazen ( 2011-12-20 23:19:11 -0500 )edit

5 Answers

Sort by ยป oldest newest most voted

answered 2012-09-21 10:23:52 -0500

ganto gravatar image

updated 2012-09-21 10:26:16 -0500

Hi everybody

I just tried to setup a Fedora 17 LXC container within a Fedora 17 host. I quickly describe here how I made my setup and what is working so far. I think they don't yet ship the lxc-fedora template yet, because it's not fully working (at least for Fedora 17). A lot of tips and tricks I found in the links posted before.

Create Container

I used the lxc-fedora template which is shipped by upstream to create the Fedora 17 container. Another few manual steps I did in the container chroot:

  • Enable the networking service:

    chroot $rootfs chkconfig network on
  • Shut up systemd udev errors:

    chroot $rootfs ln -s /dev/null /etc/systemd/system/udev-control.socket
    chroot $rootfs ln -s /dev/null /etc/systemd/system/udev-kernel.socket
  • Install and enable SSH:

    chroot $rootfs yum install openssh-server
    chroot $rootfs systemctl enable sshd.service

Run via libvirt

I then first tried to start the container via libvirt, since this would be my preferred method. This failed with an access denied error to my container root file system as long as I set selinux to enforcing.

After setting selinux to permissive, the container booted nicely and I got a login prompt of the container on virsh console. However, every login attempt failed with the following error in /var/log/secure:

login: FAILED LOGIN 1 FROM pts/0 FOR root, Authentication failure
login: pam_securetty(login:auth): access denied: tty 'pts/0' is not secure !

If I try to login via ssh the following error prevents a successful login:

sshd[239]: Accepted password for root from port 36485 ssh2
sshd[239]: pam_loginuid(sshd:session): set_loginuid failed
sshd[239]: pam_unix(sshd:session): session opened for user root by (uid=0)
sshd[239]: error: PAM: pam_open_session(): Cannot make/remove an entry for the specified session
sshd[241]: error: open /dev/tty failed - could not set controlling tty: No such file or directory
sshd[239]: Received disconnect from 11: disconnected by user

I guess some of the container internal pseudo file systems such as devpts are not properly set up by libvirt. Unfortunately I don't know how to debug this further.


When I start the container with the generated configuration and lxc-start then the container also successfully starts. I don't get a prompt when trying lxc-console. The following log message can be found in /var/log/secure:

agetty[261]: tcsetattr problem: Input/output error

At least here, the login via SSH works and I get a bash within the container.

The big problem with this setup is, that I cannot properly restart a container. After lxc-stop another lxc-start is failing with:

lxc-start: Device or resource busy - failed to remove previous cgroup '/sys/fs/cgroup/systemd/testcontainer'
lxc-start: failed to spawn 'testcontainer'
lxc-start: Device or resource busy - failed to remove cgroup '/sys/fs/cgroup/systemd/testcontainer'

Only after rebooting the host I was able to start the container again.

I'm not really an ... (more)

edit flag offensive delete link more


Thanks. This should help quite a few folks. Upvoted :)

FranciscoD_ gravatar imageFranciscoD_ ( 2012-09-23 04:45:12 -0500 )edit

answered 2011-11-22 13:00:53 -0500

FranciscoD_ gravatar image

Just googled and found this: Give it a whirl. If you manage to get it running, please do post the steps for others.

edit flag offensive delete link more

answered 2011-12-16 10:16:48 -0500

So in fedora 16 cgroup is already mounted at /sys/fs/cgroup/

If lxc does not work with that location , file a bug report and as a work around you can use mount -o bind

In fstab

/sys/fs/cgroup  /cgroup  none  bind  0  0
edit flag offensive delete link more

answered 2012-07-14 09:32:19 -0500

Schorschi gravatar image

updated 2012-07-15 09:42:08 -0500

Where do you find lxc-fedora script? I installed lxc and libvirt on a Fedora 17 system, and lxc-fedora is no where to be found. I did a yum whatprovides */lxc-fedora not find in any package? So where is this script?

Ok, so on Fedora 17 yum install lxc does not add the lxc-fedora template script? Why not? does not make any sense to me, if you install lxc from a fedora repository the expectation is that at least the fedora template script would be included, just about every documented example via Google assumes this, implies this.

edit flag offensive delete link more


I agree, the downside of LXC has always been the rapid development and lack of documentation. You really need to subacribe to the mailing lists to stay up to date. Your above "answer" is probably best filed as a bug report.

bodhi.zazen gravatar imagebodhi.zazen ( 2012-07-16 10:30:46 -0500 )edit

answered 2011-11-22 14:03:09 -0500

updated 2011-11-22 14:12:08 -0500

LXC is indeed in rapid development and if you want to try it I highly suggest you register for the mailing lists as the mailing lists are the best source of up to date information.

You need to configure your host, I highly suggest you use a bridge for networking.

Note: The information on fedora containers is a bit outdated as it uses febootstrap rather then lxc-fedora. feboostrap is no longer supported, user lxc-fedora. The configuration files may be of assistance to you.

You should then, in theory, be able to create a guest with the lxc scripts (these scripts are included in the lxc package).

/usr/bin/lxc-debian {create|destroy|purge|help} /usr/bin/lxc-fedora {create|destroy|purge|help}

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2011-11-20 20:28:26 -0500

Seen: 11,481 times

Last updated: Sep 21 '12