RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 4:31 am

The latest Raspbian images (2019-09-26) create all SD cards and USB devices with the same PTUUID/PARTUUID:
2019-09-26 Raspbian Image PTUUID

The attached set-ptuuid script can be used to change the PTUUID/PARTUUID on an SD card or a USB device. /boot/cmdline.txt and /etc/fstab will be adjusted in the process.

Usage:

set-ptuuid device [ ptuuid | random ]

where:

device = /dev/sdX or /dev/mmcblk0
ptuuid = 8-hex-digits or random

If no ptuuid is given, the current PTUUID is displayed. If the word 'random' is given, a random PTUUID will be generated.
Attachments
set-ptuuid.zip
(1.14 KiB) Downloaded 130 times
Last edited by RonR on Sat Oct 05, 2019 10:19 pm, edited 1 time in total.

User avatar
DougieLawson
Posts: 36177
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 11:05 am

Why did you post your script as a *.ZIP attachment rather than in [CODE]...[/CODE] tags?

Most folks, if they have any understanding of internet security, won't download a random ZIP file.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 5:15 pm

Is there a sale on tinfoil today?

Andyroo

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 5:29 pm

RonR wrote:
Sat Oct 05, 2019 5:15 pm
Is there a sale on tinfoil today?
Nope - he is right - put it on Github :D

Anyone daft enough to download random files gets what they deserve (no disrespect but this is AV 101).

Especially when Apple has decided that the DEFAULT is to open 'safe' files - PDF based attacks went up...

RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 5:36 pm

I'm confident the moderators will remove it if there is anything remotely suspicious about it.

User avatar
davidcoton
Posts: 4153
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 7:11 pm

RonR wrote:
Sat Oct 05, 2019 5:36 pm
I'm confident the moderators will remove it if there is anything remotely suspicious about it.
What makes you think that volunteer moderators have time to check every potentially malicious attachment posted here?

If people get used to innocent (and useful) code like yours being posted in zip files, they are less likely to spot the rogue before it does damage.

Given that either Github or Code tags give a transparent and easy way to avoid any issues and keep the whole community a little safer, users are entirely justified in not downloading zip files or (for that matter) links to random executable images.
Signature retired

User avatar
DougieLawson
Posts: 36177
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 7:17 pm

RonR wrote:
Sat Oct 05, 2019 5:15 pm
Is there a sale on tinfoil today?
I use a whole roll of Costco's aluminium foil every week. That's essential equipment as a peripatetic penetration tester and security auditor. You never know what bad things are going to infect your sandwiches with salmonella.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 8:19 pm

davidcoton wrote:
Sat Oct 05, 2019 7:11 pm
If people get used to innocent (and useful) code like yours being posted in zip files...

Thank you for the vote of confidence. Hopefully, that will allay anyone's fear of downloading my ZIP files.

User avatar
davidcoton
Posts: 4153
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 8:50 pm

RonR wrote:
Sat Oct 05, 2019 8:19 pm
davidcoton wrote:
Sat Oct 05, 2019 7:11 pm
If people get used to innocent (and useful) code like yours being posted in zip files...

Thank you for the vote of confidence. Hopefully, that will allay anyone's fear of downloading my ZIP files.
That was not my intention. I would prefer you to make useful code useable by following sensible practices so people can download without fear.
Signature retired

RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 05, 2019 8:59 pm

davidcoton wrote:
Sat Oct 05, 2019 8:50 pm
I would prefer you to make useful code useable by following sensible practices so people can download without fear.

If you wish to debate posting and attachment practices, I would prefer you started a new topic in the appropriate forum.

This topic is entitled "Change PTUUID/PARTUUID on an SD card or a USB device".

Thank you.

Milliways
Posts: 456
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sun Oct 06, 2019 4:52 am

If anyone is interested the below is a safe script I have been using for years to change PTUUID on a cloned SD Card.
(The original was posted on this site; I have modified to generate PTUUID)

Code: Select all

#!/bin/bash

errexit()
{
  echo ""
  echo "$1"
  echo ""
  exit 1
}

usage()
{
  errexit "Usage: $0 [-n | diskid]"
}

if [ $(id -u) -ne 0 ]; then
  errexit "$0 must be run as root user"
fi

PTUUID="$1"
if [ "${PTUUID}" = "" ]; then
  usage
fi
if [ "${PTUUID}" = "-n" ]; then
  echo ${PTUUID} 
  PTUUID=$(uuid | cut -c-8)
fi
PTUUID="$(tr [A-Z] [a-z] <<< "${PTUUID}")"
if [[ ! "${PTUUID}" =~ ^[[:xdigit:]]{8}$ ]]; then
  errexit "Invalid DiskID: ${PTUUID}"
fi
echo ""
echo -n "Set DiskID to ${PTUUID} on /dev/mmcblk0 (y/n)? "
while read -r -n 1 -s answer; do
  if [[ "${answer}" = [yYnN] ]]; then
    echo "${answer}"
    if [[ "${answer}" = [yY] ]]; then
      break
    else
      errexit "Aborted"
    fi
  fi
