# Can't setup a loop device (for encryption)

## KristyX

I'm trying to encrypt my home directory on my laptop so that if, God forbid, anything

should happen, the data won't be accessible.

But one of the steps calls for the setup of loop device using losetup.

My problem is, this is the error I get:

```

lappy kristy # losetup /dev/loop0 /home/kristy_home

/dev/loop0: No such file or directory

```

I tried creating an empty file called /dev/loop0 but then the error I get is:

```

lappy kristy # nano /dev/loop0

lappy kristy # losetup /dev/loop0 /home/kristy_home

ioctl: LOOP_SET_FD: Inappropriate ioctl for device

```

The HowTo I'm following is here

Anyone have any ideas?

Thanks,

Kristy

----------

## bLaXe

Do you have the relevant options/modules in the kernel? (this thread might help).

Have you modprobed the modules you need? (iirc you need 'dm-crypt')

----------

## KristyX

Yes, I have.. I compiled the necessary kernel modules and everything. And I added dm-crypt to my autoload file

for kernel-2.6. I'm just not sure what I'm missing out..

Thanks,

Kristy

----------

## KristyX

Anyone??

----------

## pteppic

The loop devices should be created for you in the directory /dev/loop as numbers 0 through 7, /dev/loop0 is just a symlink, so it may be just those missing.

You can create your own loop devices with 

```
mknod /dev/loopX b 7 X
```

 where X is the device number you wish to create.

----------

## KristyX

Thanks pteppic. I managed to set up the devices but now, running the command below results in an error "Command failed: Block device required"

```

lappy kristy # echo $KEY | cryptsetup create kristy /dev/loop0

Command failed: Block device required

```

```

lappy kristy # mknod /dev/loop0 b 7 1

lappy kristy # ls -l /dev/l*

lrwxrwxrwx  1 root root      6 Dec  2 11:46 /dev/loop0 -> loop/0

lrwxrwxrwx  1 root root      6 Dec  2 11:46 /dev/loop1 -> loop/1

lrwxrwxrwx  1 root root      6 Dec  2 11:46 /dev/loop2 -> loop/2

lrwxrwxrwx  1 root root      6 Dec  2 11:46 /dev/loop3 -> loop/3

lrwxrwxrwx  1 root root      6 Dec  2 11:46 /dev/loop4 -> loop/4

lrwxrwxrwx  1 root root      6 Dec  2 11:46 /dev/loop5 -> loop/5

lrwxrwxrwx  1 root root      6 Dec  2 11:46 /dev/loop6 -> loop/6

lrwxrwxrwx  1 root root      6 Dec  2 11:46 /dev/loop7 -> loop/7

```

Thanks,

Kristy

----------

## pteppic

From start to finish: 

```
dd if=/dev/zero of=/home/kristy_home  bs=1M count=100 #make a 100meg file called krist_home to be the encrypted block filesystem

losetup  /dev/loop0 /home/kristy_home                 #attach to the loop

echo $password| cryptsetup create kristy /dev/loop0   # create the logical device kristy in /dev/mapper

mkfs /mnt/mapper/kristy                               #format it.

mount /dev/mapper/kristy /home/kristy/encrypted       # I assume thats what you plan to do next?
```

and to undo...

```
umount /dev/mapper/kristy

crypsetup remove kristy

losetup -d /dev/loop0

```

I assume (big assumption?) that you need the same kernel modules and packages as you do for encrypting whole partitions, which for me were

modules:

Device Drivers  --->Block devices  --->Loopback device support

Multi-device support (RAID and LVM)  --->Device mapper support & Crypt target support (not sure about these ones, build as modules and see if it works without.)

Cryptographic options  ---> AES cipher algorithms (arch)

packages:

device-mapper

multipath-tools 

cryptsetup or cryptsetup-luks

Then all you need is a usb key to keep that huge, randomly generated password on, and a microwave to throw it into when the 'authorities' come knocking.

----------

