From ced836e69274af905bbc1e5f5fde71de4066c86c Mon Sep 17 00:00:00 2001 From: Nicolas Bock Date: Thu, 22 Apr 2021 12:22:54 -0600 Subject: Use `partprobe` to re-read partition table if available (#856) The blkdev command is fragile re-reading partition tables if a partition is mounted. This change instead uses the partprobe if it is available. LP: #1920939 --- cloudinit/config/cc_disk_setup.py | 13 +++++++++---- tools/.github-cla-signers | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py index d1200694..a582924b 100644 --- a/cloudinit/config/cc_disk_setup.py +++ b/cloudinit/config/cc_disk_setup.py @@ -113,6 +113,7 @@ SGDISK_CMD = subp.which("sgdisk") LSBLK_CMD = subp.which("lsblk") BLKID_CMD = subp.which("blkid") BLKDEV_CMD = subp.which("blockdev") +PARTPROBE_CMD = subp.which("partprobe") WIPEFS_CMD = subp.which("wipefs") LANG_C_ENV = {'LANG': 'C'} @@ -685,13 +686,17 @@ def get_partition_layout(table_type, size, layout): def read_parttbl(device): """ - Use partprobe instead of 'udevadm'. Partprobe is the only - reliable way to probe the partition table. + Use `partprobe` or `blkdev` instead of `udevadm`. `Partprobe` is + preferred over `blkdev` since it is more reliably able to probe + the partition table. """ - blkdev_cmd = [BLKDEV_CMD, '--rereadpt', device] + if PARTPROBE_CMD is not None: + probe_cmd = [PARTPROBE_CMD, device] + else: + probe_cmd = [BLKDEV_CMD, '--rereadpt', device] util.udevadm_settle() try: - subp.subp(blkdev_cmd) + subp.subp(probe_cmd) except Exception as e: util.logexc(LOG, "Failed reading the partition table %s" % e) diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers index d6212d1d..38e1ad74 100644 --- a/tools/.github-cla-signers +++ b/tools/.github-cla-signers @@ -31,6 +31,7 @@ manuelisimo marlluslustosa matthewruffell mitechie +nicolasbock nishigori olivierlemasle omBratteng -- cgit v1.2.3