Command fails in script but is successful in terminal
SOLVED: with a 30 second sleep timer lol. The problem was due to changing to the lts kernel, where udev takes a little longer to recognize the partition name.
This is driving me absolutely insane, especially since it used to work and now it refuses to no matter what I do.
The command in question is:
echo -n "$CRYPTPASS" | cryptsetup luksFormat -d - --align-payload=8192 -s 256 -c aes-xts-plain64 /dev/disk/by-partlabel/cryptsystem
It fails with the error: Device /dev/disk/by-partlabel/cryptsystem doesn't exist or access denied.
The partition in question definitely exists with the defined label. I can literally copy-paste the command into the terminal right after getting the error from the script and it works fine. So WTF?
I'm about ready to throw my PC out the window at this point so I'd really appreciate any help you can offer.
Posted Jan 22, 2020, 6:21 AM UTC · edited
So... what did you do?
Make sure the script has access to the device, i.e. run it as root.
I've solved the problem now thanks to one awesome guy in the bash sub. I forgot I switched kernels recently and, with the lts kernel, udev takes a little longer to recognize the change in partition name.
I tried literally everything I could think of over the course of several days. Including setting some sleep timers in there, I just didn't set them for long enough I guess. 30s sleep solved it lol.
So you're in the initrd? I suggest you look into switching it to systemd, and making a unit file that depends on the device unit being up; that way systemd will wait until the device appears before executing the script, and you don't have to fiddle with hardcoded wait timers (and will continue starting everything else in parallel, as far as possible).
The partition and label are created by the script, just prior creating the encrypted container, so I'm going to add a timer loop to sleep until the device appears, instead of just a hard 30s sleep.
In a different situation I would prefer to do what you suggest though.