2

I noticed that no matter which microSD card I burn the Raspbian image onto, its "identifier" is always 7ee80803. This appears counter-intuitive to be because "disk identifier" is something written in the hardware and is not supposed to be writable. Even if the volume ID of a partition is customizable during formatting or creation of the volume, the option PARTUUID=7ee80803-02 reads like "2nd partition of disk 7ee80803", which indicates that 7ee80803 isn't the identifier of a partition, but the disk.

Why is that?

2 Answers 2

2

When you copy an IMAGE you get an EXACT copy of the image, including the boot sector which contains the partition table and the Label or Disk identifier.

sudo fdisk -l /dev/mmcblk0 will show Disk identifier, as would a mounted copy of the image.

It is a simple task to change it; indeed the SD Copier utility has an option to do this.

The following is a script to change it.

#!/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
2

Just wanted to add on to Milliways' response.

On first boot of Raspbian, there is an auto expansion task that is run. Within that task, it updates the disk id.

fix_partuuid() {
  DISKID="$(fdisk -l "$ROOT_DEV" | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p')"

  sed -i "s/${OLD_DISKID}/${DISKID}/g" /etc/fstab
  sed -i "s/${OLD_DISKID}/${DISKID}/" /boot/cmdline.txt
}

Found out about this when I was trying to disable the auto expansion on boot. So unless you're disabling the auto expansion, it should update with the right disk ids automatically.

This is assuming you're using Raspbian from the Raspberry Pi Foundation, not sure if any the other images contain this script.

References:

Forum post referencing the init_resize.sh script

raspi-config resize script on GitHub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.