[Pkg-escience-soc2009] [SCM] Tool for creating VM images. branch, master, updated. 7a61add158a219802c7cfdee9446a707188d5c6a
David Wendt
kmeisthax at Lappy-486.A
Wed Jul 15 20:39:38 UTC 2009
The following commit has been merged in the master branch:
commit 7a61add158a219802c7cfdee9446a707188d5c6a
Author: David Wendt <kmeisthax at Lappy-486.A>
Date: Wed Jul 15 16:34:50 2009 -0400
Fixed device creation for lenny - added functions bind_ and unbind_system_devices. These will place the system's /dev, /dev/pts, and /proc into the in-progress image via mount --bind, and unbind does the opposite. These will be automatically unbound during cleanup.
Lenny.debootstrap automatically calls bind_system_devices as it used to before this commit.
Changed Lenny.create_devices to unbind the system devices before creating image devices. Before this it would create the devices in the system, polluting the system's /dev with useless device files and making subsequent VMbuilder calls break somehow. It binds them again at the end of device creation.
Added functions to -remove- cleanup commands from the cleanup phase, for unbind_system_devices.
diff --git a/VMBuilder/plugins/debian/lenny.py b/VMBuilder/plugins/debian/lenny.py
index bffd7f7..9c5e17d 100644
--- a/VMBuilder/plugins/debian/lenny.py
+++ b/VMBuilder/plugins/debian/lenny.py
@@ -64,16 +64,36 @@ class Lenny(Etch):
def debootstrap(self):
Etch.debootstrap(self)
+ self.bind_system_devices(True)
- run_cmd('mount', '--bind', '/dev', '%s/dev' % self.destdir)
- self.vm.add_clean_cmd('umount', '%s/dev' % self.destdir, ignore_fail=True)
+ def bind_system_devices(self):
+ #Mounts the system's /dev, /dev/pts, and /proc on top of ours.
+ #Also adds the appropriate umount commands to the cleanup phase.
+ if self.hasattr("system_devices_mounted") and self.system_devices_mounted:
+ run_cmd('mount', '--bind', '/dev', '%s/dev' % self.destdir)
+ self.vm.add_clean_cmd('umount', '%s/dev' % self.destdir, ignore_fail=True)
- run_cmd('mount', '--bind', '/dev/pts', '%s/dev/pts' % self.destdir)
- self.vm.add_clean_cmd('umount', '%s/dev/pts' % self.destdir, ignore_fail=True)
+ run_cmd('mount', '--bind', '/dev/pts', '%s/dev/pts' % self.destdir)
+ self.vm.add_clean_cmd('umount', '%s/dev/pts' % self.destdir, ignore_fail=True)
- run_cmd('mount', '-t', 'proc', 'proc', '%s/proc' % self.destdir)
- self.vm.add_clean_cmd('umount', '%s/proc' % self.destdir, ignore_fail=True)
+ run_cmd('mount', '-t', 'proc', 'proc', '%s/proc' % self.destdir)
+ self.vm.add_clean_cmd('umount', '%s/proc' % self.destdir, ignore_fail=True)
+ self.system_devices_mounted = True
+
+ def unbind_system_devices(self):
+ #Opposite of bind_system_devices.
+ #Also removes the cleanup commands.
+ else self.hasattr("system_devices_mounted") and self.system_devices_mounted:
+ run_cmd('umount', '%s/dev' % self.destdir)
+ self.vm.remove_clean_cmd('umount', '%s/dev' % self.destdir, ignore_fail=True)
+
+ run_cmd('umount', '%s/dev/pts' % self.destdir)
+ self.vm.remove_clean_cmd('umount', '%s/dev/pts' % self.destdir, ignore_fail=True)
+
+ run_cmd('umount', '%s/proc' % self.destdir)
+ self.vm.remove_clean_cmd('umount', '%s/proc' % self.destdir, ignore_fail=True)
+ self.system_devices_mounted = False
def copy_settings(self):
self.copy_to_target('/etc/default/locale', '/etc/default/locale')
@@ -113,4 +133,10 @@ class Lenny(Etch):
# Extremely dirty hack to fix the root parameters in menu.lst to (hd0,0)
bootdev = disk.bootpart(self.vm.disks)
run_cmd('sed', '-ie', 's/([^)]*)/(hd0,0)/', '%s/boot/grub/menu.lst' % self.destdir)
+
+ def create_devices(self):
+ #Having system devices bound makes device creation fail.
+ self.unbind_system_devices()
+ Etch.create_devices(self)
+ self.bind_system_devices()
diff --git a/VMBuilder/vm.py b/VMBuilder/vm.py
index 8782917..723d372 100644
--- a/VMBuilder/vm.py
+++ b/VMBuilder/vm.py
@@ -107,11 +107,19 @@ class VM(object):
def add_clean_cb(self, cb):
self._cleanup_cbs.insert(0, cb)
+ def remove_clean_cb(self, cb):
+ self._cleanup_cbs.remove(cb)
+
def add_clean_cmd(self, *argv, **kwargs):
cb = lambda : util.run_cmd(*argv, **kwargs)
self.add_clean_cb(cb)
return cb
+ def remove_clean_cmd(self, *argv, **kwargs):
+ cb = lambda : util.run_cmd(*argv, **kwargs)
+ self.remove_clean_cb(cb)
+ return cb
+
def cancel_cleanup(self, cb):
try:
self._cleanup_cbs.remove(cb)
--
Tool for creating VM images.
More information about the Pkg-escience-soc2009
mailing list