# Failed to stop array: device or resource busy RAID/DMCrypt

## eponymous

Hi,

I've set up encryption using dmcrypt/luks on my /dev/md0 which is a RAID0 array.

It seems I'm running into issues when I do a reboot or halt in that it doesn't stop the array properly. I never had this issue until I encrypted the disks.

/dev/md0 is just three disks which are used as a backup store - no root, boot or swap on these.

/var/log/rc.log:

```
1340  [ ok ]

1341  * Shutting down RAID devices (mdadm) ...

1342 mdadm: stopped /dev/md1

1343 mdadm: failed to stop array /dev/md0: Device or resource busy

1344 Perhaps a running process, mounted filesystem or active volume group?

1345  [ !! ]

1346  * ERROR: mdraid failed to stop

1347  * Removing dm-crypt mappings

1348  *   crypt_backup ...

1349  [ ok ]

1350  *   crypt_md0 ...

1351  [ ok ]

```

Should the RAID devices not be stopped after the dm-crypt mappings are removed? If so, how do you change that order?

----------

## krinn

not sure if it will work, but i would tried 

rc_dm_crypt_need="dmraid" in rc.conf (names might not be that, check them)

so telling openrc dm-crypt need dmraid should trigger stopping dm-crypt if dmraid goes on stop.

----------

## eponymous

Ah I should've mentioned I'm not using dmraid. I'm only using mdadm and dmcrypt. The only init scripts I have for this are /etc/init.d/dmcrypt and /etc/init.d/mdadm both of which are in the "boot" runlevel.

----------

## eponymous

Hi,

I want to make /etc/init.d/dmcrypt stop before /etc/init/d/mdadm so that the luksClose occurs before the raid arrays are taken down (as it should already do...).

However on startup, it should be mdadm that is called first so that the raid nodes are setup and then encryption is started afterward (which I think is already happening).

Does anyone know how to do this?

I've looked at the depend {} section of the init script but does this seems to apply to startup only?

----------

## eponymous

Honestly, can no one help me with this?

----------

## desultory

Merged the two preceding posts.

----------

## mbar

rc_dmcrypt_after="xxxxxx" in rc.conf

xxxxxxx is mdadm or mdraid depending on your config.

----------

## eponymous

I managed to solve it by putting the following in /etc/init.d/dmcrypt:

```
depend () {

...

after mdadm mdraid

}
```

Where is this kind of thing documented?

There is only limited info in the Gentoo init script guide and in the man pages...

----------

