Skip to content

Instantly share code, notes, and snippets.

@dllud
Created July 15, 2022 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dllud/0820d53477bce57b7f29d7b8f7761268 to your computer and use it in GitHub Desktop.
Save dllud/0820d53477bce57b7f29d7b8f7761268 to your computer and use it in GitHub Desktop.
How to change a cloned GNU/Linux machine's identity

How to change a cloned GNU/Linux machine's identity

You've just finished installing and configuring all those packages on your first machine. Now it's just a matter of cloning the hard drive into all the others and changing the hostname. Right?

Well, not so easy. If you wish to avoid conflicts on your network, backups and elsewhere, i.e. if you wanna end up with a unique fingerprint for each machine, you must go a few steps further.

Here follows a checklist to help you out. It's aimed at Debian and derivates (e.g. Ubuntu), though other distros won't be much different.

The old way: edit /etc/hostname and /etc/hosts

The systemd way: hostnamectl set-hostname newhostname

rm -f /etc/machine-id /var/lib/dbus/machine-id
dbus-uuidgen --ensure=/etc/machine-id
dbus-uuidgen --ensure
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
systemctl restart ssh

partition UUID or serial number

tune2fs /dev/sdXN -U random
mlabel -i /dev/sdXN -n
swapoff -a
mkswp /dev/sdXN

Replace the UUID at /etc/initramfs-tools/conf.d/resume with the new swap UUID (check blkid) and run update-initramfs -u

fstab

If you are using UUIDs in /etc/fstab remember to update them.

hdparm

Some goes for /etc/hdparm.conf

GPT partition table

gdisk /dev/sdXN and then an interaction as follows:

Command (? for help): x
Expert command (? for help): c
Partition number (1-3): 1
Enter the partition's new unique GUID ('R' to randomize): R
New GUID is C9C56646-E53D-427C-B905-941DCF2A1CAB

Repeat for all partitions and finally save it:

Expert command (? for help): w
Expert command (? for help): q

MBR partition table

PARTUUID is generated with the Windows Disk Signature (disk identifier) and the partition number. You can change the disk identifier with fdisk /dev/sdXN:

Command (m for help): x
Expert command (m for help): i
Enter the new disk identifier: 0x19ef8aa3
Disk identifier changed from 0x9eff18bb to 0x19ef8aa3.
Expert command (? for help): w
Expert command (? for help): q

fdisk offers no option to generate a random ID, you should make one up yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment