Linux – UUID and Drive Cloning

linuxmountpartitioningusbuuid

I have a project that I am working on, which involves a USB Storage Device and a boo.table version of linux. The way this project is coming together, I am having multiple partitions on the USB drive that need to be mounted at boot in order for proper resources to load.

My plan is to add the entries to the fstab using their UUID, however, I am not sure if this will work for my end goal. I currently have them mount by their label, but if a label is changed, the system fails to boot.

Eventually, when completed, this image will be cloned, and used to image a number of other USB devices.

My questions are these, when cloning a drive (using dd), will the UUID's for each partition change? Are they hardware specific? or does cloning it keep the same UUID as well? What happen if a system detected two devices with the same UUID?

Best Answer

UUIDs are not hardware-specific but stored in the partition's filesystem. That means cloning a disk or partition with dd will result in the same UUID.

You can assign a new UUID by using:

  • tune2fs -U random <device> (ext2/ext3/ext4)
  • xfs_admin -U generate <device> (xfs)
  • reiserfstune -u $(uuidgen) <device> (reiserfs)
  • mkswap -U $(uuidgen) <device> (swap)

Having duplicated UUIDs doesn't necessarily lead to errors. However booting and mounting a device by UUID will become ambiguous and may lead to the wrong device being used.

Related Question