Tuesday, July 29, 2014

File based disk image with encryption

File based disk image with encryption I was thinking this could be used for cloud storage where security is a concern. Once created you can save the disk image to a place like Copy, Dropbox, or Box

Creating the disk image

200M disk image
dd if=/dev/zero of=./disk_image.img bs=1MiB count=200

Set up encryption on the disk

sudo cryptsetup luksFormat disk_image.img sudo cryptsetup open disk_image.img crypt
sudo fdisk -l
Output:
Disk /dev/mapper/crypt: 198 MiB, 207618048 bytes, 405504 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Formatting the encrypted disk

sudo mkfs.xfs /dev/mapper/crypt
Output:
meta-data=/dev/mapper/crypt      isize=256    agcount=4, agsize=12672 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=50688, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Mount the disk

sudo mount /dev/mapper/crypt /mnt/crypt

Closing everything out

sudo umount /mnt/crypt sudo cryptsetup close /dev/mapper/crypt