| 1 | #!/bin/bash |
| 2 | |
| 3 | [ -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".." |
| 4 | CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup |
| 5 | DEV="" |
| 6 | DEV_STACKED="luks0xbabe" |
| 7 | DEV_NAME="dummyalign" |
| 8 | HDR="test_luks2_hdr" |
| 9 | MNT_DIR="./mnt_luks" |
| 10 | PWD1="93R4P4pIqAH8" |
| 11 | PWD2="mymJeD8ivEhE" |
| 12 | FAST_PBKDF="--pbkdf pbkdf2 --pbkdf-force-iterations 1000" |
| 13 | |
| 14 | if [ -n "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then |
| 15 | CRYPTSETUP_VALGRIND=$CRYPTSETUP |
| 16 | else |
| 17 | CRYPTSETUP_VALGRIND=../.libs/cryptsetup |
| 18 | CRYPTSETUP_LIB_VALGRIND=../.libs |
| 19 | fi |
| 20 | |
| 21 | cleanup() { |
| 22 | udevadm settle >/dev/null 2>&1 |
| 23 | if [ -d "$MNT_DIR" ] ; then |
| 24 | umount -f $MNT_DIR 2>/dev/null |
| 25 | rmdir $MNT_DIR 2>/dev/null |
| 26 | fi |
| 27 | [ -b /dev/mapper/$DEV_STACKED ] && dmsetup remove --retry $DEV_STACKED >/dev/null 2>&1 |
| 28 | [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove --retry $DEV_NAME >/dev/null 2>&1 |
| 29 | # FIXME scsi_debug sometimes in-use here |
| 30 | sleep 1 |
| 31 | rmmod scsi_debug >/dev/null 2>&1 |
| 32 | sleep 1 |
| 33 | rm -f $HDR 2>/dev/null |
| 34 | } |
| 35 | |
| 36 | fail() |
| 37 | { |
| 38 | if [ -n "$1" ] ; then echo "FAIL $1" ; fi |
| 39 | echo "FAILED backtrace:" |
| 40 | while caller $frame; do ((frame++)); done |
| 41 | cleanup |
| 42 | exit 100 |
| 43 | } |
| 44 | |
| 45 | _sigchld() { local c=$?; [ $c -eq 139 ] && fail "Segfault"; [ $c -eq 134 ] && fail "Aborted"; } |
| 46 | trap _sigchld CHLD |
| 47 | |
| 48 | skip() |
| 49 | { |
| 50 | echo "TEST SKIPPED: $1" |
| 51 | cleanup |
| 52 | exit 77 |
| 53 | } |
| 54 | |
| 55 | valgrind_setup() |
| 56 | { |
| 57 | command -v valgrind >/dev/null || fail "Cannot find valgrind." |
| 58 | [ ! -f $CRYPTSETUP_VALGRIND ] && fail "Unable to get location of cryptsetup executable." |
| 59 | [ ! -f valg.sh ] && fail "Unable to get location of valg runner script." |
| 60 | if [ -z "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then |
| 61 | export LD_LIBRARY_PATH="$CRYPTSETUP_LIB_VALGRIND:$LD_LIBRARY_PATH" |
| 62 | fi |
| 63 | } |
| 64 | |
| 65 | valgrind_run() |
| 66 | { |
| 67 | INFOSTRING="$(basename ${BASH_SOURCE[1]})-line-${BASH_LINENO[0]}" ./valg.sh ${CRYPTSETUP_VALGRIND} "$@" |
| 68 | } |
| 69 | |
| 70 | dm_crypt_features() |
| 71 | { |
| 72 | VER_STR=$(dmsetup targets | grep crypt | cut -f2 -dv) |
| 73 | [ -z "$VER_STR" ] && fail "Failed to parse dm-crypt version." |
| 74 | |
| 75 | VER_MAJ=$(echo $VER_STR | cut -f 1 -d.) |
| 76 | VER_MIN=$(echo $VER_STR | cut -f 2 -d.) |
| 77 | VER_PTC=$(echo $VER_STR | cut -f 3 -d.) |
| 78 | |
| 79 | [ $VER_MAJ -lt 1 ] && return |
| 80 | [ $VER_MAJ -gt 1 ] && { |
| 81 | DM_PERF_CPU=1 |
| 82 | DM_SECTOR_SIZE=1 |
| 83 | return |
| 84 | } |
| 85 | |
| 86 | [ $VER_MIN -lt 14 ] && return |
| 87 | DM_PERF_CPU=1 |
| 88 | if [ $VER_MIN -ge 17 ]; then |
| 89 | DM_SECTOR_SIZE=1 |
| 90 | fi |
| 91 | } |
| 92 | |
| 93 | add_device() { |
| 94 | modprobe scsi_debug $@ delay=0 >/dev/null 2>&1 |
| 95 | if [ $? -ne 0 ] ; then |
| 96 | echo "This kernel seems to not support proper scsi_debug module, test skipped." |
| 97 | exit 77 |
| 98 | fi |
| 99 | |
| 100 | sleep 1 |
| 101 | DEV=$(grep -l -e scsi_debug /sys/block/*/device/model | cut -f4 -d /) |
| 102 | |
| 103 | if [ ! -e /sys/block/$DEV/alignment_offset ] ; then |
| 104 | echo "This kernel seems to not support topology info, test skipped." |
| 105 | cleanup |
| 106 | exit 77 |
| 107 | fi |
| 108 | |
| 109 | DEV="/dev/$DEV" |
| 110 | [ -b $DEV ] || fail "Cannot find $DEV." |
| 111 | } |
| 112 | |
| 113 | format() # expected [forced] [encryption_sector_size] |
| 114 | { |
| 115 | local _sec_size=512 |
| 116 | |
| 117 | local _exp=$1 |
| 118 | |
| 119 | if [ "${2:0:1}" = "s" ]; then |
| 120 | _sec_size=${2:1} |
| 121 | shift |
| 122 | fi |
| 123 | |
| 124 | test "${3:0:1}" = "s" && _sec_size=${3:1} |
| 125 | |
| 126 | test $_sec_size -eq 512 || local _smsg=" (encryption sector size $_sec_size)" |
| 127 | |
| 128 | if [ -z "$2" ] ; then |
| 129 | echo -n "Formatting using topology info$_smsg..." |
| 130 | echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $DEV -q -c aes-cbc-essiv:sha256 --sector-size $_sec_size >/dev/null 2>&1 || fail |
| 131 | else |
| 132 | echo -n "Formatting using forced sector alignment $2$_smsg..." |
| 133 | echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $DEV -q -c aes-cbc-essiv:sha256 --align-payload=$2 --sector-size $_sec_size >/dev/null || fail |
| 134 | fi |
| 135 | |
| 136 | # check the device can be activated |
| 137 | if [ -n "$DM_SECTOR_SIZE" ] ; then |
| 138 | echo $PWD1 | $CRYPTSETUP luksOpen $DEV $DEV_NAME || fail |
| 139 | $CRYPTSETUP close $DEV_NAME || fail |
| 140 | fi |
| 141 | |
| 142 | ALIGN=$($CRYPTSETUP luksDump $DEV | grep -A1 "0: crypt" | grep "offset:" | cut -d ' ' -f2) |
| 143 | # echo "ALIGN = $ALIGN" |
| 144 | |
| 145 | [ -z "$ALIGN" ] && fail |
| 146 | ALIGN=$((ALIGN/512)) |
| 147 | [ $ALIGN -ne $_exp ] && fail "Expected alignment differs: expected $_exp != detected $ALIGN" |
| 148 | |
| 149 | # test some operation, just in case |
| 150 | echo -e "$PWD1\n$PWD2" | $CRYPTSETUP luksAddKey $DEV $FAST_PBKDF --new-key-slot 1 |
| 151 | [ $? -ne 0 ] && fail "Keyslot add failed." |
| 152 | |
| 153 | $CRYPTSETUP -q luksKillSlot $DEV 1 |
| 154 | [ $? -ne 0 ] && fail "Keyslot removal failed." |
| 155 | |
| 156 | echo "PASSED" |
| 157 | } |
| 158 | |
| 159 | format_fail() # expected [forced] [encryption_sector_size] |
| 160 | { |
| 161 | local _sec_size=512 |
| 162 | |
| 163 | local _exp=$1 |
| 164 | |
| 165 | if [ "${2:0:1}" = "s" ]; then |
| 166 | _sec_size=${2:1} |
| 167 | shift |
| 168 | fi |
| 169 | |
| 170 | test "${3:0:1}" = "s" && _sec_size=${3:1} |
| 171 | |
| 172 | test $_sec_size -eq 512 || local _smsg=" (encryption sector size $_sec_size)" |
| 173 | |
| 174 | if [ -z "$2" ] ; then |
| 175 | echo -n "Formatting using topology info$_smsg (must fail)..." |
| 176 | echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $DEV -q -c aes-cbc-essiv:sha256 --sector-size $_sec_size >/dev/null 2>&1 && fail |
| 177 | else |
| 178 | echo -n "Formatting using forced sector alignment $2$_smsg (must fail)..." |
| 179 | echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $DEV -q -c aes-cbc-essiv:sha256 --align-payload=$2 --sector-size $_sec_size >/dev/null 2>&1 && fail |
| 180 | fi |
| 181 | |
| 182 | echo "PASSED" |
| 183 | } |
| 184 | |
| 185 | auto_sector() # expected device header |
| 186 | { |
| 187 | local _exp=$1 |
| 188 | local _dev=$2 |
| 189 | local _hdr=$2 |
| 190 | local _hdrstr="" |
| 191 | local _hdrmsg="" |
| 192 | |
| 193 | if [ -n "$3" ]; then |
| 194 | _hdrstr="--header $3" |
| 195 | _hdr=$3 |
| 196 | _hdrmsg=" detached header" |
| 197 | fi |
| 198 | |
| 199 | echo -n "Formatting$_hdrmsg using optimal encryption sector size (expecting $_exp)..." |
| 200 | |
| 201 | if [ -z "$DM_SECTOR_SIZE" -a $_exp -ne 512 ]; then |
| 202 | echo "SKIPPED" |
| 203 | return |
| 204 | fi |
| 205 | |
| 206 | echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $_hdrstr $_dev -q >/dev/null 2>&1 || fail |
| 207 | |
| 208 | # check the device can be activated |
| 209 | echo $PWD1 | $CRYPTSETUP luksOpen $_hdrstr $_dev $DEV_NAME || fail |
| 210 | $CRYPTSETUP close $DEV_NAME || fail |
| 211 | |
| 212 | SECTOR=$($CRYPTSETUP luksDump $_hdr | grep -A4 "0: crypt" | grep "sector:" | cut -d ' ' -f2) |
| 213 | |
| 214 | [ -z "$SECTOR" ] && fail |
| 215 | [ $SECTOR -ne $_exp ] && fail "Expected sector size differs: expected $_exp != detected $SECTOR" |
| 216 | |
| 217 | echo "PASSED" |
| 218 | } |
| 219 | |
| 220 | [ ! -x "$CRYPTSETUP" ] && skip "Cannot find $CRYPTSETUP, test skipped." |
| 221 | [ -n "$VALG" ] && valgrind_setup && CRYPTSETUP=valgrind_run |
| 222 | if [ $(id -u) != 0 ]; then |
| 223 | echo "WARNING: You must be root to run this test, test skipped." |
| 224 | exit 77 |
| 225 | fi |
| 226 | |
| 227 | dm_crypt_features |
| 228 | modprobe --dry-run scsi_debug >/dev/null 2>&1 || skip "This kernel seems to not support proper scsi_debug module, test skipped." |
| 229 | cleanup |
| 230 | if [ -d /sys/module/scsi_debug ] ; then |
| 231 | echo "Cannot use scsi_debug module (in use or compiled-in), test skipped." |
| 232 | exit 77 |
| 233 | fi |
| 234 | |
| 235 | add_device dev_size_mb=32 |
| 236 | echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $DEV -q >/dev/null || fail |
| 237 | EXPCT=$($CRYPTSETUP luksDump $DEV | grep "offset: " | cut -f 2 -d ' ') |
| 238 | test "$EXPCT" -gt 512 || fail |
| 239 | EXPCT=$((EXPCT/512)) |
| 240 | echo "Default alignment detected: $EXPCT sectors" |
| 241 | cleanup |
| 242 | |
| 243 | echo "# Create desktop-class 4K drive" |
| 244 | echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0)" |
| 245 | add_device dev_size_mb=32 sector_size=512 physblk_exp=3 num_tgts=1 |
| 246 | format $EXPCT |
| 247 | format $EXPCT s1024 |
| 248 | format $EXPCT s2048 |
| 249 | format $EXPCT s4096 |
| 250 | format $EXPCT 1 |
| 251 | format $EXPCT 1 s1024 |
| 252 | format $EXPCT 1 s2048 |
| 253 | format $EXPCT 1 s4096 |
| 254 | format $EXPCT 8 |
| 255 | format $EXPCT 8 s1024 |
| 256 | format $EXPCT 8 s2048 |
| 257 | format $EXPCT 8 s4096 |
| 258 | format $((EXPCT+1)) $((EXPCT+1)) |
| 259 | format_fail $((EXPCT+1)) $((EXPCT+1)) s1024 |
| 260 | format_fail $((EXPCT+1)) $((EXPCT+1)) s2048 |
| 261 | format_fail $((EXPCT+1)) $((EXPCT+1)) s4096 |
| 262 | format $EXPCT $EXPCT |
| 263 | format $EXPCT $EXPCT s1024 |
| 264 | format $EXPCT $EXPCT s2048 |
| 265 | format $EXPCT $EXPCT s4096 |
| 266 | cleanup |
| 267 | |
| 268 | echo "# Create desktop-class 4K drive with misaligned opt-io (some bad USB enclosures)" |
| 269 | echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0, opt-io=1025)" |
| 270 | add_device dev_size_mb=32 sector_size=512 physblk_exp=3 num_tgts=1 opt_blks=1025 |
| 271 | format $EXPCT |
| 272 | format $EXPCT s1024 |
| 273 | format $EXPCT s2048 |
| 274 | format $EXPCT s4096 |
| 275 | format $EXPCT 1 |
| 276 | format $EXPCT 1 s1024 |
| 277 | format $EXPCT 1 s2048 |
| 278 | format $EXPCT 1 s4096 |
| 279 | format $EXPCT 8 |
| 280 | format $EXPCT 8 s1024 |
| 281 | format $EXPCT 8 s2048 |
| 282 | format $EXPCT 8 s4096 |
| 283 | format $((EXPCT+1)) $((EXPCT+1)) |
| 284 | format_fail $((EXPCT+1)) $((EXPCT+1)) s1024 |
| 285 | format_fail $((EXPCT+1)) $((EXPCT+1)) s2048 |
| 286 | format_fail $((EXPCT+1)) $((EXPCT+1)) s4096 |
| 287 | format $EXPCT $EXPCT |
| 288 | format $EXPCT $EXPCT s1024 |
| 289 | format $EXPCT $EXPCT s2048 |
| 290 | format $EXPCT $EXPCT s4096 |
| 291 | cleanup |
| 292 | |
| 293 | echo "# Create drive with misaligned opt-io to page-size (some bad USB enclosures)" |
| 294 | echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0, opt-io=33553920)" |
| 295 | add_device dev_size_mb=32 sector_size=512 num_tgts=1 opt_blks=65535 |
| 296 | format $EXPCT |
| 297 | format $EXPCT s1024 |
| 298 | format $EXPCT s2048 |
| 299 | format $EXPCT s4096 |
| 300 | format $EXPCT 1 |
| 301 | format $EXPCT 1 s1024 |
| 302 | format $EXPCT 1 s2048 |
| 303 | format $EXPCT 1 s4096 |
| 304 | format $EXPCT 8 |
| 305 | format $EXPCT 8 s1024 |
| 306 | format $EXPCT 8 s2048 |
| 307 | format $EXPCT 8 s4096 |
| 308 | format $((EXPCT+1)) $((EXPCT+1)) |
| 309 | format_fail $((EXPCT+1)) $((EXPCT+1)) s1024 |
| 310 | format_fail $((EXPCT+1)) $((EXPCT+1)) s2048 |
| 311 | format_fail $((EXPCT+1)) $((EXPCT+1)) s4096 |
| 312 | format $EXPCT $EXPCT |
| 313 | format $EXPCT $EXPCT s1024 |
| 314 | format $EXPCT $EXPCT s2048 |
| 315 | format $EXPCT $EXPCT s4096 |
| 316 | cleanup |
| 317 | |
| 318 | echo "# Create desktop-class 4K drive w/ 1-sector shift (original bug report)" |
| 319 | echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=512)" |
| 320 | add_device dev_size_mb=32 sector_size=512 physblk_exp=3 lowest_aligned=1 num_tgts=1 |
| 321 | format $((EXPCT+1)) |
| 322 | format_fail $((EXPCT+1)) s1024 |
| 323 | format_fail $((EXPCT+1)) s2048 |
| 324 | format_fail $((EXPCT+1)) s4096 |
| 325 | format $EXPCT 1 |
| 326 | format $EXPCT 1 s1024 |
| 327 | format $EXPCT 1 s2048 |
| 328 | format $EXPCT 1 s4096 |
| 329 | format $EXPCT 8 |
| 330 | format $EXPCT 8 s1024 |
| 331 | format $EXPCT 8 s2048 |
| 332 | format $EXPCT 8 s4096 |
| 333 | format $((EXPCT+1)) $((EXPCT+1)) |
| 334 | format_fail $((EXPCT+1)) $((EXPCT+1)) s1024 |
| 335 | format_fail $((EXPCT+1)) $((EXPCT+1)) s2048 |
| 336 | format_fail $((EXPCT+1)) $((EXPCT+1)) s4096 |
| 337 | format $EXPCT $EXPCT |
| 338 | format $EXPCT $EXPCT s1024 |
| 339 | format $EXPCT $EXPCT s2048 |
| 340 | format $EXPCT $EXPCT s4096 |
| 341 | cleanup |
| 342 | |
| 343 | echo "# Create desktop-class 4K drive w/ 63-sector DOS partition compensation" |
| 344 | echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=3584)" |
| 345 | add_device dev_size_mb=32 sector_size=512 physblk_exp=3 lowest_aligned=7 num_tgts=1 |
| 346 | format $((EXPCT+7)) |
| 347 | format_fail $((EXPCT+7)) s1024 |
| 348 | format_fail $((EXPCT+7)) s2048 |
| 349 | format_fail $((EXPCT+7)) s4096 |
| 350 | format $EXPCT 1 |
| 351 | format $EXPCT 1 s1024 |
| 352 | format $EXPCT 1 s2048 |
| 353 | format $EXPCT 1 s4096 |
| 354 | format $EXPCT 8 |
| 355 | format $EXPCT 8 s1024 |
| 356 | format $EXPCT 8 s2048 |
| 357 | format $EXPCT 8 s4096 |
| 358 | format $((EXPCT+1)) $((EXPCT+1)) |
| 359 | format_fail $((EXPCT+1)) $((EXPCT+1)) s1024 |
| 360 | format_fail $((EXPCT+1)) $((EXPCT+1)) s2048 |
| 361 | format_fail $((EXPCT+1)) $((EXPCT+1)) s4096 |
| 362 | format $EXPCT $EXPCT |
| 363 | format $EXPCT $EXPCT s1024 |
| 364 | format $EXPCT $EXPCT s2048 |
| 365 | format $EXPCT $EXPCT s4096 |
| 366 | cleanup |
| 367 | |
| 368 | echo "# Create enterprise-class 4K drive" |
| 369 | echo "# (logical_block_size=4096, physical_block_size=4096, alignment_offset=0)" |
| 370 | add_device dev_size_mb=32 sector_size=4096 num_tgts=1 opt_blks=64 |
| 371 | format $EXPCT |
| 372 | format $EXPCT s1024 |
| 373 | format $EXPCT s2048 |
| 374 | format $EXPCT s4096 |
| 375 | format $EXPCT 1 |
| 376 | format $EXPCT 1 s1024 |
| 377 | format $EXPCT 1 s2048 |
| 378 | format $EXPCT 1 s4096 |
| 379 | format $EXPCT 8 |
| 380 | format $EXPCT 8 s1024 |
| 381 | format $EXPCT 8 s2048 |
| 382 | format $EXPCT 8 s4096 |
| 383 | #FIXME: kernel limits issue? |
| 384 | ##format $((EXPCT+1)) $((EXPCT+1)) |
| 385 | format_fail $((EXPCT+1)) $((EXPCT+1)) s1024 |
| 386 | format_fail $((EXPCT+1)) $((EXPCT+1)) s2048 |
| 387 | format_fail $((EXPCT+1)) $((EXPCT+1)) s4096 |
| 388 | format $EXPCT $EXPCT |
| 389 | format $EXPCT $EXPCT s1024 |
| 390 | format $EXPCT $EXPCT s2048 |
| 391 | format $EXPCT $EXPCT s4096 |
| 392 | cleanup |
| 393 | |
| 394 | echo "# Create classic 512B drive and stack dm-linear" |
| 395 | echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0)" |
| 396 | add_device dev_size_mb=32 sector_size=512 num_tgts=1 |
| 397 | DEV2=$DEV |
| 398 | DEV=/dev/mapper/$DEV_STACKED |
| 399 | dmsetup create $DEV_STACKED --table "0 65536 linear $DEV2 0" |
| 400 | format $EXPCT |
| 401 | format $EXPCT s1024 |
| 402 | format $EXPCT s2048 |
| 403 | format $EXPCT s4096 |
| 404 | format $EXPCT 1 |
| 405 | format $EXPCT 1 s1024 |
| 406 | format $EXPCT 1 s2048 |
| 407 | format $EXPCT 1 s4096 |
| 408 | format $EXPCT 8 |
| 409 | format $EXPCT 8 s1024 |
| 410 | format $EXPCT 8 s2048 |
| 411 | format $EXPCT 8 s4096 |
| 412 | format $((EXPCT+1)) $((EXPCT+1)) |
| 413 | format_fail $((EXPCT+1)) $((EXPCT+1)) s1024 |
| 414 | format_fail $((EXPCT+1)) $((EXPCT+1)) s2048 |
| 415 | format_fail $((EXPCT+1)) $((EXPCT+1)) s4096 |
| 416 | format $EXPCT $EXPCT |
| 417 | format $EXPCT $EXPCT s1024 |
| 418 | format $EXPCT $EXPCT s2048 |
| 419 | format $EXPCT $EXPCT s4096 |
| 420 | cleanup |
| 421 | |
| 422 | echo "# Create enterprise-class 4K drive with fs and LUKS images." |
| 423 | # loop device here presents 512 block but images have 4k block |
| 424 | # cryptsetup should properly use 4k block on direct-io |
| 425 | add_device dev_size_mb=32 sector_size=4096 physblk_exp=0 num_tgts=1 opt_blks=64 |
| 426 | for file in $(ls img_fs_*.img.xz) ; do |
| 427 | echo -n "Format using fs image $file. " |
| 428 | xz -d -c $file | dd of=$DEV bs=1M 2>/dev/null || fail "bad image" |
| 429 | [ ! -d $MNT_DIR ] && mkdir $MNT_DIR |
| 430 | mount $DEV $MNT_DIR 2>/dev/null |
| 431 | if [ $? -ne 0 ] ; then |
| 432 | echo "[N/A]" |
| 433 | continue |
| 434 | fi |
| 435 | echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $MNT_DIR/luks.img --offset 8192 || fail |
| 436 | echo $PWD2 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $MNT_DIR/luks.img --header $MNT_DIR/luks_header.img || fail |
| 437 | umount $MNT_DIR || fail |
| 438 | echo "[OK]" |
| 439 | done |
| 440 | cleanup |
| 441 | |
| 442 | echo "# Create classic 512B drive" |
| 443 | echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0)" |
| 444 | add_device dev_size_mb=32 sector_size=512 num_tgts=1 |
| 445 | auto_sector 512 $DEV |
| 446 | auto_sector 512 $DEV $HDR |
| 447 | cleanup |
| 448 | echo "# Create desktop-class 4K drive" |
| 449 | echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0)" |
| 450 | add_device dev_size_mb=32 sector_size=512 physblk_exp=3 num_tgts=1 |
| 451 | auto_sector 4096 $DEV |
| 452 | auto_sector 4096 $DEV $HDR |
| 453 | DEV2=$DEV |
| 454 | DEV=/dev/mapper/$DEV_STACKED |
| 455 | dmsetup create $DEV_STACKED --table "0 $((`blockdev --getsz $DEV2`-1)) linear $DEV2 0" |
| 456 | auto_sector 512 $DEV |
| 457 | auto_sector 512 $DEV $HDR |
| 458 | cleanup |
| 459 | echo "# Create enterprise-class 4K drive" |
| 460 | echo "# (logical_block_size=4096, physical_block_size=4096, alignment_offset=0)" |
| 461 | add_device dev_size_mb=32 sector_size=4096 num_tgts=1 opt_blks=64 |
| 462 | auto_sector 4096 $DEV |
| 463 | auto_sector 4096 $DEV $HDR |
| 464 | cleanup |
| 465 | |
| 466 | exit 0 |