Results 1 to 10 of 16

Thread: Changing the UUID of a FAT32 or NTFS Partition

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Location
    東京
    Beans
    168
    Distro
    Xubuntu Development Release

    Arrow Changing the UUID of a FAT32 or NTFS Partition

    I'm used to finding the answers to all my technical questions with a couple of 'net searches but information in this area seems a bit scarce.

    The typical scenario is that a partition has been backed up using a cloning tool like parted, then various problems appear due to the duplicated UUID. The accepted solution is to alter the volume label on the backup partition using mlabel [mtools] and then edit /etc/fstab to have the backup partition identified using LABEL="WinWhatever" instead of UUID=89C9589FC4162F5. That's not necessarily the end of the story though. A live CD or reinstaller will again trip over the duplicate UUID.

    A more robust solution is to alter the UUID on the backup partition and create a record of the original UUID at the same time, in case the master partition crashes and is unrecoverable. First let's see what we've got:-
    Code:
    sudo blkid
    Make a note of the partition number X of the backup partition. Use that number instead of X in all the comands below.

    Now let's grab the superblock:-
    Code:
    sudo dd if=/dev/sdaX of=~/superblockX bs=512 count=1
    And edit it using hexeditor [ncurses-hexedit]:-
    Code:
    sudo hexeditor ~/superblockX
    The UUID shown by blkid earlier will match the volume serial number which you should see at 0x43-0x46 for VFAT or 0x48-0x4f for NTFS. Change it somehow and save.

    [Optional sanity check: "ls -l ~/superblockX" The file should still be exactly 512 bytes].

    Copy the modified file back to the superblock. I don't need to mention how risky this part is. Be sure you know what you're doing.
    Code:
    sudo dd if=~/superblockX of=/dev/sdaX bs=512 count=1
    Next edit /etc/fstab with a line identifying the backup partition via its new UUID. You might want to add noauto to the options if you don't want it mounted automatically all the time. Finally, I suggest mounting the backup partition and adding a tag file to its root directory. The file name should indicate the original UUID prior to editing, eg. 540C-0199.vol, as this will be needed if the master partition ever crashes catastrophically or needs to be restored.

    I hope this process will all be automated one day. See this bug report.

    Please post back if you spot errors or if there are just better ways to do the above. I haven't tested this on an NTFS partition yet.

    References:
    How FAT32 volume serial numbers are calculated.
    Some info on NTFS.
    Last edited by clubsoda; August 16th, 2009 at 07:00 PM.
    This item has not yet been configured

  2. #2
    Join Date
    Mar 2006
    Beans
    194

    Re: Changing the UUID of a FAT32 or NTFS Partition

    Thank you for this very useful howto.

    I also have partition with xfs, ext3, can I use the same solution as this one. is there any other thing need to make change?

    Anyway this is a good solution.

  3. #3
    Join Date
    Nov 2006
    Location
    東京
    Beans
    168
    Distro
    Xubuntu Development Release

    Re: Changing the UUID of a FAT32 or NTFS Partition

    I'm sure you could use this method on xfs or ext3 if you're feeling adventurous. Thankfully, those file systems are better supported so no need for open-block surgery. Have a look at xfs_admin [xfstools] and tune2fs.
    This item has not yet been configured

  4. #4
    Join Date
    Feb 2005
    Location
    Melbourne, Australia
    Beans
    13,503
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Changing the UUID of a FAT32 or NTFS Partition

    This should patch the NTFS UUID with 8 random bytes (substitute the obvious with your actual NTFS partition designation, and all those spaces are required):

    Code:
    sudo dd if=/dev/urandom bs=80 count=1 | xxd -l 80 -c 8 | tail -1 | xxd -r - /dev/sd-NTFS-Partition
    Regards, David.
    Please use the Forum search and Wiki search for immediate help
    Please mark your thread as Solved when appropriate.
    New to technical forums?: How To Ask Questions The Smart Way

  5. #5
    Join Date
    Apr 2010
    Beans
    78

    Re: Changing the UUID of a FAT32 or NTFS Partition

    Quote Originally Posted by dcstar View Post
    This should patch the NTFS UUID with 8 random bytes (substitute the obvious with your actual NTFS partition designation, and all those spaces are required):

    Code:
    sudo dd if=/dev/urandom bs=80 count=1 | xxd -l 80 -c 8 | tail -1 | xxd -r - /dev/sd-NTFS-Partition
    Can you clarify the code for me please? Ones ( 1 ) and L's ( l ) can look very similar.

    Also, could you clarify the ".... sd-NTFS-Partition" part? is that supposed to be:
    ".... sdx-NTFS-Partition" where 'x' is the partition you'd like the uuid change on?

    Are there any other parts of the code that we should be inserting the 'appropriate' value that is currently holding an 'x' place holder (ie the xxd part of the code)?

    Thanks again for the help

  6. #6
    Join Date
    Apr 2010
    Beans
    78

    Re: Changing the UUID of a FAT32 or NTFS Partition

    Ok, I gave this a try from a Live CD 10.04.1 LTS

    I imaged a windows 7 OS to the first and 2nd partition of the hard drive and checked that they both have the same UUID by typing in ===> sudo blkid

    I assumed that:
    the count=1 was a "One"
    --- and that the xxd -l was an "L"
    --- and that the /dev/sd-NTFS-Partition was supposed to be .... /dev/sda1-NTFS-Partition (assuming that it was the 1st partition on the drive that I was trying to change the UUID on.

    When I ran it I got this message:
    xxd: /dev/sda1-NTFS-Partition: Permission denied
    1+0 records in
    1+0 records out
    80 bytes (80 B) copied, 0.000107521 s, 744 kB/s


    Does anyone here have a suggestion as to how to make this work as it would be VERY VERY handy to be able to change the UUID with a single line like this!

  7. #7
    Join Date
    Sep 2008
    Beans
    41
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Changing the UUID of a FAT32 or NTFS Partition

    Quote Originally Posted by dcstar View Post
    This should patch the NTFS UUID with 8 random bytes (substitute the obvious with your actual NTFS partition designation, and all those spaces are required):

    Code:
    sudo dd if=/dev/urandom bs=80 count=1 | xxd -l 80 -c 8 | tail -1 | xxd -r - /dev/sd-NTFS-Partition
    This works great. Thanks.

  8. #8
    Join Date
    Sep 2011
    Beans
    1

    Re: Changing the UUID of a FAT32 or NTFS Partition

    Thank you! It worked perfectly for me on ubuntu 11.04
    -strudel

  9. #9
    Join Date
    May 2012
    Beans
    1

    Re: Changing the UUID of a FAT32 or NTFS Partition

    I wrote a script to automate this process for NTFS partitions and to avoid overwriting anything that isn't NTFS (or at least reduce the risks). I'm sure one could modify it to work with FAT as well, but it's a starting point.

    Code:
    #!/bin/dash
    IFS=""
    
    # echo with exit for error termination
    exho(){
        echo "error: $1"
        exit 1
    }
    
    # convert hexidecimal UUID to binary characters
    uuid2bin(){
        STBF="$1"
        while [ -n "$STBF" ]; do
            BYTE="${STBF%??}"
            BYTE="${STBF#$BYTE}"
            STBF="${STBF%$BYTE}"
            BYTE="$(printf "%u\n" "0x$BYTE")"
            echo -n "$BYTE" | awk '{printf("%c",$0)}'
        done
        return 0
    }
    
    # usage help
    if [ $# != 2 ]; then
        echo "$0 <UUID> <device>"
        exit 1
    fi
    
    # test the input UUID for validity
    UUID_NEW="$(echo -n "$1" | tr [a-f] [A-F])"
    STBF="${UUID_NEW#[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]}"
    if [ -n "$STBF" ]; then
        exho "invalid UUID format"
    fi
    if [ "$UUID_NEW" = 0000000000000000 ]; then
        exho "UUID cannot be empty"
    fi
    
    # get current/old UUID value via system tool
    UUID_OLD="$(blkid -c /dev/null -s UUID -o value "$2" 2>/dev/null)"
    if [ -z "$UUID_OLD" ]; then
        exho "could not read old UUID using blkid on $2"
    fi
    
    # get current/old UUID value via raw read
    STBF="$(dd bs=1 skip=72 count=8 if="$2" 2>/dev/null | hexdump -ve '1/1  "%02X"')"
    if [ ${#STBF} != 16 ]; then
        exho "could not read old UUID using dd on $2"
    fi
    
    # reorder the hex digits since they are reversed
    UUID_RAW=""
    while [ -n "$STBF" ]; do
        BYTE="${STBF%??}"
        BYTE="${STBF#$BYTE}"
        STBF="${STBF%$BYTE}"
        UUID_RAW="$UUID_RAW$BYTE"
    done
    
    # matching UUIDs confirm NTFS structure
    if [ "X$UUID_RAW" != "X$UUID_OLD" ]; then
        exho "$2 invalid NTFS device"
    fi
    
    # write UUID to device
    if ! uuid2bin "$UUID_NEW" | dd bs=1 seek=72 count=8 of="$2" 2>/dev/null && sync; then
        exho "could not write UUID to $2"
    fi
    
    # verify UUID
    UUID_RAW="$(blkid -c /dev/null -s UUID -o value "$2" 2>/dev/null)"
    if [ "X$UUID_RAW" != "X$UUID_NEW" ]; then
        exho "verification of new UUID failed"
    fi
    
    # status information
    echo "DEVICE:\t\t$2"
    echo "OLD UUID:\t$UUID_OLD"
    echo "NEW UUID:\t$UUID_NEW"

  10. #10
    Join Date
    Apr 2010
    Beans
    78

    Re: Changing the UUID of a FAT32 or NTFS Partition

    I have used this many times now and it works perfectly:
    http://ubuntuforums.org/showpost.php...8&postcount=10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •