3

I’m writing a script to change the UUID of an NTFS partition (AFAIK, there is none). That means writing 8 bytes from 0x48 to 0x4F (72-79 decimal) of /dev/sdaX (X being the # of my partition).

If I wanted to change it to a random UUID, I could use this:

dd if=/dev/urandom of=/dev/sdaX bs=8 count=1 seek=9 conv=notrunc

Or I could change /dev/urandom to /dev/sdaY to clone the UUID from another partition.

But... what if I want to craft a personalized UUID? I already have it stored (and regex-checked) in a $UUID variable in hexadecimal string format (16 characters), like this:

UUID="2AE2C85D31835048"

I was thinking about this approach:

echo "$UUID" | xxd -r -p | dd of=/dev/sdaX ...

This is just a scratch... I’m not sure about the exact options to make it work. My question is:

  • Is the echo $var | xxd -r | dd really the best approach?
  • What would be the exact command and options to make it work?

As for the answers, I’m also looking for:

  • An explanation of all the options used, and what they do.
  • If possible, an alternative command to test it in a file and/or screen before changing the partition.

I already have an 100-byte dump file called ntfs.bin that I can use for tests and check results using

xxd ntfs.bin

So any solution that provides me a way to check results using xxd in screen so I can compare with original ntfs.bin file would be highly appreciated.

2
  • Just a quick question here, you've tested this dd against your device with success? Your echo ... dd pipeline should work, as it will read stdin should if= not be named. Commented Mar 4, 2011 at 16:13
  • Well, ive tested dd if=/dev/urandom against my ntfs.bin file. It worked fine (ive edited my post to add the conv=notrunc option). But my fear is: /dev/urandom has infinite bytes, and my echo have only 16. When seek is used, does it seek both output AND input? How to specify "read the WHOLE input, but seek ONLY the output" ? Shall i use "seek" or "skip" ? Why? Commented Mar 4, 2011 at 17:32

1 Answer 1

1

Try:

UUID="2AE2C85D31835048"
echo "$UUID" | xxd -r -p | wc -c
echo "$UUID" | xxd -r -p | dd of=file obs=1 oseek=72 conv=block,notrunc cbs=8
Sign up to request clarification or add additional context in comments.

1 Comment

Hi! The 2nd command (wc -c) outputted 8. Whats that for? The last command has error in oseek, but after replacing it to seek, it seemed to work fine in my test files. Care to explain the options and values used? What are they for, and why such values? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.