-
Notifications
You must be signed in to change notification settings - Fork 1
/
create.sh
executable file
·44 lines (32 loc) · 1.05 KB
/
create.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Create a LUKS crypto container with filesystem inside
DIR=$(dirname $0)
source $DIR/helper.sh
source $DIR/config.sh
if [ $# -ne 4 ]
then
echo "Usage: $0 <container> <dd prefix> <dd container> <size>"
exit
fi
checkroot
CONTAINER="$1"
DD_PREFIX="$2"
DD_CONTAINER="$3"
SIZE="$4"
LOOP=$(losetup -f)
msg_status "Creating container file \"$CONTAINER\" of size $SIZE MiB..."
runuser $DD_PREFIX dd if=$FILLDEV of=$DD_CONTAINER bs=1M count=$SIZE || die
msg_status "Mounting image file \"$CONTAINER\" as \"$LOOP\"..."
losetup $LOOP $CONTAINER || die
msg_status "Creating crypto container inside \"$CONTAINER\" ($LUKSFORMAT)..."
cryptsetup $LUKSFORMAT $LOOP || die
msg_status "Mounting crypto container as \"$CRYPTNAME\"..."
cryptsetup luksOpen $LOOP $CRYPTNAME || die
msg_status "Creating filesystem ($MKFS) in \"$MAPPER/$CRYPTNAME\"..."
mkfs.ext4 $MAPPER/$CRYPTNAME || die
msg_status "Closing crypto container..."
cryptsetup luksClose $CRYPTNAME || die
msg_status "Unmounting image file..."
losetup -d $LOOP || die
msg_status "Done."
ls -lah $CONTAINER