| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# /etc/rc.d/rc.sysinit - run once at boot time |
| 4 |
# |
| 5 |
# Taken in part from Miquel van Smoorenburg's bcheckrc. |
| 6 |
# |
| 7 |
# This file is modified by Steven Shiau <steven _at_ clonezilla org> to be used for DRBL on Fedora 13 on Jun/06/2010 |
| 8 |
|
| 9 |
HOSTNAME=$(/bin/hostname) |
| 10 |
|
| 11 |
set -m |
| 12 |
|
| 13 |
if [ -f /etc/sysconfig/network ]; then |
| 14 |
. /etc/sysconfig/network |
| 15 |
fi |
| 16 |
if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then |
| 17 |
HOSTNAME=localhost |
| 18 |
fi |
| 19 |
|
| 20 |
if [ ! -e /proc/mounts ]; then |
| 21 |
mount -n -t proc /proc /proc |
| 22 |
mount -n -t sysfs /sys /sys >/dev/null 2>&1 |
| 23 |
fi |
| 24 |
if [ ! -d /proc/bus/usb ]; then |
| 25 |
modprobe usbcore >/dev/null 2>&1 && mount -n -t usbfs /proc/bus/usb /proc/bus/usb |
| 26 |
else |
| 27 |
mount -n -t usbfs /proc/bus/usb /proc/bus/usb |
| 28 |
fi |
| 29 |
|
| 30 |
. /etc/init.d/functions |
| 31 |
|
| 32 |
PLYMOUTH= |
| 33 |
[ -x /usr/bin/plymouth ] && PLYMOUTH=yes |
| 34 |
|
| 35 |
# Check SELinux status |
| 36 |
SELINUX_STATE= |
| 37 |
if [ -e "/selinux/enforce" ] && [ "$(cat /proc/self/attr/current)" != "kernel" ]; then |
| 38 |
if [ -r "/selinux/enforce" ] ; then |
| 39 |
SELINUX_STATE=$(cat "/selinux/enforce") |
| 40 |
else |
| 41 |
# assume enforcing if you can't read it |
| 42 |
SELINUX_STATE=1 |
| 43 |
fi |
| 44 |
fi |
| 45 |
|
| 46 |
if [ -n "$SELINUX_STATE" ] && [ -x /sbin/restorecon ] && __fgrep " /dev " /proc/mounts >/dev/null 2>&1 ; then |
| 47 |
/sbin/restorecon -R /dev 2>/dev/null |
| 48 |
fi |
| 49 |
|
| 50 |
disable_selinux() { |
| 51 |
echo $"*** Warning -- SELinux is active" |
| 52 |
echo $"*** Disabling security enforcement for system recovery." |
| 53 |
echo $"*** Run 'setenforce 1' to reenable." |
| 54 |
echo "0" > "/selinux/enforce" |
| 55 |
} |
| 56 |
|
| 57 |
relabel_selinux() { |
| 58 |
# if /sbin/init is not labeled correctly this process is running in the |
| 59 |
# wrong context, so a reboot will be required after relabel |
| 60 |
REBOOTFLAG=$(restorecon -v /sbin/init) |
| 61 |
AUTORELABEL= |
| 62 |
. /etc/selinux/config |
| 63 |
if [ "$AUTORELABEL" = "0" ]; then |
| 64 |
rm -f /.autorelabel |
| 65 |
|
| 66 |
[ -n "$PLYMOUTH" ] && plymouth --hide-splash |
| 67 |
echo |
| 68 |
echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required. " |
| 69 |
echo $"*** /etc/selinux/config indicates you want to manually fix labeling" |
| 70 |
echo $"*** problems. Dropping you to a shell; the system will reboot" |
| 71 |
echo $"*** when you leave the shell." |
| 72 |
echo "0" > /selinux/enforce |
| 73 |
sulogin |
| 74 |
|
| 75 |
echo $"Unmounting file systems" |
| 76 |
umount -a |
| 77 |
mount -n -o remount,ro / |
| 78 |
echo $"Automatic reboot in progress." |
| 79 |
reboot -f |
| 80 |
else |
| 81 |
[ -n "$PLYMOUTH" ] && plymouth --hide-splash |
| 82 |
echo |
| 83 |
echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required." |
| 84 |
echo $"*** Relabeling could take a very long time, depending on file" |
| 85 |
echo $"*** system size and speed of hard drives." |
| 86 |
|
| 87 |
echo "0" > /selinux/enforce |
| 88 |
/sbin/fixfiles -F restore > /dev/null 2>&1 |
| 89 |
rm -f /.autorelabel |
| 90 |
if [ ! -z "$REBOOTFLAG" ]; then |
| 91 |
echo $"Automatic reboot in progress." |
| 92 |
reboot -f |
| 93 |
fi |
| 94 |
echo $SELINUX_STATE > /selinux/enforce |
| 95 |
[ -n "$PLYMOUTH" ] && plymouth --show-splash |
| 96 |
fi |
| 97 |
} |
| 98 |
|
| 99 |
key_is_random() { |
| 100 |
[ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" \ |
| 101 |
-o "$1" = "/dev/random" ] |
| 102 |
} |
| 103 |
|
| 104 |
find_crypto_mount_point() { |
| 105 |
local fs_spec fs_file fs_vfstype remaining_fields |
| 106 |
local fs |
| 107 |
while read fs_spec fs_file remaining_fields; do |
| 108 |
if [ "$fs_spec" = "/dev/mapper/$1" ]; then |
| 109 |
echo $fs_file |
| 110 |
break; |
| 111 |
fi |
| 112 |
done < /etc/fstab |
| 113 |
} |
| 114 |
|
| 115 |
# Because of a chicken/egg problem, init_crypto must be run twice. /var may be |
| 116 |
# encrypted but /var/lib/random-seed is needed to initialize swap. |
| 117 |
init_crypto() { |
| 118 |
local have_random dst src key opt mode owner params makeswap skip arg opt |
| 119 |
local param value rc ret mke2fs mdir prompt mount_point |
| 120 |
|
| 121 |
ret=0 |
| 122 |
have_random=$1 |
| 123 |
while read dst src key opt; do |
| 124 |
[ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue |
| 125 |
[ -b "/dev/mapper/$dst" ] && continue; |
| 126 |
if [ "$have_random" = 0 ] && key_is_random "$key"; then |
| 127 |
continue |
| 128 |
fi |
| 129 |
if [ -n "$key" -a "x$key" != "xnone" ]; then |
| 130 |
if test -e "$key" ; then |
| 131 |
owner=$(ls -l $key | (read a b owner rest; echo $owner)) |
| 132 |
if ! key_is_random "$key"; then |
| 133 |
mode=$(ls -l "$key" | cut -c 5-10) |
| 134 |
if [ "$mode" != "------" ]; then |
| 135 |
echo $"INSECURE MODE FOR $key" |
| 136 |
fi |
| 137 |
fi |
| 138 |
if [ "$owner" != root ]; then |
| 139 |
echo $"INSECURE OWNER FOR $key" |
| 140 |
fi |
| 141 |
else |
| 142 |
echo $"Key file for $dst not found, skipping" |
| 143 |
ret=1 |
| 144 |
continue |
| 145 |
fi |
| 146 |
else |
| 147 |
key="" |
| 148 |
fi |
| 149 |
params="" |
| 150 |
makeswap="" |
| 151 |
mke2fs="" |
| 152 |
skip="" |
| 153 |
# Parse the src field for UUID= and convert to real device names |
| 154 |
if [ "${src%%=*}" == "UUID" ]; then |
| 155 |
src=$(/sbin/blkid -t "$src" -l -o device) |
| 156 |
elif [ "${src/^\/dev\/disk\/by-uuid\/}" != "$src" ]; then |
| 157 |
src=$(__readlink $src) |
| 158 |
fi |
| 159 |
# Is it a block device? |
| 160 |
[ -b "$src" ] || continue |
| 161 |
# Is it already a device mapper slave? (this is gross) |
| 162 |
devesc=${src##/dev/} |
| 163 |
devesc=${devesc//\//!} |
| 164 |
for d in /sys/block/dm-*/slaves ; do |
| 165 |
[ -e $d/$devesc ] && continue 2 |
| 166 |
done |
| 167 |
# Parse the options field, convert to cryptsetup parameters and |
| 168 |
# contruct the command line |
| 169 |
while [ -n "$opt" ]; do |
| 170 |
arg=${opt%%,*} |
| 171 |
opt=${opt##$arg} |
| 172 |
opt=${opt##,} |
| 173 |
param=${arg%%=*} |
| 174 |
value=${arg##$param=} |
| 175 |
|
| 176 |
case "$param" in |
| 177 |
cipher) |
| 178 |
params="$params -c $value" |
| 179 |
if [ -z "$value" ]; then |
| 180 |
echo $"$dst: no value for cipher option, skipping" |
| 181 |
skip="yes" |
| 182 |
fi |
| 183 |
;; |
| 184 |
size) |
| 185 |
params="$params -s $value" |
| 186 |
if [ -z "$value" ]; then |
| 187 |
echo $"$dst: no value for size option, skipping" |
| 188 |
skip="yes" |
| 189 |
fi |
| 190 |
;; |
| 191 |
hash) |
| 192 |
params="$params -h $value" |
| 193 |
if [ -z "$value" ]; then |
| 194 |
echo $"$dst: no value for hash option, skipping" |
| 195 |
skip="yes" |
| 196 |
fi |
| 197 |
;; |
| 198 |
verify) |
| 199 |
params="$params -y" |
| 200 |
;; |
| 201 |
swap) |
| 202 |
makeswap=yes |
| 203 |
;; |
| 204 |
tmp) |
| 205 |
mke2fs=yes |
| 206 |
esac |
| 207 |
done |
| 208 |
if [ "$skip" = "yes" ]; then |
| 209 |
ret=1 |
| 210 |
continue |
| 211 |
fi |
| 212 |
if [ -z "$makeswap" ] && cryptsetup isLuks "$src" 2>/dev/null ; then |
| 213 |
if key_is_random "$key"; then |
| 214 |
echo $"$dst: LUKS requires non-random key, skipping" |
| 215 |
ret=1 |
| 216 |
continue |
| 217 |
fi |
| 218 |
if [ -n "$params" ]; then |
| 219 |
echo "$dst: options are invalid for LUKS partitions," \ |
| 220 |
"ignoring them" |
| 221 |
fi |
| 222 |
if [ -n "$key" ]; then |
| 223 |
/sbin/cryptsetup -d $key luksOpen "$src" "$dst" <&1 2>/dev/null && success || failure |
| 224 |
rc=$? |
| 225 |
else |
| 226 |
mount_point="$(find_crypto_mount_point $dst)" |
| 227 |
[ -n "$mount_point" ] || mount_point=${src##*/} |
| 228 |
prompt=$(printf $"%s is password protected" "$mount_point") |
| 229 |
plymouth ask-for-password --prompt "$prompt" --command="/sbin/cryptsetup luksOpen -T1 $src $dst" <&1 |
| 230 |
rc=$? |
| 231 |
fi |
| 232 |
else |
| 233 |
[ -z "$key" ] && plymouth --hide-splash |
| 234 |
/sbin/cryptsetup $params ${key:+-d $key} create "$dst" "$src" <&1 2>/dev/null && success || failure |
| 235 |
rc=$? |
| 236 |
[ -z "$key" ] && plymouth --show-splash |
| 237 |
fi |
| 238 |
if [ $rc -ne 0 ]; then |
| 239 |
ret=1 |
| 240 |
continue |
| 241 |
fi |
| 242 |
if [ -b "/dev/mapper/$dst" ]; then |
| 243 |
if [ "$makeswap" = "yes" ]; then |
| 244 |
mkswap "/dev/mapper/$dst" 2>/dev/null >/dev/null |
| 245 |
fi |
| 246 |
if [ "$mke2fs" = "yes" ]; then |
| 247 |
if mke2fs "/dev/mapper/$dst" 2>/dev/null >/dev/null \ |
| 248 |
&& mdir=$(mktemp -d /tmp/mountXXXXXX); then |
| 249 |
mount "/dev/mapper/$dst" "$mdir" && chmod 1777 "$mdir" |
| 250 |
umount "$mdir" |
| 251 |
rmdir "$mdir" |
| 252 |
fi |
| 253 |
fi |
| 254 |
fi |
| 255 |
done < /etc/crypttab |
| 256 |
return $ret |
| 257 |
} |
| 258 |
|
| 259 |
# Print a text banner. |
| 260 |
echo -en $"\t\tWelcome to " |
| 261 |
read -r redhat_release < /etc/redhat-release |
| 262 |
if [[ "$redhat_release" == *"Red Hat"* ]]; then |
| 263 |
[ "$BOOTUP" = "color" ] && echo -en "\\033[0;31m" |
| 264 |
# DRBL modify the prompt, START |
| 265 |
# echo -en "Red Hat" |
| 266 |
echo -en "DRBL for Red Hat" |
| 267 |
# DRBL modify the prompt, END |
| 268 |
[ "$BOOTUP" = "color" ] && echo -en "\\033[0;39m" |
| 269 |
PRODUCT=$(sed "s/Red Hat \(.*\) release.*/\1/" /etc/redhat-release) |
| 270 |
echo " $PRODUCT" |
| 271 |
elif [[ "$redhat_release" == *Fedora* ]]; then |
| 272 |
[ "$BOOTUP" = "color" ] && echo -en "\\033[0;34m" |
| 273 |
# DRBL modify the prompt, START |
| 274 |
#echo -en "Fedora" |
| 275 |
echo -en "DRBL for Fedora" |
| 276 |
# DRBL modify the prompt, END |
| 277 |
[ "$BOOTUP" = "color" ] && echo -en "\\033[0;39m" |
| 278 |
PRODUCT=$(sed "s/Fedora \(.*\) \?release.*/\1/" /etc/redhat-release) |
| 279 |
echo " $PRODUCT" |
| 280 |
else |
| 281 |
PRODUCT=$(sed "s/ release.*//g" /etc/redhat-release) |
| 282 |
# DRBL modify the prompt, START |
| 283 |
#echo "$PRODUCT" |
| 284 |
echo "DRBL for $PRODUCT" |
| 285 |
# DRBL modify the prompt, END |
| 286 |
fi |
| 287 |
if [ "$PROMPT" != "no" ]; then |
| 288 |
echo -en $"\t\tPress 'I' to enter interactive startup." |
| 289 |
echo |
| 290 |
fi |
| 291 |
|
| 292 |
# Fix console loglevel |
| 293 |
if [ -n "$LOGLEVEL" ]; then |
| 294 |
/bin/dmesg -n $LOGLEVEL |
| 295 |
fi |
| 296 |
|
| 297 |
# Only read this once. |
| 298 |
cmdline=$(cat /proc/cmdline) |
| 299 |
|
| 300 |
# Initialize hardware |
| 301 |
if [ -f /proc/sys/kernel/modprobe ]; then |
| 302 |
if ! strstr "$cmdline" nomodules && [ -f /proc/modules ] ; then |
| 303 |
sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1 |
| 304 |
else |
| 305 |
# We used to set this to NULL, but that causes 'failed to exec' messages" |
| 306 |
sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1 |
| 307 |
fi |
| 308 |
fi |
| 309 |
|
| 310 |
touch /dev/.in_sysinit >/dev/null 2>&1 |
| 311 |
|
| 312 |
# Set default affinity |
| 313 |
if [ -x /bin/taskset ]; then |
| 314 |
if strstr "$cmdline" default_affinity= ; then |
| 315 |
for arg in $cmdline ; do |
| 316 |
if [ "${arg##default_affinity=}" != "${arg}" ]; then |
| 317 |
/bin/taskset -p ${arg##default_affinity=} 1 |
| 318 |
fi |
| 319 |
done |
| 320 |
fi |
| 321 |
fi |
| 322 |
|
| 323 |
nashpid=$(pidof nash 2>/dev/null) |
| 324 |
[ -n "$nashpid" ] && kill $nashpid >/dev/null 2>&1 |
| 325 |
unset nashpid |
| 326 |
/sbin/start_udev |
| 327 |
|
| 328 |
# Load other user-defined modules |
| 329 |
for file in /etc/sysconfig/modules/*.modules ; do |
| 330 |
[ -x $file ] && $file |
| 331 |
done |
| 332 |
|
| 333 |
# Load modules (for backward compatibility with VARs) |
| 334 |
if [ -f /etc/rc.modules ]; then |
| 335 |
/etc/rc.modules |
| 336 |
fi |
| 337 |
|
| 338 |
mount -n /dev/pts >/dev/null 2>&1 |
| 339 |
[ -n "$SELINUX_STATE" ] && restorecon /dev/pts >/dev/null 2>&1 |
| 340 |
|
| 341 |
# Configure kernel parameters |
| 342 |
update_boot_stage RCkernelparam |
| 343 |
sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1 |
| 344 |
|
| 345 |
# Set the hostname. |
| 346 |
update_boot_stage RChostname |
| 347 |
action $"Setting hostname ${HOSTNAME}: " hostname ${HOSTNAME} |
| 348 |
|
| 349 |
# Sync waiting for storage. |
| 350 |
{ rmmod scsi_wait_scan ; modprobe scsi_wait_scan ; rmmod scsi_wait_scan ; } >/dev/null 2>&1 |
| 351 |
|
| 352 |
# Device mapper & related initialization |
| 353 |
if ! __fgrep "device-mapper" /proc/devices >/dev/null 2>&1 ; then |
| 354 |
modprobe dm-mod >/dev/null 2>&1 |
| 355 |
fi |
| 356 |
|
| 357 |
if [ -f /etc/crypttab ]; then |
| 358 |
init_crypto 0 |
| 359 |
fi |
| 360 |
|
| 361 |
if ! strstr "$cmdline" nompath && [ -f /etc/multipath.conf ] && \ |
| 362 |
[ -x /sbin/multipath ]; then |
| 363 |
modprobe dm-multipath > /dev/null 2>&1 |
| 364 |
/sbin/multipath -v 0 |
| 365 |
if [ -x /sbin/kpartx ]; then |
| 366 |
/sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -p p" >/dev/null |
| 367 |
fi |
| 368 |
fi |
| 369 |
|
| 370 |
if ! strstr "$cmdline" nodmraid && [ -x /sbin/dmraid ]; then |
| 371 |
modprobe dm-mirror >/dev/null 2>&1 |
| 372 |
dmraidsets=$(LC_ALL=C /sbin/dmraid -s -c -i) |
| 373 |
if [ "$?" = "0" ]; then |
| 374 |
for dmname in $dmraidsets; do |
| 375 |
if [[ "$dmname" == isw_* ]] && \ |
| 376 |
! strstr "$cmdline" noiswmd; then |
| 377 |
continue |
| 378 |
fi |
| 379 |
/sbin/dmraid -ay -i --rm_partitions -p "$dmname" >/dev/null 2>&1 |
| 380 |
/sbin/kpartx -a -p p "/dev/mapper/$dmname" |
| 381 |
done |
| 382 |
fi |
| 383 |
fi |
| 384 |
|
| 385 |
# Start any MD RAID arrays that haven't been started yet |
| 386 |
[ -r /proc/mdstat -a -r /dev/md/md-device-map ] && /sbin/mdadm -IRs |
| 387 |
|
| 388 |
if [ -x /sbin/lvm ]; then |
| 389 |
export LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES=1 |
| 390 |
action $"Setting up Logical Volume Management:" /sbin/lvm vgchange -a y --ignorelockingfailure |
| 391 |
unset LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES |
| 392 |
fi |
| 393 |
|
| 394 |
if [ -f /etc/crypttab ]; then |
| 395 |
init_crypto 0 |
| 396 |
fi |
| 397 |
|
| 398 |
if [ -f /fastboot ] || strstr "$cmdline" fastboot ; then |
| 399 |
fastboot=yes |
| 400 |
fi |
| 401 |
|
| 402 |
if [ -f /fsckoptions ]; then |
| 403 |
fsckoptions=$(cat /fsckoptions) |
| 404 |
fi |
| 405 |
|
| 406 |
if [ -f /forcefsck ] || strstr "$cmdline" forcefsck ; then |
| 407 |
fsckoptions="-f $fsckoptions" |
| 408 |
elif [ -f /.autofsck ]; then |
| 409 |
[ -f /etc/sysconfig/autofsck ] && . /etc/sysconfig/autofsck |
| 410 |
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then |
| 411 |
AUTOFSCK_OPT="$AUTOFSCK_OPT -f" |
| 412 |
fi |
| 413 |
if [ -n "$AUTOFSCK_SINGLEUSER" ]; then |
| 414 |
[ -n "$PLYMOUTH" ] && plymouth --hide-splash |
| 415 |
echo |
| 416 |
echo $"*** Warning -- the system did not shut down cleanly. " |
| 417 |
echo $"*** Dropping you to a shell; the system will continue" |
| 418 |
echo $"*** when you leave the shell." |
| 419 |
[ -n "$SELINUX_STATE" ] && echo "0" > /selinux/enforce |
| 420 |
sulogin |
| 421 |
[ -n "$SELINUX_STATE" ] && echo "1" > /selinux/enforce |
| 422 |
[ -n "$PLYMOUTH" ] && plymouth --show-splash |
| 423 |
fi |
| 424 |
fsckoptions="$AUTOFSCK_OPT $fsckoptions" |
| 425 |
fi |
| 426 |
|
| 427 |
if [ "$BOOTUP" = "color" ]; then |
| 428 |
fsckoptions="-C $fsckoptions" |
| 429 |
else |
| 430 |
fsckoptions="-V $fsckoptions" |
| 431 |
fi |
| 432 |
|
| 433 |
READONLY= |
| 434 |
if [ -f /etc/sysconfig/readonly-root ]; then |
| 435 |
. /etc/sysconfig/readonly-root |
| 436 |
fi |
| 437 |
if strstr "$cmdline" readonlyroot ; then |
| 438 |
READONLY=yes |
| 439 |
[ -z "$RW_MOUNT" ] && RW_MOUNT=/var/lib/stateless/writable |
| 440 |
[ -z "$STATE_MOUNT" ] && STATE_MOUNT=/var/lib/stateless/state |
| 441 |
fi |
| 442 |
if strstr "$cmdline" noreadonlyroot ; then |
| 443 |
READONLY=no |
| 444 |
fi |
| 445 |
|
| 446 |
# DRBL assign the status, START |
| 447 |
# For DRBL, we assign READONLY=no, since if we say yes here, it will try to mount a lot of device or others. DRBL is NFS-based, and we do not assign them in /etc/sysconfig/readonly-root. |
| 448 |
READONLY="no" |
| 449 |
# DRBL assign the status, END |
| 450 |
|
| 451 |
if [ "$READONLY" = "yes" -o "$TEMPORARY_STATE" = "yes" ]; then |
| 452 |
|
| 453 |
mount_empty() { |
| 454 |
if [ -e "$1" ]; then |
| 455 |
echo "$1" | cpio -p -vd "$RW_MOUNT" &>/dev/null |
| 456 |
mount -n --bind "$RW_MOUNT$1" "$1" |
| 457 |
fi |
| 458 |
} |
| 459 |
|
| 460 |
mount_dirs() { |
| 461 |
if [ -e "$1" ]; then |
| 462 |
mkdir -p "$RW_MOUNT$1" |
| 463 |
find "$1" -type d -print0 | cpio -p -0vd "$RW_MOUNT" &>/dev/null |
| 464 |
mount -n --bind "$RW_MOUNT$1" "$1" |
| 465 |
fi |
| 466 |
} |
| 467 |
|
| 468 |
mount_files() { |
| 469 |
if [ -e "$1" ]; then |
| 470 |
cp -a --parents "$1" "$RW_MOUNT" |
| 471 |
mount -n --bind "$RW_MOUNT$1" "$1" |
| 472 |
fi |
| 473 |
} |
| 474 |
|
| 475 |
# Common mount options for scratch space regardless of |
| 476 |
# type of backing store |
| 477 |
mountopts= |
| 478 |
|
| 479 |
# Scan partitions for local scratch storage |
| 480 |
rw_mount_dev=$(blkid -t LABEL="$RW_LABEL" -l -o device) |
| 481 |
|
| 482 |
# First try to mount scratch storage from /etc/fstab, then any |
| 483 |
# partition with the proper label. If either succeeds, be sure |
| 484 |
# to wipe the scratch storage clean. If both fail, then mount |
| 485 |
# scratch storage via tmpfs. |
| 486 |
if mount $mountopts "$RW_MOUNT" > /dev/null 2>&1 ; then |
| 487 |
rm -rf "$RW_MOUNT" > /dev/null 2>&1 |
| 488 |
elif [ x$rw_mount_dev != x ] && mount $rw_mount_dev $mountopts "$RW_MOUNT" > /dev/null 2>&1; then |
| 489 |
rm -rf "$RW_MOUNT" > /dev/null 2>&1 |
| 490 |
else |
| 491 |
mount -n -t tmpfs $RW_OPTIONS $mountopts none "$RW_MOUNT" |
| 492 |
fi |
| 493 |
|
| 494 |
for file in /etc/rwtab /etc/rwtab.d/* /dev/.initramfs/rwtab ; do |
| 495 |
is_ignored_file "$file" && continue |
| 496 |
[ -f $file ] && cat $file | while read type path ; do |
| 497 |
case "$type" in |
| 498 |
empty) |
| 499 |
mount_empty $path |
| 500 |
;; |
| 501 |
files) |
| 502 |
mount_files $path |
| 503 |
;; |
| 504 |
dirs) |
| 505 |
mount_dirs $path |
| 506 |
;; |
| 507 |
*) |
| 508 |
;; |
| 509 |
esac |
| 510 |
[ -n "$SELINUX_STATE" ] && [ -e "$path" ] && restorecon -R "$path" |
| 511 |
done |
| 512 |
done |
| 513 |
|
| 514 |
# Use any state passed by initramfs |
| 515 |
[ -d /dev/.initramfs/state ] && cp -a /dev/.initramfs/state/* $RW_MOUNT |
| 516 |
|
| 517 |
# In theory there should be no more than one network interface active |
| 518 |
# this early in the boot process -- the one we're booting from. |
| 519 |
# Use the network address to set the hostname of the client. This |
| 520 |
# must be done even if we have local storage. |
| 521 |
ipaddr= |
| 522 |
if [ "$HOSTNAME" = "localhost" -o "$HOSTNAME" = "localhost.localdomain" ]; then |
| 523 |
ipaddr=$(ip addr show to 0.0.0.0/0 scope global | awk '/[[:space:]]inet / { print gensub("/.*","","g",$2) }') |
| 524 |
for ip in $ipaddr ; do |
| 525 |
HOSTNAME= |
| 526 |
eval $(ipcalc -h $ipaddr 2>/dev/null) |
| 527 |
[ -n "$HOSTNAME" ] && { hostname ${HOSTNAME} ; break; } |
| 528 |
done |
| 529 |
fi |
| 530 |
|
| 531 |
# Clients with read-only root filesystems may be provided with a |
| 532 |
# place where they can place minimal amounts of persistent |
| 533 |
# state. SSH keys or puppet certificates for example. |
| 534 |
# |
| 535 |
# Ideally we'll use puppet to manage the state directory and to |
| 536 |
# create the bind mounts. However, until that's all ready this |
| 537 |
# is sufficient to build a working system. |
| 538 |
|
| 539 |
# First try to mount persistent data from /etc/fstab, then any |
| 540 |
# partition with the proper label, then fallback to NFS |
| 541 |
state_mount_dev=$(blkid -t LABEL="$STATE_LABEL" -l -o device) |
| 542 |
if mount $mountopts $STATE_OPTIONS "$STATE_MOUNT" > /dev/null 2>&1 ; then |
| 543 |
/bin/true |
| 544 |
elif [ x$state_mount_dev != x ] && mount $state_mount_dev $mountopts "$STATE_MOUNT" > /dev/null 2>&1; then |
| 545 |
/bin/true |
| 546 |
elif [ ! -z "$CLIENTSTATE" ]; then |
| 547 |
# No local storage was found. Make a final attempt to find |
| 548 |
# state on an NFS server. |
| 549 |
|
| 550 |
mount -t nfs $CLIENTSTATE/$HOSTNAME $STATE_MOUNT -o rw,nolock |
| 551 |
fi |
| 552 |
|
| 553 |
if [ -w "$STATE_MOUNT" ]; then |
| 554 |
|
| 555 |
mount_state() { |
| 556 |
if [ -e "$1" ]; then |
| 557 |
[ ! -e "$STATE_MOUNT$1" ] && cp -a --parents "$1" "$STATE_MOUNT" |
| 558 |
mount -n --bind "$STATE_MOUNT$1" "$1" |
| 559 |
fi |
| 560 |
} |
| 561 |
|
| 562 |
for file in /etc/statetab /etc/statetab.d/* ; do |
| 563 |
is_ignored_file "$file" && continue |
| 564 |
[ ! -f "$file" ] && continue |
| 565 |
|
| 566 |
if [ -f "$STATE_MOUNT/$file" ] ; then |
| 567 |
mount -n --bind "$STATE_MOUNT/$file" "$file" |
| 568 |
fi |
| 569 |
|
| 570 |
for path in $(grep -v "^#" "$file" 2>/dev/null); do |
| 571 |
mount_state "$path" |
| 572 |
[ -n "$SELINUX_STATE" ] && [ -e "$path" ] && restorecon -R "$path" |
| 573 |
done |
| 574 |
done |
| 575 |
|
| 576 |
if [ -f "$STATE_MOUNT/files" ] ; then |
| 577 |
for path in $(grep -v "^#" "$STATE_MOUNT/files" 2>/dev/null); do |
| 578 |
mount_state "$path" |
| 579 |
[ -n "$SELINUX_STATE" ] && [ -e "$path" ] && restorecon -R "$path" |
| 580 |
done |
| 581 |
fi |
| 582 |
fi |
| 583 |
fi |
| 584 |
|
| 585 |
if [[ " $fsckoptions" != *" -y"* ]]; then |
| 586 |
fsckoptions="-a $fsckoptions" |
| 587 |
fi |
| 588 |
|
| 589 |
_RUN_QUOTACHECK=0 |
| 590 |
if strstr "$cmdline" forcequotacheck || [ -f /forcequotacheck ] ; then |
| 591 |
_RUN_QUOTACHECK=1 |
| 592 |
fi |
| 593 |
if [ -z "$fastboot" -a "$READONLY" != "yes" ]; then |
| 594 |
|
| 595 |
STRING=$"Checking filesystems" |
| 596 |
echo $STRING |
| 597 |
fsck -T -t noopts=_netdev -A $fsckoptions |
| 598 |
rc=$? |
| 599 |
|
| 600 |
if [ "$rc" -eq "0" ]; then |
| 601 |
success "$STRING" |
| 602 |
echo |
| 603 |
elif [ "$rc" -eq "1" ]; then |
| 604 |
passed "$STRING" |
| 605 |
echo |
| 606 |
elif [ "$rc" -eq "2" -o "$rc" -eq "3" ]; then |
| 607 |
echo $"Unmounting file systems" |
| 608 |
umount -a |
| 609 |
mount -n -o remount,ro / |
| 610 |
echo $"Automatic reboot in progress." |
| 611 |
reboot -f |
| 612 |
fi |
| 613 |
|
| 614 |
# A return of 4 or higher means there were serious problems. |
| 615 |
if [ $rc -gt 1 ]; then |
| 616 |
[ -n "$PLYMOUTH" ] && plymouth --hide-splash |
| 617 |
|
| 618 |
failure "$STRING" |
| 619 |
echo |
| 620 |
echo |
| 621 |
echo $"*** An error occurred during the file system check." |
| 622 |
echo $"*** Dropping you to a shell; the system will reboot" |
| 623 |
echo $"*** when you leave the shell." |
| 624 |
|
| 625 |
str=$"(Repair filesystem)" |
| 626 |
PS1="$str \# # "; export PS1 |
| 627 |
[ "$SELINUX_STATE" = "1" ] && disable_selinux |
| 628 |
sulogin |
| 629 |
|
| 630 |
echo $"Unmounting file systems" |
| 631 |
umount -a |
| 632 |
mount -n -o remount,ro / |
| 633 |
echo $"Automatic reboot in progress." |
| 634 |
reboot -f |
| 635 |
elif [ "$rc" -eq "1" ]; then |
| 636 |
_RUN_QUOTACHECK=1 |
| 637 |
fi |
| 638 |
fi |
| 639 |
|
| 640 |
remount_needed() { |
| 641 |
local state oldifs |
| 642 |
[ "$READONLY" = "yes" ] && return 1 |
| 643 |
state=$(LC_ALL=C awk '/ \/ / && ($3 !~ /rootfs/) { print $4 }' /proc/mounts) |
| 644 |
oldifs=$IFS |
| 645 |
IFS="," |
| 646 |
for opt in $state ; do |
| 647 |
if [ "$opt" = "rw" ]; then |
| 648 |
IFS=$oldifs |
| 649 |
return 1 |
| 650 |
fi |
| 651 |
done |
| 652 |
IFS=$oldifs |
| 653 |
return 0 |
| 654 |
} |
| 655 |
|
| 656 |
# Remount the root filesystem read-write. |
| 657 |
update_boot_stage RCmountfs |
| 658 |
if remount_needed ; then |
| 659 |
action $"Remounting root filesystem in read-write mode: " mount -n -o remount,rw / |
| 660 |
fi |
| 661 |
|
| 662 |
# Clean up SELinux labels |
| 663 |
if [ -n "$SELINUX_STATE" ]; then |
| 664 |
restorecon /etc/mtab /etc/ld.so.cache /etc/blkid/blkid.tab /etc/resolv.conf >/dev/null 2>&1 |
| 665 |
fi |
| 666 |
|
| 667 |
# If relabeling, relabel mount points. |
| 668 |
if [ -n "$SELINUX_STATE" -a "$READONLY" != "yes" ]; then |
| 669 |
if strstr "$cmdline" autorelabel || [ -f /.autorelabel ] ; then |
| 670 |
restorecon $(awk '!/^#/ && $4 !~ /noauto/ && $2 ~ /^\// { print $2 }' /etc/fstab) >/dev/null 2>&1 |
| 671 |
fi |
| 672 |
fi |
| 673 |
|
| 674 |
if [ "$READONLY" != "yes" ] ; then |
| 675 |
# DRBL modify the prompt, START |
| 676 |
## Clear mtab |
| 677 |
#(> /etc/mtab) &> /dev/null |
| 678 |
# DRBL modify the prompt, END |
| 679 |
|
| 680 |
# Remove stale backups |
| 681 |
rm -f /etc/mtab~ /etc/mtab~~ |
| 682 |
|
| 683 |
# Enter mounted filesystems into /etc/mtab |
| 684 |
# DRBL modify, START |
| 685 |
#mount -f / |
| 686 |
# DRBL modify, END |
| 687 |
mount -f /proc >/dev/null 2>&1 |
| 688 |
mount -f /sys >/dev/null 2>&1 |
| 689 |
mount -f /dev/pts >/dev/null 2>&1 |
| 690 |
mount -f /dev/shm >/dev/null 2>&1 |
| 691 |
mount -f /proc/bus/usb >/dev/null 2>&1 |
| 692 |
fi |
| 693 |
|
| 694 |
# Mount all other filesystems (except for NFS and /proc, which is already |
| 695 |
# mounted). Contrary to standard usage, |
| 696 |
# filesystems are NOT unmounted in single user mode. |
| 697 |
if [ "$READONLY" != "yes" ] ; then |
| 698 |
action $"Mounting local filesystems: " mount -a -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs,gfs2 -O no_netdev |
| 699 |
else |
| 700 |
action $"Mounting local filesystems: " mount -a -n -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs,gfs2 -O no_netdev |
| 701 |
fi |
| 702 |
|
| 703 |
# Update quotas if necessary |
| 704 |
if [ X"$_RUN_QUOTACHECK" = X1 ] && [ -x /sbin/quotacheck ]; then |
| 705 |
action $"Checking local filesystem quotas: " /sbin/quotacheck -anug |
| 706 |
fi |
| 707 |
|
| 708 |
if [ -x /sbin/quotaon ]; then |
| 709 |
action $"Enabling local filesystem quotas: " /sbin/quotaon -aug |
| 710 |
fi |
| 711 |
|
| 712 |
# DRBL comment the selinux relabel, START |
| 713 |
## Check to see if a full relabel is needed |
| 714 |
#if [ -n "$SELINUX_STATE" -a "$READONLY" != "yes" ]; then |
| 715 |
# if strstr "$cmdline" autorelabel || [ -f /.autorelabel ] ; then |
| 716 |
# relabel_selinux |
| 717 |
# fi |
| 718 |
#else |
| 719 |
# if [ "$READONLY" != "yes" ] && [ -d /etc/selinux ]; then |
| 720 |
# [ -f /.autorelabel ] || touch /.autorelabel |
| 721 |
# fi |
| 722 |
#fi |
| 723 |
# DRBL comment the selinux relabel, END |
| 724 |
|
| 725 |
# Initialize pseudo-random number generator |
| 726 |
if [ -f "/var/lib/random-seed" ]; then |
| 727 |
cat /var/lib/random-seed > /dev/urandom |
| 728 |
else |
| 729 |
[ "$READONLY" != "yes" ] && touch /var/lib/random-seed |
| 730 |
fi |
| 731 |
if [ "$READONLY" != "yes" ]; then |
| 732 |
chmod 600 /var/lib/random-seed |
| 733 |
dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null |
| 734 |
fi |
| 735 |
|
| 736 |
if [ -f /etc/crypttab ]; then |
| 737 |
init_crypto 1 |
| 738 |
fi |
| 739 |
|
| 740 |
# Configure machine if necessary. |
| 741 |
if [ -f /.unconfigured ]; then |
| 742 |
if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then |
| 743 |
/usr/bin/rhgb-client --quit |
| 744 |
fi |
| 745 |
|
| 746 |
if [ -x /usr/bin/system-config-keyboard ]; then |
| 747 |
/usr/bin/system-config-keyboard |
| 748 |
fi |
| 749 |
if [ -x /usr/bin/passwd ]; then |
| 750 |
/usr/bin/passwd root |
| 751 |
fi |
| 752 |
if [ -x /usr/sbin/system-config-network-tui ]; then |
| 753 |
/usr/sbin/system-config-network-tui |
| 754 |
fi |
| 755 |
if [ -x /usr/sbin/timeconfig ]; then |
| 756 |
/usr/sbin/timeconfig |
| 757 |
fi |
| 758 |
if [ -x /usr/sbin/authconfig-tui ]; then |
| 759 |
/usr/sbin/authconfig-tui --nostart |
| 760 |
fi |
| 761 |
if [ -x /usr/sbin/ntsysv ]; then |
| 762 |
/usr/sbin/ntsysv --level 35 |
| 763 |
fi |
| 764 |
|
| 765 |
# Reread in network configuration data. |
| 766 |
if [ -f /etc/sysconfig/network ]; then |
| 767 |
. /etc/sysconfig/network |
| 768 |
|
| 769 |
# Reset the hostname. |
| 770 |
action $"Resetting hostname ${HOSTNAME}: " hostname ${HOSTNAME} |
| 771 |
fi |
| 772 |
|
| 773 |
rm -f /.unconfigured |
| 774 |
fi |
| 775 |
|
| 776 |
# Clean out /. |
| 777 |
rm -f /fastboot /fsckoptions /forcefsck /.autofsck /forcequotacheck /halt \ |
| 778 |
/poweroff /.suspended &> /dev/null |
| 779 |
|
| 780 |
# Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might... |
| 781 |
_NEED_XFILES= |
| 782 |
[ -f /var/run/utmpx ] || [ -f /var/log/wtmpx ] && _NEED_XFILES=1 |
| 783 |
|
| 784 |
# Clean up /var. |
| 785 |
rm -rf /var/lock/cvs/* /var/run/screen/* |
| 786 |
find /var/lock /var/run ! -type d -exec rm -f {} \; |
| 787 |
rm -f /var/lib/rpm/__db* &> /dev/null |
| 788 |
rm -f /var/gdm/.gdmfifo &> /dev/null |
| 789 |
|
| 790 |
# For DRBL, create the network tag in /var/lock/subsys/ to avoid some service (like netfs service in Fedora 9 or later) is skipped, since network is up in initrd, START |
| 791 |
[ -d /var/lock/subsys/ ] && touch /var/lock/subsys/network |
| 792 |
# For DRBL, END |
| 793 |
|
| 794 |
{ |
| 795 |
# Clean up utmp/wtmp |
| 796 |
> /var/run/utmp |
| 797 |
touch /var/log/wtmp |
| 798 |
chgrp utmp /var/run/utmp /var/log/wtmp |
| 799 |
chmod 0664 /var/run/utmp /var/log/wtmp |
| 800 |
if [ -n "$_NEED_XFILES" ]; then |
| 801 |
> /var/run/utmpx |
| 802 |
touch /var/log/wtmpx |
| 803 |
chgrp utmp /var/run/utmpx /var/log/wtmpx |
| 804 |
chmod 0664 /var/run/utmpx /var/log/wtmpx |
| 805 |
fi |
| 806 |
[ -n "$SELINUX_STATE" ] && restorecon /var/run/utmp* /var/log/wtmp* >/dev/null 2>&1 |
| 807 |
|
| 808 |
# Clean up various /tmp bits |
| 809 |
[ -n "$SELINUX_STATE" ] && restorecon /tmp |
| 810 |
rm -f /tmp/.X*-lock /tmp/.lock.* /tmp/.gdm_socket /tmp/.s.PGSQL.* |
| 811 |
rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \ |
| 812 |
/tmp/kde-* /tmp/ksocket-* /tmp/mc-* /tmp/mcop-* /tmp/orbit-* \ |
| 813 |
/tmp/scrollkeeper-* /tmp/ssh-* \ |
| 814 |
/dev/.in_sysinit |
| 815 |
|
| 816 |
# Make ICE directory |
| 817 |
mkdir -m 1777 -p /tmp/.ICE-unix >/dev/null 2>&1 |
| 818 |
chown root:root /tmp/.ICE-unix |
| 819 |
[ -n "$SELINUX_STATE" ] && restorecon /tmp/.ICE-unix >/dev/null 2>&1 |
| 820 |
|
| 821 |
# Start up swapping. |
| 822 |
update_boot_stage RCswap |
| 823 |
action $"Enabling /etc/fstab swaps: " swapon -a -e |
| 824 |
if [ "$AUTOSWAP" = "yes" ]; then |
| 825 |
curswap=$(awk '/^\/dev/ { print $1 }' /proc/swaps | while read x; do get_numeric_dev dec $x ; echo -n " "; done) |
| 826 |
swappartitions=$(blkid -t TYPE=swap -o device) |
| 827 |
if [ x"$swappartitions" != x ]; then |
| 828 |
for partition in $swappartitions ; do |
| 829 |
[ ! -e $partition ] && continue |
| 830 |
majmin=$(get_numeric_dev dec $partition) |
| 831 |
echo $curswap | grep -qw "$majmin" || action $"Enabling local swap partitions: " swapon $partition |
| 832 |
done |
| 833 |
fi |
| 834 |
fi |
| 835 |
|
| 836 |
# Set up binfmt_misc |
| 837 |
/bin/mount -t binfmt_misc none /proc/sys/fs/binfmt_misc > /dev/null 2>&1 |
| 838 |
|
| 839 |
# Boot time profiles. Yes, this should be somewhere else. |
| 840 |
if [ -x /usr/sbin/system-config-network-cmd ]; then |
| 841 |
if strstr "$cmdline" netprofile= ; then |
| 842 |
for arg in $cmdline ; do |
| 843 |
if [ "${arg##netprofile=}" != "${arg}" ]; then |
| 844 |
/usr/sbin/system-config-network-cmd --profile ${arg##netprofile=} |
| 845 |
fi |
| 846 |
done |
| 847 |
fi |
| 848 |
fi |
| 849 |
|
| 850 |
# For DRBL, create the directory /tmp/boot, so that the link /tmp/boot /boot |
| 851 |
# in template (node_root) works, START |
| 852 |
[ ! -d /tmp/boot ] && mkdir /tmp/boot |
| 853 |
# For DRBL, END |
| 854 |
|
| 855 |
# Now that we have all of our basic modules loaded and the kernel going, |
| 856 |
# let's dump the syslog ring somewhere so we can find it later |
| 857 |
[ -f /var/log/dmesg ] && mv -f /var/log/dmesg /var/log/dmesg.old |
| 858 |
dmesg -s 131072 > /var/log/dmesg |
| 859 |
|
| 860 |
# For DRBL, comment touch /.autofsck, START |
| 861 |
## create the crash indicator flag to warn on crashes, offer fsck with timeout |
| 862 |
#touch /.autofsck &> /dev/null |
| 863 |
# For DRBL, comment touch /.autofsck, END |
| 864 |
|
| 865 |
if [ "$PROMPT" != no ]; then |
| 866 |
while :; do |
| 867 |
pid=$(/sbin/pidof getkey) |
| 868 |
[ -n "$pid" ] || [ -e /var/run/getkey_done ] && break |
| 869 |
usleep 100000 |
| 870 |
done |
| 871 |
[ -n "$pid" ] && kill -TERM "$pid" >/dev/null 2>&1 |
| 872 |
fi |
| 873 |
} & |
| 874 |
if strstr "$cmdline" confirm ; then |
| 875 |
touch /var/run/confirm |
| 876 |
fi |
| 877 |
if [ "$PROMPT" != "no" ]; then |
| 878 |
/sbin/getkey i && touch /var/run/confirm |
| 879 |
touch /var/run/getkey_done |
| 880 |
fi |
| 881 |
wait |
| 882 |
[ "$PROMPT" != no ] && rm -f /var/run/getkey_done |
| 883 |
|
| 884 |
# Let rhgb know that we're leaving rc.sysinit |
| 885 |
if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then |
| 886 |
/usr/bin/rhgb-client --sysinit |
| 887 |
fi |
| 888 |
|