lxc: Tweak lxc template script for systemd/sysvinit
PATCH 1/1 lxc: Tweak lxc template script for systemd/sysvinit
Tweak the script to make it work for both systemd and sysvinit.
Add "-i <init_method>" parameter. If sysvinit guest is used, "-i sysvinit" need to be passed. The default init is systemd.
The below systemd specific changes are added:
Add "lxc.autodev=1" since LXC will create its own device tree. Add "lxc.kmsg=0" to prevent lxc symlinks /dev/kmsg to /dev/console, this leads to journald running 100% cpu usage all the time.
Remove unnecessary mount entry in fstab.
--- templates/lxc-wrlinux.in | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)
templates/lxc-wrlinux.in +26 -5
@@ -30,8 +30,10 @@ default_profile=default configure_wrlinux() { - # Tweak initscripts - sed -i 's/^\(si::sysinit:\/etc\/init.d\/rcS\)/# \1/' ${rootfs_path}/etc/inittab + if [ "${init_method}" == "sysvinit" ]; then + # Tweak initscripts + sed -i 's/^\(si::sysinit:\/etc\/init.d\/rcS\)/# \1/' ${rootfs_path}/etc/inittab + fi # Touch file for fastboot dev_path="${rootfs_path}/dev"
@@ -78,9 +80,11 @@ copy_configuration() mkdir -p $config_path grep -q "^lxc.rootfs" $config_path/config 2>/dev/null || echo "lxc.rootfs = $rootfs_path" >> $config_path/config + + if [ "${init_method}" == "sysvinit" ]; then cat <<EOF >> $config_path/config lxc.utsname = $name -lxc.tty = 6 +lxc.tty = 6 lxc.pts = 1024 lxc.mount = $config_path/fstab EOF
@@ -91,6 +95,21 @@ none $rootfs_path/sys sysfs defaults 0 0 none $rootfs_path/dev/pts devpts defaults 0 0 none $rootfs_path/dev/shm tmpfs defaults 0 0 EOF + # systemd + else + cat <<EOF >> $config_path/config +lxc.utsname = $name +lxc.autodev=1 +lxc.kmsg=0 +lxc.tty = 6 +lxc.pts = 1024 +lxc.mount = $config_path/fstab +EOF + + cat <<EOF > $config_path/fstab +none $rootfs_path/sys sysfs defaults 0 0 +EOF + fi if [ $? -ne 0 ]; then echo "Failed to add configuration"
@@ -110,17 +129,18 @@ usage() cat <<EOF usage: $1 -n|--name=<container_name> - [-p|--path=<path>] [-h|--help] + [-p|--path=<path>] [-i|--init=<init_method>] [-h|--help] Mandatory args: -n,--name container name, used to as an identifier for that container from now on Optional args: -p,--path path to where the container rootfs will be created, defaults to @LXCPATH@. The container config will go under @LXCPATH@ in that case + -i,--init init method used by system, systemd or sysvinit -h,--help print this help EOF return 0 } -options=$(getopt -o hp:n: -l help,path:,name: -- "$@") +options=$(getopt -o hp:n:i: -l help,path:,name:,init: -- "$@") if [ $? -ne 0 ]; then usage $(basename $0) exit 1
@@ -133,6 +153,7 @@ do -h|--help) usage $0 && exit 0;; -p|--path) path=$2; shift 2;; -n|--name) name=$2; shift 2;; + -i|--init) init_method=$2; shift 2;; --) shift 1; break ;; *) break ;; esac
Signature · 1 line
2.0.2
Quoted 10 lines · Yang Shi
Tweak the script to make it work for both systemd and sysvinit.
Add "-i <
init_method>" parameter. If sysvinit guest is used, "-i sysvinit" need to be passed. The default init is systemd.The below systemd specific changes are added:
Add "lxc.autodev=1" since LXC will create its own device tree. Add "lxc.kmsg=0" to prevent lxc symlinks/dev/kmsgto/dev/console, this leads to journald running 100% cpu usage all the time.
Remove unnecessary mount entry in fstab.
This is definitely good information, and worth the broadcast. I was asking for any systemd changes that may be floating around, but since we are patching code that isn't already part of meta-virt, we'll let this sit and see if any of the dependencies are also available to merge.
Cheers,
Bruce
Quoted 88 lines
Signed-off-by Yang Shi <[email protected]>--- templates/lxc-wrlinux.in | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)templates/lxc-wrlinux.in +26
-5@@ -30,8 +30,10 @@ default_profile=default configure_wrlinux() { - # Tweak initscripts - sed -i 's/^\(si::sysinit:\/etc\/init.d\/rcS\)/# \1/' ${rootfs_path}/etc/inittab + if [ "${init_method}" == "sysvinit" ]; then + # Tweak initscripts + sed -i 's/^\(si::sysinit:\/etc\/init.d\/rcS\)/# \1/' ${rootfs_path}/etc/inittab + fi # Touch file for fastboot dev_path="${rootfs_path}/dev"@@ -78,9 +80,11 @@ copy_configuration() mkdir -p $config_path grep -q "^lxc.rootfs" $config_path/config 2>/dev/null || echo "lxc.rootfs = $rootfs_path" >> $config_path/config + + if [ "${init_method}" == "sysvinit" ]; then cat <<EOF >> $config_path/config lxc.utsname = $name -lxc.tty = 6 +lxc.tty = 6 lxc.pts = 1024 lxc.mount = $config_path/fstab EOF@@ -91,6 +95,21 @@ none $rootfs_path/sys sysfs defaults 0 0 none $rootfs_path/dev/pts devpts defaults 0 0 none $rootfs_path/dev/shm tmpfs defaults 0 0 EOF + # systemd + else + cat <<EOF >> $config_path/config +lxc.utsname = $name +lxc.autodev=1 +lxc.kmsg=0 +lxc.tty = 6 +lxc.pts = 1024 +lxc.mount = $config_path/fstab +EOF + + cat <<EOF > $config_path/fstab +none $rootfs_path/sys sysfs defaults 0 0 +EOF + fi if [ $? -ne 0 ]; then echo "Failed to add configuration"@@ -110,17 +129,18 @@ usage() cat <<EOF usage: $1 -n|--name=<container_name> - [-p|--path=<path>] [-h|--help] + [-p|--path=<path>] [-i|--init=<init_method>] [-h|--help] Mandatory args: -n,--name container name, used to as an identifier for that container from now on Optional args: -p,--path path to where the container rootfs will be created, defaults to @LXCPATH@. The container config will go under @LXCPATH@ in that case + -i,--init init method used by system, systemd or sysvinit -h,--help print this help EOF return 0 } -options=$(getopt -o hp:n: -l help,path:,name: -- "$@") +options=$(getopt -o hp:n:i: -l help,path:,name:,init: -- "$@") if [ $? -ne 0 ]; then usage $(basename $0) exit 1@@ -133,6 +153,7 @@ do -h|--help) usage $0 && exit 0;; -p|--path) path=$2; shift 2;; -n|--name) name=$2; shift 2;; + -i|--init) init_method=$2; shift 2;; --) shift 1; break ;; *) break ;; esac