Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

According to the cryptsetup changelog (1.2.0):

Allow explicit UUID setting in luksFormat and allow change it later in luksUUID (--uuid parameter).

My problem is that the current Debian stable (squeeze) uses 1.1.3 - Is there a way to change the LUKS UUID if I can not upgrade this version? (Maybe with an other program)?

share|improve this question

migrated from Jul 29 '12 at 19:11

This question came from our site for computer enthusiasts and power users.

Why do you want to change it? – mgorven Jul 29 '12 at 19:30
As part of a backup-restore procedure I would like to re-create a partition which will be in sync with the existing system. (For example crypttab uses the UUID). - I do not want to change crypttab itself as there is no guarantee that it is only used in there. – vbence Jul 30 '12 at 6:56
up vote 1 down vote accepted

The luks format looks pretty simple and is text based so should be easy to manipulate. I wrote this in about 10 minutes that should do it.

Backup your luks headers first!

import sys
import uuid
import re

if __name__ == "__main__":
    haveuuid = False
    val = ""

    f = open(sys.argv[1], "r+")
    if len(sys.argv) > 2:
       if not re.match('[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}', \
          print "Not a valid UUID"
          val = sys.argv[2]
       # Create a new UUID
       val = uuid.uuid1()
    # Be happy this is LUKS
    if == "LUKS":
        # This is the start position of the UUID field.*5)+8, 0)

        print "Not a luks image"

Run it with python /path/to/ /path/to/luks/device Optionally to specify a UUID: python /path/to/ /path/to/luks/device abcdef01-abcd-abcd-abcd-abcdef012345

share|improve this answer
Thanks for the answer. Only one thing is unclear for me how can you pass the desired new UUID for the script (also what does uuid.uuid1 do)? – vbence Aug 4 '12 at 21:53
that generates a new uuid, you never specified you wanted to use a specific uuid. – Matthew Ife Aug 5 '12 at 0:48
I'd like to replicate the --uuid behavior of cryptsetup. This would be part of a backup-restore procedure (as I already mentioned in my first comment). – vbence Aug 5 '12 at 12:31
@vbence I added the ability to specify the uuid you want to write. – Matthew Ife Aug 8 '12 at 21:03
Thanks for the example. I did not realize that the UUID is stored in a textual representation, and I thought your script was missing the conversion part. – vbence Aug 9 '12 at 8:25

I don't know if it works, but you can boot on a liveCD with cryptsetup >= 1.2.0 and change the UUID of your volume.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.