done
}
+# resolve a device node to its major:minor numbers in decimal or hex
+get_numeric_dev() {
+ local dev=$1 enc=${2:-hex} res
+
+ res=$(stat -Lc "%t:%T" "$dev")
+ if [ "$enc" = dec ]; then
+ local oifs=$IFS
+ IFS=":"
+ set -- $res
+ IFS=$oifs
+ res=$((0x$1)):$((0x$2))
+ fi
+ echo -n $res
+}
+
# setup SELINUX variable
init_selinux() {
# user knows!
echo $SELINUX > $selinuxfs/enforce
}
+# Enable automatic swapon of all partitions with the proper swap magic.
+# This allows setting up swap without editing /etc/fstab.
+enable_autoswap() {
+ local swappartitions=$(blkid -t TYPE=swap -o device)
+ if [ -z "$swappartitions" ]; then
+ return
+ fi
+
+ local curswap=$(awk '/^\/dev/ { print $1 }' /proc/swaps | while read x; do echo -n " "; get_numeric_dev $x; echo -n " "; done)
+
+ local partition
+ for partition in $swappartitions; do
+ [ ! -e $partition ] && continue
+ majmin=$(get_numeric_dev $partition)
+ if ! strstr "$curswap" " $majmin "; then
+ run_cmd "$(nls 'Enabling local swap partitions: %s' $partition)" swapon $partition
+ fi
+ done
+}
+
+
+enable_swap() {
+ run_cmd "Activating swap" swapon -a "$@"
+ is_yes "$AUTOSWAP" && enable_autoswap
+}
+
# Remove duplicate entries from mtab (for vserver guest use only)
clean_vserver_mtab() {
> /etc/mtab.clean
fi
# Start up swapping
- run_cmd "Activating swap partitions" swapon -a -e
+ enable_swap -e
# Initialize USB controllers
usb=0
is_yes "$SELINUX" && restorecon /tmp/.ICE-unix >/dev/null 2>&1
if ! is_yes "$VSERVER"; then
- run_cmd "Enabling swap space" true
- # Right, now turn on swap in case we swap to files
- swapon -a >/dev/null 2>&1
+ enable_swap
emit --no-wait all-swaps
# If a SCSI tape has been detected, load the st module unconditionally