From cdd887757ee70d1795bfa6116d72f7b6b53303c2 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sun, 5 Jan 2020 23:41:08 -0500 Subject: [PATCH] Use by-id labels for disks and dump/cpass /var/log --- .../provisioner/examples/debootstrap_script.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/client-api/provisioner/examples/debootstrap_script.py b/client-api/provisioner/examples/debootstrap_script.py index b5deeb2e..5cb696ad 100644 --- a/client-api/provisioner/examples/debootstrap_script.py +++ b/client-api/provisioner/examples/debootstrap_script.py @@ -96,15 +96,22 @@ def install(**kwargs): # Create an fstab entry for each disk fstab_file = "{}/etc/fstab".format(temporary_directory) + # The disk ID starts at zero and increments by one for each disk in the fixed-order + # disk list. This lets us work around the insanity of Libvirt IDs not matching guest IDs, + # while still letting us have some semblance of control here without enforcing things + # like labels. It increments in the for loop below at the end of each iteration, and is + # used to craft a /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-X device ID + # which will always match the correct order from Libvirt (unlike sdX/vdX names). + disk_id = 0 for disk in disks: # We assume SSD-based/-like storage, and dislike atimes options = "defaults,discard,noatime,nodiratime" - # The root and var volumes have specific values + # The root, var, and log volumes have specific values if disk['mountpoint'] == "/": dump = 0 cpass = 1 - elif disk['mountpoint'] == '/var': + elif disk['mountpoint'] == '/var' or disk['mountpoint'] == '/var/log': dump = 0 cpass = 2 else: @@ -113,8 +120,8 @@ def install(**kwargs): # Append the fstab line with open(fstab_file, 'a') as fh: - data = "/dev/{disk} {mountpoint} {filesystem} {options} {dump} {cpass}\n".format( - disk=disk['disk_id'], + data = "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-{disk} {mountpoint} {filesystem} {options} {dump} {cpass}\n".format( + disk=disk_id, mountpoint=disk['mountpoint'], filesystem=disk['filesystem'], options=options, @@ -123,6 +130,9 @@ def install(**kwargs): ) fh.write(data) + # Increment the disk_id + disk_id += 1 + # Write the hostname hostname_file = "{}/etc/hostname".format(temporary_directory) with open(hostname_file, 'w') as fh: