Linux: use a file as an encrypted partition with losetup

Categories: Linux, Slackware

On my notebook i’ve decided to have a / partition and a cripted home for my user, automagically mounted at boot.
That’s what you need to do, after a fresh Slackware 13.1 installation:

Create the user:

adduser username

then the file to mount as home partition:

dd if=/dev/zero of=/cryptedfile bs=1k count=5000

load the cryptoloop module:

modprobe cryptoloop

link the file to the loop device:

losetup -e blowfish /dev/loop0 /cryptedfile

now choose a good password and DON’T FORGET IT!

create the filesystem:

mkfs -t ext3 /dev/loop0

mount the loop device to the mountpoint:

mount -t ext3 /dev/loop0 /home/username

You’re done.
Here is what i’ve on my rc.local and rc.local_shutdown to mount and umount the crypted file:
I’ve added a KILL to the user’s processes to stop all write to the encrypted file when i umount it.


modprobe cryptoloop
losetup -e blowfish /dev/loop0 /cryptedfile
mount -t ext3 /dev/loop0 /home/username/


skill -KILL -u username
sleep 4
umount /home/username
losetup -d /dev/loop0

If you’ve something to suggest, leave a comment.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.