Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 55973 - modifications to baselayout to add vserver-support
Summary: modifications to baselayout to add vserver-support
Status: VERIFIED LATER
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 66472
  Show dependency tree
 
Reported: 2004-07-03 08:39 UTC by Thomas Eckert
Modified: 2009-10-24 06:17 UTC (History)
8 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
gentoo-vserver-baselayout.html (gentoo-vserver-baselayout.html,7.63 KB, text/html)
2004-07-03 08:41 UTC, Thomas Eckert
Details
diff against 1.6.9 (rc-scripts-1.6.9-vserver.diff,4.85 KB, patch)
2005-02-05 02:32 UTC, Benedikt Böhm (RETIRED)
Details | Diff
vserver.patch (vserver.patch,3.01 KB, patch)
2005-02-06 01:47 UTC, SpanKY
Details | Diff
rc-scripts-1.6.9-vserver.diff (rc-scripts-1.6.9-vserver.diff,6.57 KB, patch)
2005-02-06 05:50 UTC, Benedikt Böhm (RETIRED)
Details | Diff
xdm.initd.patch for vserver-guests (xdm.initd.patch,827 bytes, patch)
2005-02-10 16:51 UTC, Thomas Eckert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Eckert 2004-07-03 08:39:37 UTC
the same text as pasted below is added as an attachement in html -- this is
better readable.

--- snipp ---
Attempt to modify Gentoo-baselayout to make vserver-deployment easier without
breaking the current behaviour and without needing to split the baselayout.

The modifications outlined below were tested with sys-apps/baselayout-1.9.4-r2
on a vserver-enabled system without trouble; further testing is needed as
failures in baselayout may render the system unbootable.

sources of information:

    * http://vserver.strahlungsfrei.de/tiki-index.php?page=VServerGentooNew
    * http://www.linux-vserver.org 

related Gentoo-packages:

    * sys-kernel/vserver-sources
    * sys-cluster/util-vserver 

helper-functions and modification of /sbin/rc and /etc/inittab

    * helper-functions we use:

instserv sbin # cat /sbin/vserver-functions.sh
#!/bin/bash
##
## basic function-set for integration in gentoo-baselayout -- this
## should allow save (re-)booting of vservers and root-servers without
## maintaining 2 completely different baselayouts.
## Idea: we simply check if we are on a root- or v-server and react
accordingly.
## If there is no "s_context:" at all we have a vanilla (i.e. non-vserver)
system
## that is treated like a root-server.

check_context() {
        ## TODO: error-handling? what to do if /proc/$$/status does not exist?
        awk '/^s_context:/ { print $2; }' /proc/$$/status
}

on_rootserver() {
        local ctx=$(check_context)

        if [ "x${ctx}" = "x0" -o "x${ctx}" = "x" ]; then
                ## we are on the root-server or a non-vserver-system:
                return 0
        else
                return 1
        fi
}

on_vserver() {
        on_rootserver && return 1 || return 0
}

    * modify /sbin/rc to perform a depscan (the "fake-init"-stuff prevents
    * /sbin/rc to do it as the runlevel is never "S"!?):

instserv sbin # diff -u rc.org  rc
--- rc.org      2004-06-13 13:32:17.000000000 +0200
+++ rc  2004-07-03 15:40:42.000000000 +0200
@@ -10,6 +10,10 @@
 [ -f /sbin/livecd-functions.sh ] && source /sbin/livecd-functions.sh
 umask 022

