Bugzilla – Bug 12964
a li'l pile of fixing for init.d (INSTALL_ROOT,groups,no asking in INSTALL))
Last modified: 2007-04-01 02:08:04 UTC
So, I've seen that init.d is really dangerous for $INSTALL_ROOT != "" and fixed it to work on cast of a to-be chroot. It also uses groups on static dev tree generation that may not yet exist... Well, Just see the diff that follows; I'm asking here for some feedback/approval before I commit this to git and possibly break a kindof vital spell... diff --git a/smgl/init.d/CONFIGURE b/smgl/init.d/CONFIGURE index 604e247..86d7bf2 100755 --- a/smgl/init.d/CONFIGURE +++ b/smgl/init.d/CONFIGURE @@ -16,4 +16,8 @@ if grep -q devfs /proc/filesystems && message "\n${MESSAGE_COLOR}NOTICE: Switching from devfs to udev or static currently needs manual editing of /etc/fstab.${DEFAULT_COLOR}\n" fi && -config_query_list DEVICES "Choose /dev management mode:" $DEVICES_LIST +config_query_list DEVICES "Choose /dev management mode:" $DEVICES_LIST && +if [[ "$DEVICES" != "devfs" ]] +then + config_query CREATE_DEV_TREE "check for / create static /dev tree" y +fi diff --git a/smgl/init.d/FINAL b/smgl/init.d/FINAL index 39e56ed..27e9f85 100755 --- a/smgl/init.d/FINAL +++ b/smgl/init.d/FINAL @@ -1,7 +1,9 @@ +# that's ugly, should be a safe/random file name +# hm, and are these files never updated? if [ -e /tmp/initd_first_install ] ; then - install -m 754 $SCRIPT_DIRECTORY/files/tshutdown /sbin/tshutdown + install -m 754 $SCRIPT_DIRECTORY/files/tshutdown ${INSTALL_ROOT}/sbin/tshutdown install -m 754 $SCRIPT_DIRECTORY/files/smgl-cleanup \ - /etc/init.d/runlevels/%S/ + ${INSTALL_ROOT}/etc/init.d/runlevels/%S/ rm -f /tmp/initd_first_install fi @@ -20,7 +22,7 @@ if [ -e /tmp/devices2dev ] ; then rm /tmp/devices2dev fi -sedit "s/DEVICES=.*/DEVICES=$DEVICES/" /etc/sysconfig/devices +sedit "s/DEVICES=.*/DEVICES=$DEVICES/" ${INSTALL_ROOT}/etc/sysconfig/devices if [ "$DEVICES" == "devfs" ]; then sedit "s:/dev/tty\(.\):/dev/vc/\1:" ${INSTALL_ROOT}/etc/inittab @@ -30,6 +32,7 @@ else fi # remove /etc/inittab from the simpleinit install log +# this should work for $INSTALL_ROOT/etc/inittab, too for i in $INSTALL_LOGS/simpleinit* $MD5SUM_LOGS/simpleinit* do if [ -f $i ] ; then sedit "/\/etc\/inittab/D" $i @@ -41,9 +44,9 @@ # The next sedit is to fix my (sandalle) # where casting from a queue (or not using -r) will not reassign # it. Should be removed in about a month (~20040926) # -if grep -q "mountall$" /etc/sysconfig/facilities; then - message "${MESSAGE_COLOR}Fixing /etc/sysconfig/facilities:local_fs${DEFAULT_COLOR}" && - sedit 's:mountall:mountall.sh:' /etc/sysconfig/facilities +if grep -q "mountall$" ${INSTALL_ROOT}/etc/sysconfig/facilities; then + message "${MESSAGE_COLOR}Fixing ${INSTALL_ROOT}/etc/sysconfig/facilities:local_fs${DEFAULT_COLOR}" && + sedit 's:mountall:mountall.sh:' ${INSTALL_ROOT}/etc/sysconfig/facilities fi && # # End rename fix diff --git a/smgl/init.d/INSTALL b/smgl/init.d/INSTALL index d0ca990..023633a 100755 --- a/smgl/init.d/INSTALL +++ b/smgl/init.d/INSTALL @@ -1,16 +1,26 @@ check_static_dev () { echo "checking if your static /dev is ok..." && mkdir /tmp/$$.bindmount && - mount --bind / /tmp/$$.bindmount && + mount --bind ${INSTALL_ROOT}/ /tmp/$$.bindmount && cd /tmp/$$.bindmount/dev && if [ ! -c console -o ! -c null ]; then - if query "You don't seem to have a static /dev tree, should i create it ?" y - then $SCRIPT_DIRECTORY/MAKEDEV generic-nopty md - mkdir -p shm pts && - mknod initctl p - fi + message "Ok, going to create!" && + # asked in CONFIGURE + # if query "You don't seem to have a static /dev tree, should i create it ?" y + # then + create_group kmem && + create_group tty && + create_group ppp && + create_group lp && + create_group disk && + create_group floppy && + # existing nodes should not make me fail + $SCRIPT_DIRECTORY/MAKEDEV generic-nopty md || true && + mkdir -p shm pts && + mknod initctl p || true + # fi else - echo "seems ok" + echo "seems ok" fi && cd / && umount /tmp/$$.bindmount && @@ -39,7 +49,7 @@ FD=$SCRIPT_DIRECTORY/files # Files Di ID=${INSTALL_ROOT}/etc/init.d # Init Dir RD=${INSTALL_ROOT}/etc/init.d/runlevels # Runlevels Dir -if [ "$DEVICES" != "devfs" ]; then +if [[ "$DEVICES" != "devfs" ]] && [[ "$CREATE_DEV_TREE" == y ]]; then check_static_dev fi && @@ -78,19 +88,22 @@ mkdep 3 2 mkdep 4 3 && mkdep 5 4 && -if ! grep -sq runlevels /etc/inittab ; then - pinfo "Installing /etc/inittab..." && +if ! grep -sq runlevels ${INSTALL_ROOT}/etc/inittab ; then + pinfo "Installing ${INSTALL_ROOT}/etc/inittab..." && install -v -m 644 $FD/inittab ${INSTALL_ROOT}/etc/inittab fi && pinfo "Other stuff..." && # Proper shutdown procedure -ln -fsv ${TRACK_ROOT}/etc/sysconfig/shutdown ${INSTALL_ROOT}/etc/shutdown.conf && +# TRACK_ROOT??? +# ln -fsv ${TRACK_ROOT}/etc/sysconfig/shutdown ${INSTALL_ROOT}/etc/shutdown.conf && +ln -fsv sysconfig/shutdown ${INSTALL_ROOT}/etc/shutdown.conf && # Yeah, I know ln -sfv /bin/true $RD/rc && # LILO uses the auto runlevel when it doesn't encounter any user input -ln -sfv /etc/init.d/runlevels/%default \ +# path relative to be safer for chroots +ln -sfv %default \ ${INSTALL_ROOT}/etc/init.d/runlevels/%auto diff --git a/smgl/init.d/PRE_BUILD b/smgl/init.d/PRE_BUILD index 4270519..ef8bb82 100755 --- a/smgl/init.d/PRE_BUILD +++ b/smgl/init.d/PRE_BUILD @@ -1,21 +1,43 @@ # Remove old init.d if ! [ "$CROSS_INSTALL" = "on" ] ; then -if [ ! -e /etc/init.d/smgl_init ] ; then - touch /tmp/initd_first_install +if [ ! -e ${INSTALL_ROOT}/etc/init.d/smgl_init ] ; then + touch /tmp/initd_first_install && - mkdir -p /etc/init.d.backup + if [[ -e ${INSTALL_ROOT}/etc/init.d ]] + then - mv /etc/init.d /etc/init.d.backup + message "doing backup of old init.d" && + local bd=${INSTALL_ROOT}/etc/init.d.backup && + + if [[ -e ${bd} ]] + then + message "$bd exists, trying with number suffix" && + local num=2 && + while [[ -e ${bd}.$num ]] + do + let num+=1 && + message "trying ${bd}.$num..." + done + message "using ${bd}.$num" && + bd=${bd}.$num + fi && + + + mkdir -pv $bd && + + mv ${INSTALL_ROOT}/etc/init.d ${bd} && for l in 0 1 2 3 4 5 6 S ; do - [ -d /etc/rc$l.d ] && mv /etc/rc$l.d /etc/init.d.backup + [ -d ${INSTALL_ROOT}/etc/rc$l.d ] && mv ${INSTALL_ROOT}/etc/rc$l.d ${bd} done + + fi fi -fi +fi && # remove left behind file, bug #5784. -if [ -f /etc/init.d/runlevels/%3/z-misc.sh ]; then - rm /etc/init.d/runlevels/%3/z-misc.sh -fi +if [ -f ${INSTALL_ROOT}/etc/init.d/runlevels/%3/z-misc.sh ]; then + rm ${INSTALL_ROOT}/etc/init.d/runlevels/%3/z-misc.sh +fi && true
Hah! For that patch to really work, one should add definitions for some groups to grimoire: kmem tty disk floppy lp I suggest (my current /etc/group): kmem:x:15: tty:x:5:orgis disk:x:6: floppy:x:25:orgis lp:x:7: (o' course ignore the user, that's just me;-) plus: create_group should fail if it cannot find a definition!
OK, also, the old init.d backup in PRE_BUILD could change the rcX.d part: for l in 0 1 2 3 4 5 6 S ; do if [[ -d ${INSTALL_ROOT}/etc/rc$l.d ]] then mv ${INSTALL_ROOT}/etc/rc$l.d ${bd} fi done The old variant silently fails if there is no /etc/rcX.d directory...
man... last update from me before someone else had his chance: there are some more groups... you really have to cast stuff with an empty /etc/passwd (note: mine had just a root account in it created by a special spell for being able to install sorcery in chroot). so I have now in the relevant part of INSTALL: create_group kmem && create_group tty && create_group ppp && create_group lp && create_group disk && create_group floppy && create_group audio && and these groups in the fresh /etc/group (after casting smgl-fhs and init.d): root:*:0: games:x:60: mail:x:8: utmp:x:43: ppp:x:20: kmem:x:15: tty:x:5: lp:x:7: disk:x:6: floppy:x:25: audio:x:29:
Created attachment 6430 [details] more consistent INSTALL_ROOT support first of three incremental patches to be applied with patch -Np1 in spell dir
Created attachment 6431 [details] patch 2: better init.d backup routine
Created attachment 6432 [details] patch 3: groups and static dev This is the last one of the broken up parts of the too-big-to-review patch. There are now 3 steps: 1. put more INSTALL_ROOT in it; this was halfway done before 2. fix/improve the init.d backup routine 3. fix static dev tree creation by creating needed groups and asking in CONFIGURE instead in the middle of a cast Please comment on these so that I can commit to git.
Seems sane to me. But it's 7:45am on a monday... Others should probably review this, as it's kinda critical to making the system boot. Like the backup routine. <tangent>It might be nice to have that as a grimoire level function, since a few spells use it.</tangent> If I'm understanding correctly, you could start with an empty /etc/passwd (well, with root) and casting this would create the necessary users/groups? That's pretty nice :)
Well, the working cast of stuff with empty /etc/passwd is a long/mid/(short;-) term goal I have. Atm. I even have a root-account spell that creates at least the one line you need to get going in a fresh chroot. But that will be subject of the account system reworking that is in the mindworks (I have to prepare that proposal...).
are these standalone patches or do they depend on each other?
They're incremental steps (from 1 to 3). Stuff really depends on each other.
1. Perhaps use a persistent variable instead of checking [[ -e /tmp/ initd_first_install ]]. 2. TRACK_ROOT is used to define where you will be running from. From: http:// wiki.sourcemage.org/install_root_and_others "TRACK_ROOT This describes what prefix should be given to files installed in the install log."
Point 1: Yes, I think, too, that this temp file in the role of a peristent flag us some ugly thing. It would have been the next thing to change for me;-). Will prepare a fourth incremental patch for that. Point 2: So you agree with me that the usage of TRACK_ROOT was wrong and my variant of that is better? I cannot see how the symlink of etc/shutdown.conf is related to TRACK_ROOT... well, at least I cannot see why this should be good.
I don't believe any init script/package should be using TRACK_ROOT as it will *only* be run from 'inside' the system, not outside (which is what TRACK_ROOT is for, AFAIK), so yes I agree, I was just answering your question (or what I thought was a question) about what TRACK_ROOT was.
Created attachment 6443 [details] step 4: first_install as persistent variable, not file incremental after steps 1,2,3
So, anyone against me commiting these changes in the next days?
I'd say go for the commit if it seems to be working on your machine. You'll know soon enough if our machines break. ;)
It is in test now: commit 557bc9028c2705ae3d65b7973234a8ed03a5dfd7 Short after my commit that added the definition for the group tty, Jaka fixed bug #7768 for util-inux using that group definition. He requested stable integration of his fix... should I request integration here, too, to make sure that the new groups file is integrated? I guess we don't want the whole changes to init.d in stable immediately (although it is bugfixing) and also that the integrator is conscious enough to see the issue - so: no.(?)
closing fixed bugs
reassign to sm-grimoire-bugs