summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Bock <nicolasbock@gmail.com>2021-04-22 12:22:54 -0600
committerGitHub <noreply@github.com>2021-04-22 13:22:54 -0500
commitced836e69274af905bbc1e5f5fde71de4066c86c (patch)
tree3851b97bd6b84604d93354566a04d179614ef061
parentd132356cc361abef2d90d4073438f3ab759d5964 (diff)
downloadcloud-init-git-ced836e69274af905bbc1e5f5fde71de4066c86c.tar.gz
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
-rw-r--r--cloudinit/config/cc_disk_setup.py13
-rw-r--r--tools/.github-cla-signers1
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