+## vserver-support:
+[ -f /sbin/vserver-functions.sh ] && source /sbin/vserver-functions.sh
+on_vserver && /sbin/depscan.sh
+
 try() {
        local errstr
        local retval=0

    * create two new runlevel-directories and adjust /etc/inittab:
      [ "vdefault" may be omitted, see "Plan B" below ]

mkdir /etc/runlevels/{vboot,vdefault}
instserv runlevels # diff -u /etc/inittab.org /etc/inittab
--- /etc/inittab.org    2004-06-13 13:32:17.000000000 +0200
+++ /etc/inittab        2004-07-03 15:49:16.000000000 +0200
@@ -17,14 +17,14 @@
 si::sysinit:/sbin/rc sysinit

 # Further system initialization, brings up the boot runlevel.
-rc::bootwait:/sbin/rc boot
+rc::bootwait:/sbin/rc vboot

 l0:0:wait:/sbin/rc shutdown
 l1:S1:wait:/sbin/rc single
 l2:2:wait:/sbin/rc nonetwork
-l3:3:wait:/sbin/rc default
-l4:4:wait:/sbin/rc default
-l5:5:wait:/sbin/rc default
+l3:3:wait:/sbin/rc vdefault
+l4:4:wait:/sbin/rc vdefault
+l5:5:wait:/sbin/rc vdefault
 l6:6:wait:/sbin/rc reboot
 #z6:6:respawn:/sbin/sulogin


      => nothing is started up by defaut, to add a service use, e.g.

rc-update add sshd vdefault

      => this does not work as the values in /etc/inittab are not used; they
are overridden by the "vserver"-tool from "sys-cluster/util-vserver" so that
always "default" is choosen.

      Plan B:

cd /etc/runlevels; mv default default.org; ln -s vdefault default

      We might as well de-populate the original default-runlevel with
"rc-update" and omitt the whole "vdefault"-stuff above.

    * prepare a configfile for your vserver on your root-server
    * (/etc/vservers/my_vserver.conf). 

modify initscripts

We need to modify some initscripts as some operations are not possible within
a vserver and the dependency-tracking of the Gentoo-initsystem is more than
unhappy with failing services (which is the perfectly correct behaviour).

A vserver "inherits" some of the root-server setup or get's configured from
the root-server. This is the case for, e.g. hardware-clock and
network-configuration.

List of initscripts that we need to make vserver-aware:

hostname
modules
checkfs
localmount
clock
consolefont
serial
net.eth0
net.lo

We use the same trick as in /sbin/rc, each initscript gets the following lines
added at the top (directly after the copyright-header):

## vserver-support:
[ -f /sbin/vserver-functions.sh ] && source /sbin/vserver-functions.sh
on_vserver && exit 0

(if this get's integrated in the offical baselayout the sourcing of
vserver-functions.sh will happen at a more central place and not in every
initscript)

reboot and halt

In order to enable reboot and halt for a vserver rebootmgr needs to be running
on the root-server and /sbin/halt on the vserver needs to be replaced by
vreboot from sys-cluster/util-vserver. (what about /etc/init.d/shutdown.sh?)

Simply overwriting it is not a good solution as the next baselayout-update
will revert to the "wrong" (non-vserver) version.
If we only modify /etc/init.d/halt.sh and /etc/init.d/reboot.sh like

sed -i -e "s@/sbin/halt@/sbin/vhalt@g;" /etc/init.d/halt.sh
	:
	:

it is still possible to type reboot on the shell-prompt and loose contact with
your vserver.

=> we need to decide what way to go here (maybe a vserver-USE-flag for
baselayout could be introduced?). 
--- snapp ---


Reproducible: Always
Steps to Reproduce:
Comment 1 Thomas Eckert 2004-07-03 08:41:10 UTC
Created attachment 34714 [details]
gentoo-vserver-baselayout.html

the same information as in the description-field -- maybe better readable.
Comment 2 Thomas Eckert 2004-09-02 13:19:16 UTC
addition for the "reboot and halt"-section:
with util-vserver it's possible to "stop" and "start" a vserver from the host-system. the following changes in /etc/init.d/halt.sh (the vserver's halt.sh,
not the host-system's) let the "stop"-case finish without errors (patch for
baselayout-1.9.4-r3):
--- snipp ---
--- /etc/init.d/halt.sh 2004-08-25 21:33:12.000000000 +0200
+++ /vservers/v1/etc/init.d/halt.sh     2004-08-27 18:28:45.000000000 +0200
@@ -31,7 +31,7 @@
 # occure, bug #13599.
 umount -at tmpfs &>/dev/null
 
