Package: vmdb2 Version: 0.13.2+git20190215-1 Severity: wishlist Tags: patch
(debbugs cc: Lars) Only vmdb2 can know exactly what device is mounted as the image rootfs. Therefore, the only reliable way of creating /etc/fstab to have a working image, is to do that from withing vmdb2 itself. Patch attached. -- System Information: Debian Release: buster/sid APT prefers unstable-debug APT policy: (500, 'unstable-debug'), (500, 'testing-debug'), (500, 'unstable'), (500, 'testing'), (1, 'experimental-debug'), (1, 'experimental') Architecture: amd64 (x86_64) Kernel: Linux 4.19.0-3-amd64 (SMP w/4 CPU cores) Locale: LANG=pt_BR.UTF-8, LC_CTYPE=pt_BR.UTF-8 (charmap=UTF-8), LANGUAGE=pt_BR:pt:en (charmap=UTF-8) Shell: /bin/sh linked to /usr/bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled Versions of packages vmdb2 depends on: ii cmdtest 0.32-3 ii debootstrap 1.0.114 ii kpartx 0.7.9-2 ii parted 3.2-24 ii python3 3.7.2-1 ii python3-cliapp 1.20180812.1-2 ii python3-jinja2 2.10-1 ii python3-yaml 3.13-2 ii qemu-utils 1:3.1+dfsg-4 Versions of packages vmdb2 recommends: ii ansible 2.7.6+dfsg-1 vmdb2 suggests no packages. -- no debconf information
From 31f486ae3e7fc88f4a1dde3582d1197ccff6c0db Mon Sep 17 00:00:00 2001 From: Antonio Terceiro <terce...@debian.org> Date: Tue, 19 Feb 2019 14:59:49 -0300 Subject: [PATCH] Add: step to create /etc/fstab --- vmdb/plugins/fstab.mdwn | 12 +++++++++ vmdb/plugins/fstab_plugin.py | 49 ++++++++++++++++++++++++++++++++++++ without-tests | 1 + 3 files changed, 62 insertions(+) create mode 100644 vmdb/plugins/fstab.mdwn create mode 100644 vmdb/plugins/fstab_plugin.py diff --git a/vmdb/plugins/fstab.mdwn b/vmdb/plugins/fstab.mdwn new file mode 100644 index 0000000..a2c8eef --- /dev/null +++ b/vmdb/plugins/fstab.mdwn @@ -0,0 +1,12 @@ +Step: `fstab` +----------------------------------------------------------------------------- + +Create `/etc/fstab` inside the the image. + +Step keys: + +* `fstab` — REQUIRED; value is the tag for the root filesystem. + +Example (in the .vmdb file): + + - fstab: root diff --git a/vmdb/plugins/fstab_plugin.py b/vmdb/plugins/fstab_plugin.py new file mode 100644 index 0000000..f05e5a2 --- /dev/null +++ b/vmdb/plugins/fstab_plugin.py @@ -0,0 +1,49 @@ +# Copyright 2019 Antonio Terceiro +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# =*= License: GPL-3+ =*= + +import os + +import cliapp + +import vmdb + + +class FstabPlugin(cliapp.Plugin): + + def enable(self): + self.app.step_runners.add(FstabStepRunner()) + + +class FstabStepRunner(vmdb.StepRunnerInterface): + + def get_required_keys(self): + return ['fstab'] + + def run(self, step, setting, state): + tag = step['fstab'] + device = state.tags.get_dev(tag) + chroot = state.tags.get_mount_point(tag) + + rootdev = '/dev/sda1' + output = vmdb.runcmd(['blkid', '-c', '/dev/null', '-o', 'value', '-s', 'UUID', device]) + if output: + uuid = output.decode().strip() + rootdev = 'UUID=%s' % uuid + + fstab_path = os.path.join(chroot, 'etc/fstab') + with open(fstab_path, 'w') as fstab: + fstab.write("%s / ext4 errors=remount-ro 0 1\n" % rootdev) diff --git a/without-tests b/without-tests index 5745e27..7b479e0 100644 --- a/without-tests +++ b/without-tests @@ -11,6 +11,7 @@ vmdb/plugins/chroot_plugin.py vmdb/plugins/debootstrap_plugin.py vmdb/plugins/echo_plugin.py vmdb/plugins/error_plugin.py +vmdb/plugins/fstab_plugin.py vmdb/plugins/grub_plugin.py vmdb/plugins/kernel_plugin.py vmdb/plugins/lvm2_plugin.py -- 2.20.1
signature.asc
Description: PGP signature