Command fails in script but copy-paste into terminal works fine.
SOLVED: it seems that my script broke due to switching to the lts kernel, which takes longer to recognize the partition name. Adding a sleep timer for 30s seems to have solved the issue. Not really a bash specific problem but you guys were super helpful. Thanks!
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.
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:19 AM UTC · edited
What are the perms of the device? Is the script being executed by cron or something else that has different ID or GID?
The script is run manually as root, so permissions shouldn't be an issue. It's not mounted and has been secure wiped and had a new GPT table and partitions created immediately prior to this command.
It's a live system with an installation script, running in VirtualBox.
The part that gets me is if I exit the script and immediately run that exact command again, it works fine. I can't figure out how tf that is possible.
Oh! It is possible that the "mapped" names (things under /dev/disk and /dev/mapper) don't exist when the script runs. If I remember correctly, those are all created by udev, not instantly upon seeing the disk.
Just add a
sleep 30to your script and see if that fixes it.If so, you can then use something more elegant like:
I suspected something like this and tried some smaller sleep times in between commands I will try the 30s wait and post the result.
Thank you! This seems to work and allows me to continue using the lts kernel, which is something I require but switching to it seems to be the reason why my script stopped working in the first place.
I guess the reason it worked for me previously is because udev recognizes the change a lot faster with the 5.x kernel vs 4.19 lts.
Happy to help :-)
Glad you got it fixed... now on to your next bug> Squish them as fast as you can, but know when you need sleep more than fixing another bug (as it's 2 AM here and I have to get up at 7 ....
if, or until loop ? :)