# Cannot setup dm-crypt

**URL:** <https://forum.openwrt.org/t/cannot-setup-dm-crypt/56836>\
**Category:** Installing and Using OpenWrt\
**Created:** [March 4, 2020, 2:19am UTC](https://forum.openwrt.org/t/cannot-setup-dm-crypt/56836 "2020-03-04T02:19:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Livy](https://forum.openwrt.org/user_avatar/forum.openwrt.org/livy/32/15990_2.png) [@Livy](https://forum.openwrt.org/u/Livy)\
**Post date:** [March 4, 2020, 2:19am UTC](https://forum.openwrt.org/t/cannot-setup-dm-crypt/56836/1 "2020-03-04T02:19:40Z")

</div>

```
root@OpenWrt:~# opkg install "kmod-crypto-ecb" "kmod-crypto-iv" "kmod-crypto-misc" "cryptsetup";
root@OpenWrt:~# cryptsetup luksFormat "/dev/sda";
WARNING: Device /dev/sda already contains a 'iso9660' superblock signature.
WARNING: Device /dev/sda already contains a 'gpt' partition signature.
WARNING!
========
This will overwrite data on /dev/sda irrevocably.
Are you sure? (Type uppercase yes): YES
Enter passphrase for /dev/sda:
Verify passphrase:
Locking aborted. The locking path /run/cryptsetup is unusable (not a directory or missing).
Failed to acquire write device lock.
Cannot format device /dev/sda in use.
root@OpenWrt:/etc/hotplug.d/block# block info
/dev/mtdblock5: UUID="1ed3cb7b-cf7c8a04-ffbb0445-861f2a0e" VERSION="4.0" MOUNT="/rom" TYPE="squashfs"
/dev/mtdblock6: MOUNT="/overlay" TYPE="jffs2"

```

Before the `luksFormat` command, the device `/dev/sda` was plugged-in, not mounted or in use of any sort. After the format failed, it magically disappeared from the system. `block info` won't detect it until I plug it into a PC to create a MBR / GPT.

What is the problem and how do I solve it?

---

<div class="post-metadata">

**Author:** ![neheb](https://forum.openwrt.org/user_avatar/forum.openwrt.org/neheb/32/545_2.png) [@neheb](https://forum.openwrt.org/u/neheb)\
**Post date:** [March 4, 2020, 6:38am UTC](https://forum.openwrt.org/t/cannot-setup-dm-crypt/56836/2 "2020-03-04T06:38:32Z")

</div>

Wrong path. Seems this has to be fixed.

---

<div class="post-metadata">

**Author:** ![Livy](https://forum.openwrt.org/user_avatar/forum.openwrt.org/livy/32/15990_2.png) [@Livy](https://forum.openwrt.org/u/Livy)\
**Post date:** [March 4, 2020, 12:26pm UTC](https://forum.openwrt.org/t/cannot-setup-dm-crypt/56836/3 "2020-03-04T12:26:54Z")

</div>

Alright, I solve the problem by creating the directory `/run/cryptsetup`. I do not know what is that directory used for, but it should be created by default after the packet `cryptsetup` is installed.

After the format fails, looks like the MBR / GPT is destroyed. Still, what I want to know is why the USB device cannot be detected by `block info` until I re-create a MBR / GPT for it?

The OpenWrt user guide for disk encryption is poorly maintained. Even the sample auto-mount script is written in **Bash**. I'll port it back into pure Busybox **ash** when my testing goes well enough.

---

<div class="post-metadata">

**Author:** ![eduperez](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eduperez/32/2066_2.png) [@eduperez](https://forum.openwrt.org/u/eduperez)\
**Post date:** [March 4, 2020, 1:35pm UTC](https://forum.openwrt.org/t/cannot-setup-dm-crypt/56836/4 "2020-03-04T13:35:53Z")

</div>

> [@Livy](#):
>
> After the format fails, looks like the MBR / GPT is destroyed.

Well, you ran "cryptsetup" over "/dev/sda", what did you expect?

---

<div class="post-metadata">

**Author:** ![neheb](https://forum.openwrt.org/user_avatar/forum.openwrt.org/neheb/32/545_2.png) [@neheb](https://forum.openwrt.org/u/neheb)\
**Post date:** [March 5, 2020, 3:32am UTC](https://forum.openwrt.org/t/cannot-setup-dm-crypt/56836/5 "2020-03-05T03:32:39Z")

</div>

Opened a PR fixing this: [https://github.com/openwrt/packages/pull/11508](https://github.com/openwrt/packages/pull/11508)