-if [ -n "`swapon -s 2>/dev/null`" ]
+if [ -n "`swapon -s 2>/dev/null`" -a ! on_vserver ]
 then
        ebegin "Deactivating swap"
        swapoff -a &>/dev/null
@@ -162,7 +162,7 @@
 # Get better results with a sync and sleep
 sync; sync
 sleep 1
-if ! mount_readonly
+[ ! on_vserver ] && if ! mount_readonly
 then
        killall5 -9  &>/dev/null
        sync; sync

--- snapp ---
Comment 3 Benedikt Böhm (RETIRED) gentoo-dev 2004-11-13 11:33:45 UTC
i am writing a gentoo vserver guide atm, this sounds interesting...

perhaps i'll do some experimental baselayout ebuilds tomorrow so they can be tested before they get in main portage

if you like contact me on freenode (nick: Hollow)
Comment 4 Benedikt Böhm (RETIRED) gentoo-dev 2004-11-14 04:57:41 UTC
first part of the guide is done. i created vserver enabled baselayout ebuilds

you can find the guide and all ebuilds at http://oss.croup.de/vserver/guide/
Comment 5 Thomas Eckert 2005-01-07 11:16:49 UTC
@benedikt: i've tested your ebuilds and they work very smooth (used the 1.9.4
baselayout).
your guide is very nice and correct (good work, thanks).

for the configuration-part of the guide:
one thing that will cause trouble for most users is that most (all?) daemons on
the host-system will bind to 0.0.0.0 preventing any daemons from a slave-vserver
to start up, example:
sshd on the host-system: need to edit /etc/ssh/sshd_config to allow sshd for
slave-vservers to start up:
  ListenAddress <your "primary" host-ip>
Comment 6 Benedikt Böhm (RETIRED) gentoo-dev 2005-01-23 00:52:21 UTC
what's the status here? is there any chance to get that into baselayout?
Comment 7 Benedikt Böhm (RETIRED) gentoo-dev 2005-02-05 02:32:40 UTC
Created attachment 50428 [details, diff]
diff against 1.6.9
Comment 8 SpanKY gentoo-dev 2005-02-06 00:00:09 UTC
ok, some of those hunks make sense and a bunch dont :)

since i dont know anything about vservers, i glanced through their wiki real quick ... it seems that each vserver has a separate filesystem ?  so each vserver has its own /etc/ config tree ?

if that is the case, then i would say that the hunks for consolefont/net.lo/serial wont be merged ... i'd rather just keep the files slim and tell you to not add them to your default runlevel

with respect to the detection functions, what is the typical output of 's_context:' on a vserver ?  just an integer ?  what kind of output can we expect on a selinux system ?
Comment 9 Benedikt Böhm (RETIRED) gentoo-dev 2005-02-06 00:28:28 UTC
> it seems that each vserver has a separate filesystem

the vserver itself has no seperate filesystem, but you can put it on one, if you like, it doesn't matter

> so each vserver has its own /etc/ config tree ?

yes, vserver is sth between chroot, jail and UML, so it has it's own /etc

> if that is the case, then i would say that the hunks for consolefont/net.lo/serial wont be merged ... i'd rather just keep the files slim and tell you to not add them to your default runlevel

consolefont, serial ok, but how to tell other init scripts that net is up if i remove net.* from the runlevels? network interfaces are setup on the host system before the vserver starts

> with respect to the detection functions, what is the typical output of 's_context:' on a vserver ?  just an integer ?  what kind of output can we expect on a selinux system ?

s_context is an integer containing the context id of a vserver, the root always has 0, vservers always have >=2, context 1 is reserved for use by util-vserver apps
Comment 10 Benedikt Böhm (RETIRED) gentoo-dev 2005-02-06 01:15:38 UTC
output of /proc/$$/status:

