summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-03-21 06:02:48 +0000
committerLars Wirzenius <liw@liw.fi>2020-03-21 06:02:48 +0000
commit10e5d7cc965d0091e302707b1c35f0fcc48e5923 (patch)
treea45173da3244d2267f684ae1a4425473c69f6d03
parent196b7a1fa4fbaa4e3de756560fa5e570ed9052c8 (diff)
parent7573a714ea8d42cc6f81a0371d5ea38963ec1e89 (diff)
downloadvmdb2-10e5d7cc965d0091e302707b1c35f0fcc48e5923.tar.gz
Merge branch 'proc' into 'master'
Always mount /proc in chroot Closes #18 See merge request larswirzenius/vmdb2!12
-rw-r--r--vmdb/plugins/grub_plugin.py4
-rw-r--r--vmdb/runcmd.py33
2 files changed, 33 insertions, 4 deletions
diff --git a/vmdb/plugins/grub_plugin.py b/vmdb/plugins/grub_plugin.py
index 3943f9b..937fffc 100644
--- a/vmdb/plugins/grub_plugin.py
+++ b/vmdb/plugins/grub_plugin.py
@@ -36,7 +36,7 @@
# mount /dev into the chroot so the device is available.
#
# grub-install seems to also require /proc and /sys so we bind mount
-# those into the chroot as well.
+# /sys into the chroot as well. /proc is already mounted otherwise.
#
# We install the UEFI version of GRUB, and for that we additionally
# bind mount the EFI partition in the image. Oh yeah, you MUST have
@@ -136,7 +136,7 @@ class GrubStepRunner(vmdb.StepRunnerInterface):
else:
efi_dev = None
- self.bind_mount_many(chroot, ['/dev', '/proc', '/sys'], state)
+ self.bind_mount_many(chroot, ['/dev', '/sys'], state)
if efi_dev:
self.mount(chroot, efi_dev, '/boot/efi', state)
self.install_package(chroot, grub_package)
diff --git a/vmdb/runcmd.py b/vmdb/runcmd.py
index 7ab57de..fa26f92 100644
--- a/vmdb/runcmd.py
+++ b/vmdb/runcmd.py
@@ -18,6 +18,7 @@
import logging
import os
+import subprocess
import sys
import cliapp
@@ -53,8 +54,36 @@ def runcmd(argv, *argvs, **kwargs):
def runcmd_chroot(chroot, argv, *argvs, **kwargs):
- full_argv = ['chroot', chroot] + argv
- return runcmd(full_argv, *argvs, **kwargs)
+ _mount_proc(chroot)
+ try:
+ full_argv = ['chroot', chroot] + argv
+ return runcmd(full_argv, *argvs, **kwargs)
+ except Exception:
+ _unmount_proc(chroot)
+ raise
+ finally:
+ _unmount_proc(chroot)
+
+
+def _mount_proc(chroot):
+ proc = _procdir(chroot)
+ argv = ['chroot', chroot, 'mount', '-t', 'proc', 'proc', '/proc']
+ progress('mounting proc: %r' % argv)
+ subprocess.check_call(argv)
+
+
+def _unmount_proc(chroot):
+ proc = _procdir(chroot)
+ argv = ['chroot', chroot, 'umount', '/proc']
+ progress('unmounting proc: %r' % argv)
+ subprocess.check_call(argv)
+
+
+def _procdir(chroot):
+ proc = os.path.join(chroot, 'proc')
+ if not os.path.exists(proc):
+ os.mkdir(proc, mode=Oo755)
+ return proc
def _log_stdout(data):