Merge lp:~cjwatson/vmbuilder/chroot-grub into lp:vmbuilder/trunk

Proposed by Colin Watson
Status: Merged
Approved by: Soren Hansen
Approved revision: 351
Merged at revision: not available
Proposed branch: lp:~cjwatson/vmbuilder/chroot-grub
Merge into: lp:vmbuilder/trunk
Diff against target: 46 lines
1 file modified
VMBuilder/plugins/ubuntu/distro.py (+20/-4)
To merge this branch: bzr merge lp:~cjwatson/vmbuilder/chroot-grub
Reviewer Review Type Date Requested Status
Soren Hansen Approve
Review via email: mp+12865@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Soren Hansen (soren) wrote :

On Mon, Oct 05, 2009 at 11:10:25AM -0000, Colin Watson wrote:
> + def install_bootloader_cleanup(self):
> + self.vm.cancel_cleanup(self.install_bootloader_cleanup)

Clever! I can think of a bunch of places this would be useful.

The rest looks great as well. Thank you!

 merge approved

--
Soren Hansen |
Lead virtualisation engineer | Ubuntu Server Team
Canonical Ltd. | http://www.ubuntu.com/

review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

On Thu, Oct 08, 2009 at 10:48:12AM -0000, Soren Hansen wrote:
> On Mon, Oct 05, 2009 at 11:10:25AM -0000, Colin Watson wrote:
> > + def install_bootloader_cleanup(self):
> > + self.vm.cancel_cleanup(self.install_bootloader_cleanup)
>
> Clever! I can think of a bunch of places this would be useful.

Not my idea, actually; I borrowed it from
VMBuilder.disk.Filesystem.umount. :-)

--
Colin Watson [<email address hidden>]

Revision history for this message
Soren Hansen (soren) wrote :

On Thu, Oct 08, 2009 at 10:54:11AM -0000, Colin Watson wrote:
>On Thu, Oct 08, 2009 at 10:48:12AM -0000, Soren Hansen wrote:
>> On Mon, Oct 05, 2009 at 11:10:25AM -0000, Colin Watson wrote:
>>> + def install_bootloader_cleanup(self):
>>> + self.vm.cancel_cleanup(self.install_bootloader_cleanup)
>>
>> Clever! I can think of a bunch of places this would be useful.
> Not my idea, actually; I borrowed it from
> VMBuilder.disk.Filesystem.umount. :-)

Wow, and "bzr blame" says I wrote that bit. Talk about a brief moment of
clarity :)

--
Soren Hansen |
Lead virtualisation engineer | Ubuntu Server Team
Canonical Ltd. | http://www.ubuntu.com/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'VMBuilder/plugins/ubuntu/distro.py'
2--- VMBuilder/plugins/ubuntu/distro.py 2009-09-15 10:33:37 +0000
3+++ VMBuilder/plugins/ubuntu/distro.py 2009-10-05 11:10:24 +0000
4@@ -20,6 +20,7 @@
5 import os
6 import socket
7 import types
8+import shutil
9 import VMBuilder
10 from VMBuilder import register_distro, Distro
11 from VMBuilder.util import run_cmd
12@@ -155,15 +156,30 @@
13 def use_virtio_net(self):
14 return self.suite.virtio_net
15
16+ def install_bootloader_cleanup(self):
17+ self.vm.cancel_cleanup(self.install_bootloader_cleanup)
18+ tmpdir = '%s/tmp/vmbuilder-grub' % self.destdir
19+ for disk in os.listdir(tmpdir):
20+ if disk != 'device.map':
21+ run_cmd('umount', os.path.join(tmpdir, disk))
22+ shutil.rmtree(tmpdir)
23+
24 def install_bootloader(self):
25- devmapfile = '%s/device.map' % self.vm.workdir
26- devmap = open(devmapfile, 'w')
27+ tmpdir = '/tmp/vmbuilder-grub'
28+ os.makedirs('%s%s' % (self.destdir, tmpdir))
29+ self.vm.add_clean_cb(self.install_bootloader_cleanup)
30+ devmapfile = os.path.join(tmpdir, 'device.map')
31+ devmap = open('%s%s' % (self.destdir, devmapfile), 'w')
32 for (disk, id) in zip(self.vm.disks, range(len(self.vm.disks))):
33- devmap.write("(hd%d) %s\n" % (id, disk.filename))
34+ new_filename = os.path.join(tmpdir, os.path.basename(disk.filename))
35+ open('%s%s' % (self.destdir, new_filename), 'w').close()
36+ run_cmd('mount', '--bind', disk.filename, '%s%s' % (self.destdir, new_filename))
37+ devmap.write("(hd%d) %s\n" % (id, new_filename))
38 devmap.close()
39- run_cmd('grub', '--device-map=%s' % devmapfile, '--batch', stdin='''root (hd0,0)
40+ self.run_in_target('grub', '--device-map=%s' % devmapfile, '--batch', stdin='''root (hd0,0)
41 setup (hd0)
42 EOT''')
43+ self.install_bootloader_cleanup()
44
45 def xen_kernel_version(self):
46 if self.suite.xen_kernel_flavour: