Skip to content

Instantly share code, notes, and snippets.

@hugohil
Last active February 1, 2023 14:51
Show Gist options
  • Save hugohil/be331667771b1d369f69f47db33ab35f to your computer and use it in GitHub Desktop.
Save hugohil/be331667771b1d369f69f47db33ab35f to your computer and use it in GitHub Desktop.
rename raspberry at next boot

create a file name nextboot.sh

#!/bin/bash

basename="nextboot"

uuid=$(cat /proc/sys/kernel/random/uuid)
echo $uuid

echo "renaming $HOSTNAME to $basename-$uuid"

sudo sed -i "s/$HOSTNAME/$basename-$uuid/" /etc/hosts /etc/hostname

sudo rm $0

sudo reboot

chmod +x nextboot.sh

sudo cp nextboot.sh /opt

sudo vim /etc/rc.local

add the following before exit 0. make sure the path to your program is right.

if test -f "/opt/nextboot.sh"; then
  /opt/nextboot.sh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment