2015年7月29日 星期三

建立加密磁區 on Unbut / Linux / Raspberry with losetup


/* 0. Make sure you had loaded the cryptoloop module */
/* Otherwise you will get error about losetup  ioctl: LOOP_SET_STATUS: Invalid argument */
sudo modprobe cryptoloop

/* 1. Generate target encrypted partition file */
sudo dd if=/dev/zero of=/media/10M.img bs=1M count=10

/* 2. Encrypt the partition file, it will ask you the desired password. */
sudo losetup -e aes -k 256 /dev/loop0 /media/10M.img

/* 3. Make filesystem for the encrypted partition. */
sudo mkfs.ext4 /dev/loop0

/* 4. change permission and generate a test file */
mkdir /dev/shm/mydir
sudo mount -t ext4 /dev/loop0 /dev/shm/mydir
sudo chwon user:group /dev/shm/mydir
sudo chown user:group /dev/shm/mydir
echo "test" > /dev/shm/tc/test.txt
ls -lt /dev/shm/tc/

/* 5. Finish. umount the dir and loop0 */
sudo umount /dev/shm/mydir
sudo losetup -d /dev/loop0






After you umount the encrypted partition, you should see an empty folder.

/* 6. If you need to use this partition, mount it with encryption option. */
/* It will ask you the password. */
sudo mount -t ext4 /media/mydir/10G.img /dev/shm/mydir -o encryption=aes

沒有留言:

張貼留言