root-server:
kronos ~ # cat /proc/$$/status
Name:   bash
State:  S (sleeping)
SleepAVG:       88%
Tgid:   10377
Pid:    10377
PPid:   10376
TracerPid:      0
Uid:    0       0       0       0
Gid:    0       0       0       0
FDSize: 256
Groups: 0 1 2 3 4 6 10 11 20 26 27
VmSize:     4356 kB
VmLck:         0 kB
VmRSS:      1572 kB
VmData:      180 kB
VmStk:        36 kB
VmExe:       660 kB
VmLib:      1340 kB
VmPTE:        12 kB
Threads:        1
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000080010000
SigIgn: 0000000000384004
SigCgt: 000000004b813efb
CapInh: 0000000000000000
CapPrm: 00000000fffffeff
CapEff: 00000000fffffeff
s_context: 0
ctxflags: none
initpid: none
ipv4root: 0
ipv4root_bcast: 0

vserver (s_context is random here, though it could be set to a fixed value):
gentoo1 ~ # cat /proc/$$/status
Name:   bash
State:  S (sleeping)
SleepAVG:       98%
Tgid:   10352
Pid:    10352
PPid:   9290
TracerPid:      0
Uid:    0       0       0       0
Gid:    0       0       0       0
FDSize: 256
Groups: 0 1 2 3 4 6 10 11 20 26 27
VmSize:     5380 kB
VmLck:         0 kB
VmRSS:      1412 kB
VmData:      176 kB
VmStk:        36 kB
VmExe:       608 kB
VmLib:      1344 kB
VmPTE:        16 kB
Threads:        1
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000080010000
SigIgn: 0000000000384004
SigCgt: 000000004b813efb
CapInh: 0000000000000000
CapPrm: 00000000d44c04ff
CapEff: 00000000d44c04ff
s_context: 49152
ctxflags: 202000015
initpid: 0
ipv4root: 0102a8c0/00ffffff
ipv4root_bcast: ffffffff
Comment 11 SpanKY gentoo-dev 2005-02-06 01:47:00 UTC
Created attachment 50516 [details, diff]
vserver.patch

try this one
Comment 12 Thomas Eckert 2005-02-06 03:06:27 UTC
comment #11
- _looks_ mostly ok -- I'll test it next week (hopefully till wednesday).
- the for /sbin/functions.sh-part
    +	grep -qs '^s_context:[[:space:]]*[1-9]' /proc/self/status
  could be made more robust (not that it was more robust in my original version;)
- what about the net.*?

side-note: a drawback of my original "exit-0-early-in-vsservers"-suggestion is
that rc-status shows theses fake-services as "off". Without having looked at
the code I feel that to fix this we could "move" the patch to a more central
position like "ebegin" or the like?

@Mike: good to have you on-board :)
Comment 13 SpanKY gentoo-dev 2005-02-06 03:14:05 UTC
none of the other init scripts will be patched since you can setup your /etc/ files to work properly, including net.* (set 'config_eth0=( "null" )')

wrt to the grep, i dont see what lack of robustness you're refering to ...
Comment 14 Thomas Eckert 2005-02-06 03:26:21 UTC
net.*: like ``iface_ethX=""'' in /etc/conf.d/net?

i was thinking of leading 0s ... on 2nd thought it may be silly.
Comment 15 Benedikt Böhm (RETIRED) gentoo-dev 2005-02-06 05:50:41 UTC
Created attachment 50533 [details, diff]
rc-scripts-1.6.9-vserver.diff

i tried your patch and it works, though i added some `return 0` and `exit 0` to
reflect the default behaviour even if some of the init scripts would work under
certain circumstances (mainly where vservers have more capabilities or unlikely
setups)
Comment 16 Benedikt Böhm (RETIRED) gentoo-dev 2005-02-06 06:07:06 UTC
re #12,14:

there are changes that need to be done in- and outside the vserver to get it running with this patch. i'll add them to my guide at http://dev.gentoo.org/~hollow/vserver/guide/ as soon as this patch goes into cvs


