Advertisement
plirof2

Change UUIDs of all partitions

Jun 23rd, 2024 (edited)
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. UUID
  2.  
  3.  
  4. #!/bin/bash
  5.  
  6. # Get the device name of the disk
  7. #read -p "Enter the device name of the disk (e.g. /dev/sda): " disk
  8. disk='/dev/sdX'
  9. # Generate new UUIDs for all partitions on the disk
  10. partitions=($(lsblk -no NAME $disk | grep -v '^$'))
  11. for part in "${partitions[@]}"
  12. do
  13.     new_uuid=$(uuidgen)
  14.     tune2fs -U $new_uuid $disk$part
  15. done
  16.  
  17. echo "UUIDs changed successfully for all partitions on $disk"
  18.  
  19.  
  20. --------------------------
  21. To change the UUID of the source disk in Linux, you can use the tune2fs command. Here's how you can do it:
  22.  
  23. First, make sure the source disk is unmounted. You can check if it's mounted by using the mount command.
  24.  
  25. Find out the device name of the source disk. You can use the lsblk command to list all block devices and their attributes.
  26.  
  27. Once you have the device name (e.g. /dev/sda1), you can use the tune2fs command to change the UUID. Run the following command, replacing /dev/sda1 with your device name:
  28.  
  29.  
  30. sudo tune2fs -U random /dev/sda1
  31. This will generate a new random UUID for the source disk. You can also specify a specific UUID by replacing random with the desired UUID in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.
  32.  
  33. Once the command has executed successfully, you can remount the source disk and verify that the UUID has been changed by running the blkid command.
  34. By following these steps, you can change the UUID of the source disk in Linux after cloning it using dd.
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement