From 77dfb326d54bb5b66ab23b841c40f4ff1df8f495 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sun, 15 Jul 2012 21:13:58 +0200 Subject: cryptsetup: add blkid check for safety Before we create a swap partition or a filesystm, check that nothing exists on the underlying block device. Signed-off-by: Tom Gundersen --- functions | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'functions') diff --git a/functions b/functions index a0cea12..5be90c7 100644 --- a/functions +++ b/functions @@ -468,11 +468,15 @@ do_unlock_systemd() { else IFS=, if in_array swap ${options[@]}; then - if ! mkswap /dev/mapper/$name >/dev/null; then + # create swap on the device only if no fs signature exists + blkid -p "$2" &>/dev/null + if (( $? == 2 )) || ! mkswap /dev/mapper/$name >/dev/null; then failed=1 fi elif in_array tmp ${options[@]}; then - if ! mke2fs /dev/mapper/$name >/dev/null; then + # create fs on the device only if no fs signature exists + blkid -p "$2" &>/dev/null + if (( $? == 2 )) || ! mke2fs /dev/mapper/$name >/dev/null; then failed=1 fi fi -- cgit v1.2.3