summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcin Niestroj <m.niestroj@grinn-global.com>2019-06-26 09:38:35 +0200
committerMarcin Niestroj <m.niestroj@grinn-global.com>2019-08-05 21:13:46 +0200
commitdd20bcfd78ffb2c6bb5ceed6a474cb2830d240c0 (patch)
tree136fb456d7d44371ac4361577f74c3ddbc448cbe
parentfe10a25f2e22b2f6461bb1736651dd2d81b3db44 (diff)
downloadgenimage-dd20bcfd78ffb2c6bb5ceed6a474cb2830d240c0.tar.gz
genimage-dd20bcfd78ffb2c6bb5ceed6a474cb2830d240c0.tar.xz
hdimage: use random mbr disk signature if not provided
Disk signature is part of PARTUUID for MBR partitions. PARTUUID can be used to provide root partition, instead of hardcoding /dev/sd* or /dev/mmcblk* nodes. The advantage of using PARTUUID is that it doesn't change across reboots (depending on device drivers probe order). Add a possibility to use random value as disk signature, which will be used after specifying 'disk-signature = random'. Using it will make it less likely to have multiple SD cards with the same PARTUUIDs connected to a single system, resulting in PARTUUID conflict. Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
-rw-r--r--image-hd.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/image-hd.c b/image-hd.c
index 204d601..93f29e2 100644
--- a/image-hd.c
+++ b/image-hd.c
@@ -416,12 +416,13 @@ static int hdimage_setup(struct image *image, cfg_t *cfg)
int has_extended, autoresize = 0;
unsigned int partition_table_entries = 0;
unsigned long long now = 0;
+ const char *disk_signature;
struct hdimage *hd = xzalloc(sizeof(*hd));
hd->align = cfg_getint_suffix(cfg, "align");
hd->partition_table = cfg_getbool(cfg, "partition-table");
hd->extended_partition = cfg_getint(cfg, "extended-partition");
- hd->disksig = strtoul(cfg_getstr(cfg, "disk-signature"), NULL, 0);
+ disk_signature = cfg_getstr(cfg, "disk-signature");
hd->gpt = cfg_getbool(cfg, "gpt");
hd->fill = cfg_getbool(cfg, "fill");
hd->disk_uuid = cfg_getstr(cfg, "disk-uuid");
@@ -456,6 +457,11 @@ static int hdimage_setup(struct image *image, cfg_t *cfg)
hd->disk_uuid = uuid_random();
}
+ if (!strcmp(disk_signature, "random"))
+ hd->disksig = random();
+ else
+ hd->disksig = strtoul(disk_signature, NULL, 0);
+
partition_table_entries = 0;
list_for_each_entry(part, &image->partitions, list) {
if (autoresize) {