• Home
  • About
  • Contact
  • Store

IT from Scratch

Small Business IT from the ground up

Cryptsetup: Command failed with code 22: Invalid argument

August 1, 2013 By The New Guy 17 Comments

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.

Filed Under: Scratch

Comments

  1. ste says

    January 17, 2014 at 12:24 pm

    You saved my day, I was going crazy, thanks.

    Reply
  2. Kuro says

    August 29, 2015 at 12:35 pm

    Haha, i am such an idiot! Thank you for this helpful post 🙂

    Reply
  3. XiR_ says

    January 22, 2016 at 3:56 am

    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.

    Reply
  4. Mercure says

    February 3, 2016 at 1:29 pm

    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” =)

    Reply
  5. Folatt says

    March 6, 2016 at 2:51 pm

    Looks like someone fails to read the instructions carefully for this every year.

    – Guilty person of 2016 –

    Reply
  6. dastos says

    March 13, 2016 at 1:22 am

    Thank 8)

    Reply
  7. Dácccs says

    March 15, 2016 at 11:14 am

    I fight with this more than a hour, and not this was the first situation to meet wit this uppercase letters problem.

    Reply
  8. Hal says

    May 14, 2016 at 4:25 pm

    I feel so idiotic. Thanks for this after hours of pulling my hair out.

    Reply
  9. Daniel says

    May 15, 2016 at 10:14 am

    Yes! I make the same mistake. Just for not follow the instructions.
    I’m feel idiot now. But thanks.

    Reply
  10. David says

    September 29, 2016 at 7:32 am

    Same here, wish the error message was better, I was also checking and testing arguments to see what I had missed.

    Reply
  11. topsnek22 says

    December 15, 2016 at 6:47 am

    God damn it, all that time I wasted..

    Reply
  12. Diego says

    March 3, 2017 at 8:47 am

    Gracias, mil gracias!

    Reply
  13. Jack Zelig says

    July 4, 2017 at 2:38 am

    Thank you. Saved me a ton of time, too.

    Reply
  14. Chris says

    August 20, 2017 at 10:47 am

    This is such a usability flaw… It’s a nice idea for avoiding accidents, but really unintuitive.

    Thanks for the post.

    Reply
  15. Hugo Montoya says

    January 18, 2018 at 9:55 am

    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.

    Reply
  16. gahhh says

    January 27, 2018 at 7:29 am

    Didn’t work for me, still got that error message, and I DID type YES!!@

    Reply
  17. Usman says

    September 14, 2018 at 10:06 am

    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…

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Click Here for 500 MB free VPN connection through Private Tunnel

Recent Posts

  • How to Get the macOS Catalina Installer, Post Big Sur
  • Mac: How to Get SHA1 Hash
  • iTunes error: “You do not have enough access privileges for this operation”
  • Is Websense Filtering My Internet Traffic?
  • How to Delete a Mac VPN Profile
  • Home
  • About
  • Contact
  • Store

Copyright © 2025 ·WP-Ubuntu