Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to run systemd based Ubuntu in LXC container
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
lefsha
Veteran
Veteran


Joined: 30 Aug 2004
Posts: 1173
Location: Burgas, Bulgaria

PostPosted: Fri Nov 06, 2020 10:41 pm    Post subject: How to run systemd based Ubuntu in LXC container Reply with quote

Hi,

After playing with VirtualBox, then with KVM have decided to use LXC container
for running Caelinux, which is Ubuntu with systemd init bloatware.

It won't work straight away with openrc based Gentoo.

Here are the steps I did to run it.

1. Create a partition / dataset for containers. In my case:

Code:
zfs create <dataset>
zfs set mountpoint=/var/lib/lxc <dataset>


2. Create a container:
Code:
lxc-create -t download -n <container>

answer questions.

3. Create cgroups for devices and systemd:

Code:
#!/bin/sh

cg_path=/sys/fs/cgroup

group=devices
gr_path=$cg_path/$group

if [ ! -d $gr_path ]; then
   mount -o remount,rw $cg_path
   mkdir -p $gr_path
   mount -t cgroup -o $group  $group  $gr_path
   mount -o remount,ro $cg_path
fi


group=systemd
gr_path=$cg_path/$group

if [ ! -d $gr_path ]; then
   mount -o remount,rw $cg_path
   mkdir -p $gr_path
   mount -t cgroup -o none,name=$group  $group  $gr_path
   mount -o remount,ro $cg_path
fi


I was trying to use the same syntax for mount, didn't work. Mount for systemd has been found
on that forum. Mount for devices somewhere else.

4. Start the container

Code:
lxc-start -n <container>


5. Attach to console:

Code:
lxc-attach -n <container>


6. Add root password or create a user - up to you:

Code:
passwd


7. Stop the container:

Code:
lxc-stop -n <container>


8. Start the container with login to console:

Code:
lxc-start -n <container> -F


Now you can update the system, Install openssh or do what ever you pleased to.


Cheers,
_________________
Lefsha
Back to top
View user's profile Send private message
alamahant
Guru
Guru


Joined: 23 Mar 2019
Posts: 555

PostPosted: Fri Nov 06, 2020 11:22 pm    Post subject: Reply with quote

In my case it seems much simpler:
I use LXD
Code:

mkdir -p /sys/fs/cgroup/systemd
mount -t cgroup -o none,name=systemd systemd /sys/fs/cgroup/systemd

in /etc/rc.conf
Code:

rc_cgroup_mode="legacy"

And then
Code:

lxc launch ubuntu:focal/amd64 myubuntu

And it is done.
Although I dont know if it will work with your particular flavor of ubuntu.
Running systemd container from openrc shouldnt be a problem.
I think running openrc container from openrc might pose some problems......
_________________
:)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum