Getting the error "WRITE ERROR ON SWAP DEVICE
" on boot but all works fine when I change the line:
truncate -s $swapsize $flPtDev
by
cp /swap.img $flPtDev
The complete script is the following:
cd /home/myuser/
mkdir ./.myfolder
cd ./.myfolder
swapsize='4G'
curdir=$(pwd)
flNmDev="myfile.img"
flPtDev="$curdir/$flNmDev"
flNmKey="mykeyfile"
flPtKey="$curdir/$flNmKey"
flNmMnt="myDesiredMappedDeviceName"
flPtMnt="$curdir/$flNmMnt"
truncate -s $swapsize $flPtDev # ** THE OFFENDING LINE **
chmod 0600 $flPtDev
chown root $flPtDev
dd if=/dev/urandom of=$flPtKey bs=4096 count=1 conv=notrunc,noerror
sudo chmod 0600 $flPtKey
chown root $flPtKey
cat << EOF > /etc/crypttab
# <target name> <source device> <key file> <options>
$flNmMnt $flPtDev $flPtKey swap,offset=1024,cipher=aes-xts-plain64
EOF
cryptdisks_start $flNmMnt
rpl "/swap.img none swap sw 0 0" "#/swap.img none swap sw 0 0" /etc/fstab
echo "/dev/mapper/$flNmMnt none swap sw 0 0" >> /etc/fstab