bug#35714: Parted destroys mbr_signature (Disk Identifier) when adding MBR bootcode

Matthijs Kooijman <[email protected]> Mon, 13 May 2019 16:30:32 +0200
Newsgroups gmane.comp.gnu.parted.bugs
Message-ID <[email protected]>
Hi folks,

one more addition: Below is an example of reproducing this problem on an
Ubuntu Disco system running parted 3.2-25. I haven't tried git master,
but looking at the code, I'm pretty sure the problem stil exists there.

Gr.

Matthijs


# Use fdisk to create an empty partition table without any boot code
matthijs@grubby:~$ truncate -s 8M tmp.img
matthijs@grubby:~$ echo -e 'o\nw' | fdisk tmp.img

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x0298967f.

Command (m for help): Created a new DOS disklabel with disk identifier 0x94bfb6ca.

Command (m for help): The partition table has been altered.
Syncing disks.

matthijs@grubby:~$ fdisk -l tmp.img | grep identifier
Disk identifier: 0x94bfb6ca
matthijs@grubby:~$ head -c 512 tmp.img | hd
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  ca b6 bf 94 00 00 00 00  |................|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200


# Then use parted to add a partition
matthijs@grubby:~$ parted tmp.img mkpart p fat32 4096s 8191s
/sys/firmware/dmi/tables/smbios_entry_point: Permission denied
/dev/mem: Permission denied
WARNING: You are not superuser.  Watch out for permissions.

# This has changed the disk identifier (and added bootcode)
matthijs@grubby:~$ fdisk -l tmp.img | grep identifier
Disk identifier: 0x5d7de418
matthijs@grubby:~$ head -c 512 tmp.img | hd
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  18 e4 7d 5d 00 00 00 00  |..........}]....|
000001c0  01 20 0c 03 20 3f 00 10  00 00 00 10 00 00 00 00  |. .. ?..........|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEMyF3AetYrDfGJ9el6ZMxy91tJYwFAlzZf4QACgkQ6ZMxy91t
JYzLPhAAinbPImRnYrVU5pKQj9s/XFwJpechcb4KtTklFzdKO8+EAz1/JqLcotCp
kpnpWYPd6k+UXD5fom4rDDJ0PHUVfT8F+XmJIEwcWBfA8BXTz+OypZrvZFb+zAdy
huAzMsbuW9JDn8XmfjJgel3F7c92PgMZJJrVUxzcQG1L8+eSEriUw7Zs6otuFHms
GKEmVscx5k4eLgWJoZFj48XPzIITDw1InbUjSftMihNgaVsgzUwfgV2jmL1mr4oe
Lvru11Cccx45rwmu3yyZYHgAI21ZYNzU92kKjrSkjLNOZ3bhOJdM6q0zP+PrYJjf
F4BhTQ7F/Vc/pz+WT8mKsycNfZFgB0DfZiRjRIgwvs2tHopJfTT+pL8F3cPq6Hz4
UhOQgYQ1SWXQjtEioe0YksA2q1z1uWeMIIBm0rzspq3ud+rn9+SSU9NU7jF0ZBN6
1zV9mj6ggkGzRVbr0I/EGrqbNNccoRhn0PgCfMmNyT0DbC3IN1dT9u2TlK5GkhA/
2do/i/OcsX8VOg1nIp2p6cX2+tf9aXVCNoluOMnspM6aehwHrXii+4YXF3VhT+kz
DLG9vTO26guOLxEVO28TbFr121t9KdQBAjC7u2VgvJXSEl3YODKjtyX4yGl56nku
9OsJA2K4P6XAEACW/v/pltNsfCDpn9zqQKQXmfiVrbW3+vdLIDw=
=31ft
-----END PGP SIGNATURE-----