From 6cadece6089ef4d4efbfebeb6b23ca3f2429b36c Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Tue, 8 Jul 2014 17:34:08 +0200 Subject: dracut: Enable converting of directory /var/run /var/lock to symlinks to /run If /var/run is a directory this module will be added. After reboot /var/run and /var/lock will be symlinks. Another initrd re-creation will not include convertfs module anymore. bnc#877680 Signed-off-by: Thomas Renninger --- modules.d/30convertfs/convertfs.sh | 9 ------ modules.d/30convertfs/convertrunfs.sh | 54 +++++++++++++++++++++++++++++++++++ modules.d/30convertfs/do-convertfs.sh | 17 +++++++++++ modules.d/30convertfs/module-setup.sh | 10 +++++-- 4 files changed, 79 insertions(+), 11 deletions(-) create mode 100755 modules.d/30convertfs/convertrunfs.sh Index: dracut-041/modules.d/30convertfs/convertfs.sh =================================================================== --- dracut-041.orig/modules.d/30convertfs/convertfs.sh 2015-01-31 12:54:52.000000000 +0100 +++ dracut-041/modules.d/30convertfs/convertfs.sh 2015-03-17 17:37:15.774237322 +0100 @@ -62,15 +62,6 @@ fi rm -f -- "$testfile" -testfile="$ROOT/usr/.usrmovecheck$$" -rm -f -- "$testfile" -> "$testfile" -if [[ ! -e "$testfile" ]]; then - echo "Cannot write to $ROOT/usr/" - exit 1 -fi -rm -f -- "$testfile" - find_mount() { local dev mnt etc wanted_dev wanted_dev="$(readlink -e -q $1)" Index: dracut-041/modules.d/30convertfs/convertrunfs.sh =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ dracut-041/modules.d/30convertfs/convertrunfs.sh 2015-03-17 17:37:15.778237383 +0100 @@ -0,0 +1,54 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +ROOT="$1" + +if [[ ! -d "$ROOT" ]]; then + echo "Usage: $0 " + exit 1 +fi + +if [[ "$ROOT" -ef / ]]; then + echo "Can't convert the running system." + echo "Please boot with 'rd.convertfs' on the kernel command line," + echo "to update with the help of the initramfs," + echo "or run this script from a rescue system." + exit 1 +fi + +while [[ "$ROOT" != "${ROOT%/}" ]]; do + ROOT=${ROOT%/} +done + +if findmnt "$ROOT" -O ro;then + WAS_RO=1 + mount $ROOT -o remount,rw +else + WAS_RO=0 +fi + +testfile="$ROOT/.usrmovecheck$$" +rm -f -- "$testfile" +> "$testfile" +if [[ ! -e "$testfile" ]]; then + echo "Cannot write to $ROOT/" + exit 1 +fi +rm -f -- "$testfile" + +if [ ! -L $ROOT/var/run -a -e $ROOT/var/run ]; then + echo "Converting /var/run to symlink" + mv -f $ROOT/var/run $ROOT/var/run.runmove~ + ln -sfn ../run $ROOT/var/run +fi + +if [ ! -L $ROOT/var/lock -a -e $ROOT/var/lock ]; then + echo "Converting /var/lock to symlink" + mv -f $ROOT/var/lock $ROOT/var/lock.lockmove~ + ln -sfn ../run/lock $ROOT/var/lock +fi + +if [ $WAS_RO -eq 1 ];then + mount $ROOT -o remount,ro +fi Index: dracut-041/modules.d/30convertfs/do-convertfs.sh =================================================================== --- dracut-041.orig/modules.d/30convertfs/do-convertfs.sh 2015-03-17 17:31:01.441312547 +0100 +++ dracut-041/modules.d/30convertfs/do-convertfs.sh 2015-03-17 17:37:15.786237620 +0100 @@ -1,9 +1,26 @@ #!/bin/bash +# This converts all, /usr/bin -> /bin, ... and /var/run -> /run +# Do not enable by default! if getargbool 0 rd.convertfs; then + info "Converting both /var/run to /run tmpfs and /usr/bin -> /bin" if getargbool 0 rd.debug; then bash -x convertfs "$NEWROOT" 2>&1 | vinfo + exit 0 else convertfs "$NEWROOT" 2>&1 | vinfo + exit 0 + fi +fi + +# This only converts /var/run -> /run as tmpfs +if ! test -L "$NEWROOT"/var/run;then + info "Converting /var/run to /run tmpfs" + if getargbool 0 rd.debug; then + bash -x convertrunfs "$NEWROOT" 2>&1 | vinfo + exit 0 + else + convertrunfs "$NEWROOT" 2>&1 | vinfo + exit 0 fi fi Index: dracut-041/modules.d/30convertfs/module-setup.sh =================================================================== --- dracut-041.orig/modules.d/30convertfs/module-setup.sh 2015-03-17 17:31:01.445312770 +0100 +++ dracut-041/modules.d/30convertfs/module-setup.sh 2015-03-17 17:37:15.786237620 +0100 @@ -2,8 +2,13 @@ # called by dracut check() { - [[ $mount_needs ]] && return 1 - return 255 + # Only check for /var/run + if test -L /var/run;then + return 255 + else + require_binaries bash find ldconfig mv rm cp ln || return 1 + return 0 + fi } # called by dracut @@ -16,5 +21,6 @@ inst_multiple bash find ldconfig mv rm cp ln inst_hook pre-pivot 99 "$moddir/do-convertfs.sh" inst_script "$moddir/convertfs.sh" /usr/bin/convertfs + inst_script "$moddir/convertrunfs.sh" /usr/bin/convertrunfs }