Bug 15526 - mkdosfs produces identical serial numbers if called in quick succession
Summary: mkdosfs produces identical serial numbers if called in quick succession
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.35.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-07 19:19 UTC by VIAVI_AB
Modified: 2023-04-07 19:19 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
patch (646 bytes, application/octet-stream)
2023-04-07 19:19 UTC, VIAVI_AB
Details

Note You need to log in before you can comment on or make changes to this bug.
Description VIAVI_AB 2023-04-07 19:19:26 UTC
Created attachment 9581 [details]
patch

(vanilla busybox 1.35 source)

I'm using busybox to automate the creation of a virtual machine; part of this requires me to script something like this:

#! /bin/sh
sfdisk --quiet --wipe=always --wipe-partitions=always /dev/sda << EOF
label: dos
1: type=0b, size=500M
2: type=0b, size=500M
3: type=0b, size=500M
4: type=0b, size=500M
EOF
mkdosfs /dev/sda1
mkdosfs /dev/sda2
mkdosfs /dev/sda3
mkdosfs /dev/sda4
lsblk -npr -o NAME,TYPE,UUID /dev/sda

On a "modern" machine, the problem is that without a small (>= 1s) delay between the invocations of mkdosfs, all filesystems end up with the same serial number, which is undesirable (especially if those UUIDs end up in an /etc/fstab).

Attached is a patch for consideration that attempts to use /dev/random first, falling back to the time-based mechanism in case /dev/random isn't accessible.