diff options
author | Tom Gundersen <teg@jklm.no> | 2012-07-15 21:13:58 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2012-07-15 21:13:58 +0200 |
commit | 77dfb326d54bb5b66ab23b841c40f4ff1df8f495 (patch) | |
tree | f1ba7f7220ccad9389316595c13fd49be05b8116 | |
parent | 046d35bac04022eab343e9e6e40a3056c5e653ad (diff) |
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 <teg@jklm.no>
-rw-r--r-- | functions | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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 |