done
echo ""
fdisk /dev/mmcblk0 <<EOF > /dev/null
p
x
i
0x${PTUUID}
r
p
w
EOF
sync
PARTUUID="$(sed -n 's|^.*PARTUUID=\(\S\+\)\s.*|\1|p' /boot/cmdline.txt)"
if [ "${PARTUUID}" != "" ]; then
  sed -i "s|PARTUUID=\S\+\s|PARTUUID=${PTUUID}-02 |" /boot/cmdline.txt
  sed -i "s|${PARTUUID:0:(${#PARTUUID} - 1)}|${PTUUID}-0|" /etc/fstab
fi
sync

RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sun Oct 06, 2019 5:36 am

Milliways wrote:
Sun Oct 06, 2019 4:52 am
If anyone is interested the below is a safe script I have been using for years to change PTUUID on a cloned SD Card.
(The original was posted on this site; I have modified to generate PTUUID)

I posted that a couple years ago (in response to your request: How to change Disk identifier). It's the predecessor to the set-ptuuid script in the first post of this topic. It's inferior to the new one posted in this topic and doesn't handle several special cases, including the duplicate PTUUID/PARTUUID problem introduced in the latest Raspbian images (2019-09-26). I highly recommend using the new one in the first post of this topic.

Milliways
Posts: 456
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sun Oct 06, 2019 7:03 am

RonR wrote:
Sun Oct 06, 2019 5:36 am
Milliways wrote:
Sun Oct 06, 2019 4:52 am
If anyone is interested the below is a safe script I have been using for years to change PTUUID on a cloned SD Card.
(The original was posted on this site; I have modified to generate PTUUID)

I posted that a couple years ago (in response to your request: How to change Disk identifier). It's the predecessor to the set-ptuuid script in the first post of this topic. It's inferior to the new one posted in this topic and doesn't handle several special cases, including the duplicate PTUUID/PARTUUID problem introduced in the latest Raspbian images (2019-09-26). I highly recommend using the new one in the first post of this topic.
Ron,

I find your scripts useful (if undocumented and uncommented), I don't know what the "several special cases" may be; I don't understand "the duplicate PTUUID/PARTUUID problem" and have always set a PARTUUID when I clone an image (I don't anticipate downloading an new image until Bullseye is released).

While I don't share the concerns about zip files expressed above I never run downloaded scripts until I have analysed them, and the script I listed meets my needs of setting PARTUUID on a running image on a SD Card.

My request was to see if there existed a script, rather than re-inventing the wheel, as my manual process was becoming tedious.
I was surprised that the Foundation hadn't anticipated the need and supplied a script.

RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sun Oct 06, 2019 7:53 am

Milliways wrote:
Sun Oct 06, 2019 7:03 am
While I don't share the concerns about zip files expressed above I never run downloaded scripts until I have analysed them, and the script I listed meets my needs of setting PARTUUID on a running image on a SD Card.

Once you've had a chance to analyze the new version, I'm confident you'll find it has a number of improvements over the old one from two years ago:

1. Addresses arbitrary devices (SD card or any USB device), not just the current root system.

2. Does not affect commented lines in cmdline.txt and fstab.

3. Does a 'fix-up' of cmdline.txt on systems running from USB devices which boot via the SD card so they still boot properly.

If you don't need or want these improvements, that's fine, but I don't recommend others use the older version.

HeadHunter
Posts: 1
Joined: Sat Oct 12, 2019 2:46 pm

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 12, 2019 2:47 pm

Sry but with the script i get a permission denied. Can you help me?
I have root acces

Thx

RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Sat Oct 12, 2019 5:49 pm

HeadHunter wrote:
Sat Oct 12, 2019 2:47 pm
Sry but with the script i get a permission denied. Can you help me?
I have root acces

Did you make the script executable?:

Code: Select all

chmod +x set-ptuuid

bellibelson
Posts: 1
Joined: Sat May 11, 2019 4:24 pm

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Mon Oct 14, 2019 9:44 pm

Hallo,
I needed some time to get this script to work because I had to find out how these scripts are called up exactly. I am a beginner with linux.
Now it works. But actually I am trying to run the raspberry pi 4 from SSD. Im am working on that now 4 days. After changing the partuuid for the sd card and changing the cmdline.txt the raspberry would not start any more. Also the boot folder on sd card and ssd are empty.
I have tried these 3 tutorials but none of them works:
https://www.stewright.me/2019/10/run-ra ... erry-pi-4/
https://www.tomshardware.com/news/boot- ... 39782.html
https://jamesachambers.com/raspberry-pi ... sh-drives/

Has anybody got a hint for me why the boot folders get deleted after changing partuuid and cmdline.txt?

RonR
Posts: 520
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Change PTUUID/PARTUUID on an SD card or a USB device

Tue Oct 15, 2019 5:12 pm

bellibelson wrote:
Mon Oct 14, 2019 9:44 pm
But actually I am trying to run the raspberry pi 4 from SSD. Im am working on that now 4 days. After changing the partuuid for the sd card and changing the cmdline.txt the raspberry would not start any more.

usb-boot (Running Raspbian from USB Devices : Made Easy) will take care of the PTUUID/PARTUUID probem at the same time it makes your SSD boot properly.

Return to “Advanced users”