summaryrefslogtreecommitdiff
path: root/cloudinit
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 /cloudinit
parentd132356cc361abef2d90d4073438f3ab759d5964 (diff)
downloadvyos-cloud-init-ced836e69274af905bbc1e5f5fde71de4066c86c.tar.gz
vyos-cloud-init-ced836e69274af905bbc1e5f5fde71de4066c86c.zip
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
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/config/cc_disk_setup.py13
1 files changed, 9 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)