Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to encrypt an existing filesystem in a file that is mountable via loopback?

I thought I had a simple plan for moving from an old notebook to a new one, but actually something does not seem to work the way I think or I'm the only one to think of this way.

Anyway, I want an accessible, as in loopback mountable full partition backup of my old system and I wan't it encrypted.

So what I thought I would do is dd of the old partition to another harddrive, run some crypto magic and have a mountable encrypted backup.

After having spent two hours reading up on the topic it seems as neither truecrypt nor the in kernel crypto stuff work that way that you can just somehow encrypt an existing partition image.

So what I want to do is the following:

dd if=/dev/sda1 of=/media/old-notebook.bin 
*crypt* /media/old-notebook.bin
mount *some magic options here* /media/old-notebook.bin /mnt
cd /mnt/home/foo

Is there a way I'm missing?

share|improve this question

1 Answer 1

Ok, turns out it works with dm-crypt mostly as I want it:

dd if=/dev/zero of=/media/crypted-backup.bin bs=512 count=`blockdev --getsize /dev/hdb2`
losetup /dev/loop0 /media/crypted-backup.bin
cryptsetup -c aes -h ripemd160 -y create cryptvol1 /dev/loop0
dd if=/dev/hdb2 of=/dev/mapper/cryptvol1 bs=4k

That's not exactly an existing image, but as I was going to create the image anyway this solves the problem for me.

share|improve this answer
    
I guess you want to use --getsz instead of --getsize. If the blocksize is not 512, you may end up with /media/crypted-backup.bin having 1/2, 1/4 or 1/8 of the desired size. –  user39559 Sep 17 '10 at 13:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.