]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
add AUTOSWAP feature
authorElan Ruusamäe <glen@delfi.ee>
Thu, 19 Jun 2014 19:58:35 +0000 (22:58 +0300)
committerElan Ruusamäe <glen@delfi.ee>
Thu, 19 Jun 2014 20:04:52 +0000 (23:04 +0300)
inspired from initscripts 9.39-1

doc/sysconfig.txt
lib/functions
rc.d/rc.sysinit
sysconfig/system

index 063a332b75e3336ee19ec8f07c8a7055dca8d300..635d0545f3988733304a91ad3c7cc40b012b7831 100644 (file)
@@ -1,6 +1,13 @@
 Files in /etc/sysconfig
 =======================
 
+/etc/sysconfig/system:
+
+  AUTOSWAP=yes|no
+     Set to 'yes' to enable automatic swapon of all partitions with
+     the proper swap magic. This allows setting up swap without editing
+     /etc/fstab.
+
 /etc/sysconfig/keyboard:
 
   KEYTABLE=<keytable file>
index e32f2d087ec28458ad3427307b76f9c7af945705..1b1b97264f10543fc1e8093246b456faacea1127 100644 (file)
@@ -174,8 +174,7 @@ is_empty_file() {
 
 # returns OK if $1 contains $2
 strstr() {
-       local a=$2
-       [ "${1#*$a*}" = "$1" ] && return 1
+       [ "${1#*$2*}" = "$1" ] && return 1
        return 0
 }
 
index 0b9d5c728f5f012226ffea4898d6798df93c0f7d..e14ad740b0d3e6ba51f2d419f599273119a35c2e 100755 (executable)
@@ -102,6 +102,21 @@ parse_cmdline() {
        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!
@@ -162,6 +177,32 @@ relabel_selinux() {
        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
@@ -494,7 +535,7 @@ if ! is_yes "$VSERVER" && [[ "$container" != lxc* ]]; then
        fi
 
        # Start up swapping
-       run_cmd "Activating swap partitions" swapon -a -e
+       enable_swap -e
 
        # Initialize USB controllers
        usb=0
@@ -1005,9 +1046,7 @@ chown root:root /tmp/.ICE-unix
 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
index f86eb7369c035914b0b4d8dec132bc7f64e2a876..0734c41e44b3cfbeca9e886b7c05ea9454c94336 100644 (file)
@@ -80,6 +80,9 @@ EVMS_AIX=no
 # EVMS OS/2 LVM volumes
 EVMS_OS2=no
 
+# Set to 'yes' to allow probing for devices with swap signatures
+AUTOSWAP=no
+
 # LVM2
 # disable if your only LVM volume is rootfs started on initrd and want faster startup
 LVM2=yes
This page took 0.178211 seconds and 4 git commands to generate.