diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-02-07 11:41:04 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-02-07 14:34:42 +0000 |
commit | 794301e1e1ec1b35145ae7bdd9093909c6488478 (patch) | |
tree | 1ca39c748baebf5ba94d7c24d12c2d88aca1343f /morphlib/writeexts.py | |
parent | e3bb31154b259eb04019e7f63f1e0270d1606e06 (diff) | |
download | morph-794301e1e1ec1b35145ae7bdd9093909c6488478.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
Diffstat (limited to 'morphlib/writeexts.py')
-rwxr-xr-x | morphlib/writeexts.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py index fae0d5d9..60848345 100755 --- a/morphlib/writeexts.py +++ b/morphlib/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') |