After installing Ubuntu with encrypted LVM, I decided to do go ahead and encrypt the external drives the server uses with cryptsetup LUKS command. But for some reason I kept getting this error: Command failed with code 22: Invalid argument
I plan to write up a detailed guide on encrypting drives, but in the meantime I just wanted to post how to fix this error.
Using Cryptsetup
When you’re using the installer, setting up encryption doesn’t involve the command line; the GUI lets you choose your settings through its menus and then it does the rest. When you’re encrypting external drives, you have to write the commands yourself.
After you get your drives, partitions, etc. set up the way you want them and you’re ready to create your encrypted volume, all you have to do is enter this simple line:
cryptsetup luksFormat -vy
The cryptsetup
program calls the luksFormat
function to encrypt your device. Your device name goes after your options there. The “v” is for verbose, and the “y” is to prompt you for a passphrase. That way you’ll be able to de-/-encrypt the volume at will.
If you entered the right information, you receive this warning from cryptsetup
:
WARNING!
========
This will overwrite data on /dev/mapper/enclosure-data irrevocably.Are you sure? (Type uppercase yes):
Here’s where the trouble starts.
Command failed with code 22: Invalid argument
For a reason unknown to me at the time, I kept getting this error at this point of the encryption process:
Command failed with code 22: Invalid argument
I was driving myself crazy going over each part of the command to figure out what I had done wrong.
It wasn’t until I reread the cryptsetup
prompt that I realized my mistake wasn’t in the original command; the mistake was in my response to cryptsetup
‘s warning.
WARNING!
========
This will overwrite data on /dev/mapper/enclosure-data irrevocably.Are you sure? (Type uppercase yes):
With many prompts in Ubuntu, you can just type “y” for yes and “n” for no.
Not the case with cryptsetup
. The error I was getting was because I was just typing “y” at this prompt. The letter alone doesn’t cut it. To get this command to go through you have to type out “YES” in all uppercase letters.
Once you enter that correctly, the program should proceed by asking you to enter the passphrase. After you verify the passphrase and the volume is set up, you’ll get a confirmation of the process.
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Command successful.
So if your terminal tells you, “Command failed with code 22: Invalid argument,” now you know what to do.
You saved my day, I was going crazy, thanks.
Haha, i am such an idiot! Thank you for this helpful post 🙂
This is because human beings are lazy and if they may skip to read one sentence, they will. It happened to me too and this was very helpful though it made me feel stupid too. Thanks.
You saved my day, thanks. Fortunately, I found your post about 3mn after having the problem. I would be mad to lose my time for such a “problem” =)
Looks like someone fails to read the instructions carefully for this every year.
– Guilty person of 2016 –
Thank 8)
I fight with this more than a hour, and not this was the first situation to meet wit this uppercase letters problem.
I feel so idiotic. Thanks for this after hours of pulling my hair out.
Yes! I make the same mistake. Just for not follow the instructions.
I’m feel idiot now. But thanks.
Same here, wish the error message was better, I was also checking and testing arguments to see what I had missed.
God damn it, all that time I wasted..
Gracias, mil gracias!
Thank you. Saved me a ton of time, too.
This is such a usability flaw… It’s a nice idea for avoiding accidents, but really unintuitive.
Thanks for the post.
Awesome, thank you really thank you! It was driving me really crazy this little detail. But helped me to understand better the way of encryption.
Didn’t work for me, still got that error message, and I DID type YES!!@
OMG! so many times reinstallation, and been through so many different articles … just couldnt get the Passphrase prompt! and then it was cause of “uppercase” YES …. spank me hard! sorry.. had to say it…