Line 13:
mkdir -p /home/${u}/${dir}
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
mkdir -p /home/"${u}"/"${dir}"
Line 19:
dd if=/dev/urandom of=${outfile} bs=${blocksize} count=1 iflag=fullblock
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
dd if=/dev/urandom of="${outfile}" bs="${blocksize}" count=1 iflag=fullblock
Line 27:
losetup ${LOOPDEV} ${img}
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
losetup "${LOOPDEV}" "${img}"
Line 28:
cryptsetup luksFormat ${img}
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
cryptsetup luksFormat "${img}"
Line 29:
cryptsetup open ${img} ${name}
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
cryptsetup open "${img}" "${name}"
Line 30:
mkfs.ext4 /dev/mapper/${name}
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
mkfs.ext4 /dev/mapper/"${name}"
Line 36:
cryptsetup open ${img} ${name}
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
cryptsetup open "${img}" "${name}"
Line 42:
mount -t ext4 /dev/mapper/${name} /home/${u}/${dir}
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
mount -t ext4 /dev/mapper/"${name}" /home/"${u}"/"${dir}"
Line 49:
umount /home/${u}/${dir}
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
umount /home/"${u}"/"${dir}"
Line 50:
cryptsetup close ${name}
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
cryptsetup close "${name}"
Oh, and I'm pleased to see that you've dropped bloaty old bash — POSIX sh ftw! :-)
]]>It looks like it worked. The previous error is gone. Maybe loop1 is left from before? I think you can just delete it manually.
that seems to be the case. Thanks again.
]]>what is it for?
See random(4). If you have any other questions then please open a new thread rather than hijack this one, thanks.
]]> ~ $ > sudo ./ccreate.sh -c test.img
+ img=test.img
+ getopts :c opt
+ case "${opt}" in
+ crypt_create test.img
+ losetup -f
++ cat /tmp/nextloop
+ LOOPDEV=/dev/loop0
+ losetup /dev/loop0 test.img
+ cryptsetup luksFormat test.img
WARNING!
========
This will overwrite data on test.img irrevocably.
Are you sure? (Type 'yes' in capital letters): YES
Enter passphrase for test.img:
Verify passphrase:
+ cryptsetup open test.img cryptfs
Enter passphrase for test.img:
+ mkfs.ext4 /dev/mapper/cryptfs
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 4096 1k blocks and 1024 inodes
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
+ getopts :c opt
~ $ > lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 20M 0 loop
loop1 7:1 0 20M 0 loop
└─cryptfs 254:1 0 4M 0 crypt
#!/bin/bash
set -x
img="$2"
crypt_create () {
losetup -f > /tmp/nextloop
LOOPDEV=$(cat /tmp/nextloop)
losetup ${LOOPDEV} $img
cryptsetup luksFormat $img
cryptsetup open $img cryptfs
mkfs.ext4 /dev/mapper/cryptfs
}
while getopts ":c" opt; do
case "${opt}" in
c ) crypt_create $2
;;
\? ) echo "Usage: cmd [c]"
;;
esac
done
+ losetup test.img
losetup: test.img: failed to use device: No such device
I think you need to define LOOPDEV after you run 'losetup -f'.
crypt_create () {
losetup -f > /tmp/nextloop
LOOPDEV=$(cat /tmp/nextloop)
losetup ${LOOPDEV} $img
cryptsetup luksFormat $img
cryptsetup open $img cryptfs
mkfs.ext4 /dev/mapper/cryptfs
}
dice wrote:i ) crypt_img $2 $3
I think that should be
i) crypt_img "$@"
Otherwise $2 & $3 will be interpreted as the third and forth arguments applied to the script.
Not sure about the encryption stuff though, I don't use that.
Yes that seems to work as well. Im having a hard time wrapping my head around this stuff, thanks.
]]>If you somehow end up with more than one loop device, you might use something like this:
losetup -f > /tmp/nextloop LOOPDEV=$(cat /tmp/nextloop) losetup ${LOOPDEV} ${LOOP_FILENAME}
That's taken from refracta2usb which can make an encrypted loopback filesystem for live-usb persistence.
Hi fsmithred, if you see this would you say this is the right way to implement loopdev?
here is just the code to the cryptsetup commands, im yet to figure out how to use that in the main script.
#!/bin/bash
set -x
LOOPDEV=$(cat /tmp/nextloop)
img="$2"
crypt_create () {
losetup -f > /tmp/nextloop
losetup ${LOOPDEV} $img
cryptsetup luksFormat $img
cryptsetup open $img cryptfs
mkfs.ext4 /dev/mapper/cryptfs
}
while getopts ":c" opt; do
case "${opt}" in
c ) crypt_create $2
;;
\? ) echo "Usage: cmd [c]"
;;
esac
done
seems to work although set -x throws some errors?
sudo ./ccreate.sh -c test.img
++ cat /tmp/nextloop
cat: /tmp/nextloop: No such file or directory
+ LOOPDEV=
+ img=test.img
+ getopts :c opt
+ case "${opt}" in
+ crypt_create test.img
+ crypt_create test.img
+ losetup -f
+ losetup test.img
losetup: test.img: failed to use device: No such device
+ cryptsetup luksFormat test.img
WARNING!
========
This will overwrite data on test.img irrevocably.
Are you sure? (Type 'yes' in capital letters): YES
Enter passphrase for test.img:
Verify passphrase:
+ cryptsetup open test.img cryptfs
Enter passphrase for test.img:
+ mkfs.ext4 /dev/mapper/cryptfs
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 4096 1k blocks and 1024 inodes
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
+ getopts :c opt
i ) crypt_img $2 $3
I think that should be
i) crypt_img "$@"
Otherwise $2 & $3 will be interpreted as the third and forth arguments applied to the script.
Not sure about the encryption stuff though, I don't use that.
]]>NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 20M 0 loop
└─cryptfs 254:1 0 4M 0 crypt /home/$u/crypt
Need to look into better command structure using more positional parameters, especially with the use of the crypt.img?
Find out how to use getopts usage better.
#!/bin/bash
set -x
u="<username>"
outfile="$2"
blocksize="$3"
crypt_img () {
dd if=/dev/urandom of=$outfile bs=$blocksize count=1 iflag=fullblock
}
crypt_create () {
losetup --find
losetup /dev/loop0 crypt.img
cryptsetup luksFormat crypt.img
cryptsetup open crypt.img cryptfs
mkfs.ext4 /dev/mapper/cryptfs
}
crypt_open () {
cryptsetup open crypt.img cryptfs
}
crypt_mount () {
mount -t ext4 /dev/mapper/cryptfs /home/$u/crypt
}
crypt_umount () {
umount /home/$u/crypt
cryptsetup close cryptfs
losetup -d /dev/loop0
}
while getopts ":iComu" opt; do
case ${opt} in
i ) crypt_img $2 $3
;;
C ) crypt_create
;;
o ) crypt_open
;;
m ) crypt_mount
;;
u ) crypt_umount
;;
\? ) echo "Usage: cmd [-i] [-C] [-o] [-m] [-u]"
;;
esac
done
thanks fsmithred, that is exactly where i am stuck right now having two loop devices.
This not anything serious btw, just trying to learn. Think i would rather use tomb to be quite honest
]]>losetup -f > /tmp/nextloop
LOOPDEV=$(cat /tmp/nextloop)
losetup ${LOOPDEV} ${LOOP_FILENAME}
That's taken from refracta2usb which can make an encrypted loopback filesystem for live-usb persistence.
]]>