fyi here is a list of init scripts included in baselayout and for what reason they need to be changed:

bootmisc		works
checkfs			may work, not needed by default (exit 0)
checkroot		may work, not needed by default (exit 0)
clock			fails (fake like UML)
consolefont		fails (fake like UML)
crypto-loop		unknown
domainname		may work, remove from runlevels
halt.sh			fails, util-vserver does all halting (exit 0)
hostname		may work, not needed by default (exit 0)
keymaps			fails (fake like UML)
localmount		may work, not needed by default (exit 0)
modules			fails, not supported by vserver (exit 0)
net			fails, util-vserver cares about interfaces for now, this could be changed by the new NGNet patches which are far away from stable (exit 0)
netmount		may work, remove from runlevels
numlock			fails, remove from runlevels
reboot.sh		fails, util-vserver does all rebooting (exit 0)
serial			fails, remove from runlevels
Comment 17 Thomas Eckert 2005-02-10 16:48:36 UTC
addition to comment #16 [ thanks for the "networking-ng" background ]
xdm:
  uses /dev/initctl that is not available in vservers (ctx!=[0|1]) -- see patch
  for a possible solution.

i didn't manage to test out the new stuff yet but as Benedikt did so it should
be ok.
Comment 18 Thomas Eckert 2005-02-10 16:51:06 UTC
Created attachment 50964 [details, diff]
xdm.initd.patch for vserver-guests

patch against:
#  $Header: /home/cvsroot/gentoo-x86/x11-base/xfree/files/4.3.0/xdm.start,v
#  1.3 2003/12/04 06:37:47 spyderous Exp $

from vserver-patched baselayout-1.9.4-r6
Comment 19 Benedikt Böhm (RETIRED) gentoo-dev 2005-02-10 23:43:16 UTC
never used xdm in vservers, but initctl is not accessable, right.

vapier: is there a possibility to fake the status of init scripts during boot? i'm thinking of an extra init scripts which fakes all the init scripts you won't need before
Comment 20 Benedikt Böhm (RETIRED) gentoo-dev 2005-02-23 07:30:10 UTC
since this approach seems to never get into baselayout i will come up with another solution soon, please be patient.
Comment 21 James Pic 2009-10-23 21:17:07 UTC
It's not resolved, it's open and *critical*.

Emerging baselayout on a gentoo vserver just breaks the vserver. Repatching must be done by hand. What a pain.

Please reopen.
Comment 22 SpanKY gentoo-dev 2009-10-24 05:43:00 UTC
use openrc/baselayout-2
Comment 23 James Pic 2009-10-24 05:46:25 UTC
(In reply to comment #22)
> use openrc/baselayout-2
> 

That is what i do and, (guess what) it won't boot unless this script is used to patch the vserver openrc/baselayout-2 stuff: /usr/lib/util-vserver/distributions/gentoo/initpost.
Comment 24 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-10-24 05:56:49 UTC
jamespic@gmail.com:
I've got 10+ vservers that run fine with Baselayout2+openrc (Full ~arch systems)
If you've got issues with that specific combination, please file a new bug.
Comment 25 James Pic 2009-10-24 06:09:46 UTC
(In reply to comment #24)
> I've got 10+ vservers that run fine with Baselayout2+openrc (Full ~arch
> systems)
> 

I've got 10+ vservers that run fine with Baselayout2+openrc as well. But that's not the question i'm trying to empathize.

If you do `emerge baselayout` in your vserver, and then reboot it from the host works perfectly? Wouldn't that mean that /usr/lib/util-vserver/distributions/gentoo/initpost is called by vserver ... build without any relevant reason? In that case i'll file an issue.
Comment 26 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-10-24 06:17:32 UTC
1. Reboot in my vservers works perfectly.
2. /usr/lib/util-vserver/distributions/gentoo/initpost (lib64) is part of sys-cluster/util-vserver, NOT baselayout or openrc, so emerging baselayout+openrc doesn't have anything to do with it.

Open a new bug.