summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bächler <thomas@archlinux.org>2011-01-26 17:30:59 +0100
committerThomas Bächler <thomas@archlinux.org>2011-01-26 17:30:59 +0100
commit6cfb498956013f69aa2d6004b235842be9c938bc (patch)
treebfd3540ab7fb71a2eeac3b29af4b77153a5b40ac
parent8569035c827a23fd0acf5681f4ec19a93eefbae7 (diff)
Change SWAP sanity check to use blkid in favor of cryptsetup
This improves the sanity check before overwriting a partition with randomly encrypted swapspace. A device will only be overwritten if blkid finds no valid file system on it, otherwise the process will be aborted.
-rwxr-xr-xrc.sysinit21
1 files changed, 17 insertions, 4 deletions
diff --git a/rc.sysinit b/rc.sysinit
index 44238fa..f5c3e87 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -145,10 +145,23 @@ if [[ -f /etc/crypttab && $CS ]]; then
fi
case $3 in
SWAP)
- if [[ $_isluks ]]; then
- # This is DANGEROUS! The only possible safety check
- # is to not proceed in case we find a LUKS device
- # This may cause dataloss if it is not used carefully
+ local _overwriteokay=0
+ if [[ -b $2 && -r $2 ]]; then
+ # This is DANGEROUS! If there is any known file system,
+ # partition table, RAID or LVM volume on the device
+ # we don't overwrite it.
+ #
+ # 'blkid' returns 2 if no valid signature has been found.
+ # Only in this case we should allow overwriting the device.
+ #
+ # This sanity check _should_ be sufficient, but it might not.
+ # This may cause dataloss if it is not used carefully.
+ /sbin/blkid -p "$2" &>/dev/null
+ if [[ $? -eq 2 ]]; then
+ _overwriteokay=1
+ fi
+ fi
+ if [[ $_overwriteokay -eq 0 ]]; then
false
elif $CS -d /dev/urandom $4 $open "$a" "$b" >/dev/null; then
stat_append "creating swapspace.."