Add AddSwap task
authorNikos Skalkotos <skalkoto@grnet.gr>
Fri, 11 May 2012 14:44:50 +0000 (17:44 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Fri, 11 May 2012 14:44:50 +0000 (17:44 +0300)
This task is used to set up the swap partition previously created by
FixPartitionTable task and to add a swap entry in the instances fstab
file.

snf-image-helper/common.sh
snf-image-helper/tasks/40AddSwap.in [new file with mode: 0644]
snf-image-helper/tasks/Makefile.am

index 7bd72ee..734a2b4 100644 (file)
@@ -28,6 +28,8 @@ TUNE2FS=tune2fs
 RESIZE2FS=resize2fs
 PARTED=parted
 SFDISK=sfdisk
+MKSWAP=mkswap
+BLKID=blkid
 REGLOOKUP=reglookup
 CHNTPW=chntpw
 
diff --git a/snf-image-helper/tasks/40AddSwap.in b/snf-image-helper/tasks/40AddSwap.in
new file mode 100644 (file)
index 0000000..0ae970b
--- /dev/null
@@ -0,0 +1,70 @@
+#! /bin/bash
+
+# Copyright (C) 2011 GRNET S.A. 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+### BEGIN TASK INFO
+# Provides:            AddSwap
+# RunBefore:            UmountImage
+# RunAfter:             MountImage
+# Short-Description:    Set up the swap partition and add an entry in fstab
+### END TASK INFO
+
+set -e
+. "@commondir@/common.sh"
+
+# Check if the task should be prevented from running.
+check_if_excluded
+
+if [ ! -d "$SNF_IMAGE_TARGET" ]; then
+    log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing."
+fi
+
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then
+    exit 0
+fi
+
+if [ -z "$SNF_IMAGE_PROPERTY_SWAP" ]; then
+    warn "No swap partition defined"
+    exit 0
+fi
+
+if [[ "$SNF_IMAGE_PROPERTY_SWAP" =~ ^([0-9]+):[0-9]+$ ]]; then
+    swap_id=${BASH_REMATCH[1]}
+else
+    log_error "SWAP property \`$SNF_IMAGE_PROPERTY_SWAP' is not valid"
+fi
+
+swap_dev="${SNF_IMAGE_DEV}${swap_id}"
+
+if [ ! -b "$swap_dev" ]; then
+    log_error "Swap partition \`$swap_dev' is missing."
+fi
+
+$MKSWAP "$swap_dev"
+
+UUID=$(cut -d" " -f2 <<< $($BLKID -s UUID "$swap_dev"))
+
+if [ -f "$SNF_IMAGE_TARGET/etc/fstab" ]; then
+    echo -e "$UUID\tnone\tswap\tsw\t0\t0" >> "$SNF_IMAGE_TARGET/etc/fstab"
+else
+    log_error "/etc/fstab file is missing"
+fi
+
+exit 0
+
+# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
index 2a62293..1e9175c 100644 (file)
@@ -4,6 +4,7 @@ dist_tasks_SCRIPTS = \
                10FixPartitionTable \
                20FilesystemResizeUnmounted \
                30MountImage \
+               40AddSwap \
                40DeleteSSHKeys \
                40DisableRemoteDesktopConnections \
                40InstallUnattend \