summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-02-07 11:41:04 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-02-07 14:34:42 +0000
commit4aeffa2de48737a481cd20688f8b1b874cf7e46e (patch)
treec2fc9d836a2cf87b00dfb2d4f8ed39451fcaaf74
parent65d7afb64c344a219b831eeb0e4bb0ebcbbf4ab6 (diff)
downloaddefinitions-4aeffa2de48737a481cd20688f8b1b874cf7e46e.tar.gz
Refactor: Add WriteExtension.create_local_system method
This allows code sharing amongst all the places that create a system in a raw disk image. This also adds the creation of a factory-run subvolume, and fixes error messages for errors that happen during a disk image creation. Suggested-By: Richard Maw Suggested-By: Sam Thursfield
-rwxr-xr-xwriteexts.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/writeexts.py b/writeexts.py
index fae0d5d9..60848345 100755
--- a/writeexts.py
+++ b/writeexts.py
@@ -47,6 +47,31 @@ class WriteExtension(cliapp.Application):
'''
self.output.write('%s\n' % (kwargs['msg'] % kwargs))
+
+ def create_local_system(self, temp_root, raw_disk):
+ '''Create a raw system image locally.'''
+
+ size = self.get_disk_size()
+ self.create_raw_disk_image(raw_disk, size)
+ try:
+ self.mkfs_btrfs(raw_disk)
+ mp = self.mount(raw_disk)
+ except BaseException:
+ sys.stderr.write('Error creating disk image')
+ os.remove(raw_disk)
+ raise
+ try:
+ self.create_factory(mp, temp_root)
+ self.create_fstab(mp)
+ self.create_factory_run(mp)
+ self.install_extlinux(mp)
+ except BaseException, e:
+ sys.stderr.write('Error creating disk image')
+ self.unmount(mp)
+ os.remove(raw_disk)
+ raise
+ else:
+ self.unmount(mp)
def get_disk_size(self):
'''Parse disk size from environment.'''
@@ -120,6 +145,15 @@ class WriteExtension(cliapp.Application):
factory_boot = os.path.join(factory, 'boot')
root_boot = os.path.join(real_root, 'boot')
cliapp.runcmd(['cp', '-a', factory_boot, root_boot])
+
+ def create_factory_run(self, real_root):
+ '''Create the 'factory-run' snapshot.'''
+
+ self.status(msg='Creating factory-run subvolume')
+ factory = os.path.join(real_root, 'factory')
+ factory_run = factory + '-run'
+ cliapp.runcmd(
+ ['btrfs', 'subvolume', 'snapshot', factory, factory_run])
def create_fstab(self, real_root):
'''Create an fstab.'''
@@ -139,7 +173,7 @@ class WriteExtension(cliapp.Application):
f.write('timeout 1\n')
f.write('label linux\n')
f.write('kernel /boot/vmlinuz\n')
- f.write('append root=/dev/sda rootflags=subvol=factory '
+ f.write('append root=/dev/sda rootflags=subvol=factory-run '
'init=/sbin/init rw\n')
self.status(msg='Installing extlinux')