#!/bin/bash echo "===============================================" echo "UUID manipulater by Kiyoshi SUZUKI at 2011/4/20" echo "===============================================" gksu sleep 0 sudo blkid echo "===============================================" echo "Type the partition device file name the UUID of which you want to modify (for example, sda1)" read a if [ ! -e /dev/$a ];then echo "/dev/$a does not exist. Abort!" exit 0 fi filesystem=$(sudo blkid /dev/$a|sed -e "s/.*TYPE=\"//" -e "s/\".*//") echo "filesystem of /dev/$a is $filesystem" littleendian () { if [ $(expr $(echo $check1|wc -c) % 2) = 0 ];then echo "number of word \"$check1\" is odd. Abort." exit 0 else repeatnum=$(expr $(expr $(echo $check1|wc -c) - 1) / 2 - 1) len=$(expr $(echo $check1|wc -c) - 1) while [ 0 -lt $repeatnum ];do check1="$(echo $check1|cut -c3-$(expr $(expr $repeatnum \* 2) + 2))$(echo $check1|cut -c1-2)$(if [ $(expr $(expr $repeatnum + 1) \* 2) -lt $len ];then echo $check1|cut -c$(expr $(expr $repeatnum \* 2) + 3)-;fi)" repeatnum=$(expr $repeatnum - 1) done fi } modify () { sudo dd if=/dev/$a bs=1 count=$num skip=$skip > test 2>/dev/null check1=$(hd test |head -n 1| sed -e "s/|.*//"|cut -c 9-|tr -d " ") if [ $littleendian = "on" ];then littleendian;fi check2=$(sudo blkid /dev/$a|tr -d "-"|sed -e "s/.*UUID=\"//" -e "s/\".*//") echo $check1 : $check2 : if [ $check1 = $(echo $check2|tr "[A-Z]" "[a-z]") ];then echo "UUID is $check2" echo "Please type what UUID you want to change to" read newuuid newuuid=$(echo "${newuuid}00000000000000000000000000000000"|cut -b1-$(expr $num + $num)) if [ $(echo $newuuid|tr -d "0123456789abcdef") ];then echo "===============================================" echo "UUID must consist of \"0123456789abcdef\" only. Abort." echo "===============================================" exit 0 fi echo "===============================================" echo "Do you want to change UUID of /dev/$a to ${newuuid} ? (Yes:y or No:other)" read b if [ $b = "y" ];then if [ $littleendian = "on" ];then check1=$newuuid littleendian newuuid=$check1 fi echo "${newuuid}y"|hexedit test 2>/dev/null check1=$(hd test|head -n 1| sed -e "s/|.*//"|cut -c 9-|tr -d " ") if [ $littleendian = "on" ];then littleendian;fi echo "===============================================" echo "Please confirm new UUID of /dev/$a is:" echo $check1 echo "Is it OK? (Yes:y, No:other)" read ans if [ $ans = "y" ];then sudo dd if=test bs=1 count=$num of=/dev/$a seek=$skip 2>/dev/null && echo "UUID is modified. \"blkid\" command gives: $(sudo blkid /dev/$a) You should manually update (modify) system settings such as /etc/fstab, /boot/grub/grub.cfg, /etc/initramfs-tools/conf.d/resume and so on." sudo sync exit 0 else echo "If you want to change, type \"y\". Abort." exit 0 fi else echo "If you want to change, type \"y\". Abort." exit 0 fi else echo "Something is wrong. Abort!" exit 0 fi } case $filesystem in ext2|ext3|ext4) echo "Please type what UUID you want to change to" read newuuid newuuid=$(echo $newuuid|tr "[A-Z]" "[a-z]"|tr -d -- -) newuuid=$(echo "${newuuid}00000000000000000000000000000000"|cut -b1-32) if [ $(echo $newuuid|tr -d "0123456789abcdef") ];then echo "===============================================" echo "UUID must consist of \"0123456789abcdef\" only. Abort." echo "===============================================" exit 0 fi echo "===============================================" echo "Do you want to change UUID of /dev/$a to ${newuuid} ? (Yes:y or No:other)" read b if [ $b = "y" ];then sudo tune2fs -U "$(echo $newuuid|cut -c1-8)-$(echo $newuuid|cut -c9-12)-$(echo $newuuid|cut -c13-16)-$(echo $newuuid|cut -c17-20)-$(echo $newuuid|cut -c21-32)" /dev/$a && echo "UUID is modified. \"blkid\" command gives: $(sudo blkid /dev/$a) You should manually update (modify) system settings such as /etc/fstab, /boot/grub/grub.cfg, /etc/initramfs-tools/conf.d/resume and so on." sudo sync exit 0 else echo "If you want to change, type \"y\". Abort." exit 0 fi ;; swap) num=16 skip=1036 littleendian="off" modify ;; ntfs) num=8 skip=72 littleendian="on" modify ;; reiserfs) num=16 skip=65620 littleendian="off" modify ;; btrfs) num=16 skip=65568 littleendian="off" modify ;; vfat) if [ -n "$(sudo blkid /dev/$a|grep msdos)" ];then num=4 skip=39 littleendian="on" modify else num=4 skip=67 littleendian="on" modify fi ;; *) echo "Filesystem type $filesystem is not supported. Abort." exit 0 ;; esac exit 0