diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2013-05-10 14:31:39 +0000 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2013-05-13 10:14:59 +0100 |
commit | 12d5377995f736caac630c85749cec81be6a419c (patch) | |
tree | a0fe1af7f1155fb7d07e0376322d1e6347b29503 /morphlib/writeexts.py | |
parent | 9898c112dfced5bd5fe3a56aab64a7a0163ebe16 (diff) | |
download | morph-12d5377995f736caac630c85749cec81be6a419c.tar.gz |
Use a different disk system layout for rawdisk
This is in preparation for making deployments able
to upgrade existing baserock systems.
Diffstat (limited to 'morphlib/writeexts.py')
-rwxr-xr-x | morphlib/writeexts.py | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py index 48847d56..cb47f63d 100755 --- a/morphlib/writeexts.py +++ b/morphlib/writeexts.py @@ -62,10 +62,14 @@ class WriteExtension(cliapp.Application): os.remove(raw_disk) raise try: - self.create_factory(mp, temp_root) - self.create_fstab(mp) - self.create_factory_run(mp) + version_label = 'version1' + version_root = os.path.join(mp, 'systems', version_label) + os.makedirs(version_root) + self.create_orig(version_root, temp_root) + self.create_fstab(version_root) + self.create_run(version_root) if self.bootloader_is_wanted(): + self.install_kernel(version_root, temp_root) self.install_extlinux(mp) except BaseException, e: sys.stderr.write('Error creating disk image') @@ -152,36 +156,30 @@ class WriteExtension(cliapp.Application): cliapp.runcmd(['umount', mount_point]) os.rmdir(mount_point) - def create_factory(self, real_root, temp_root): + def create_orig(self, version_root, temp_root): '''Create the default "factory" system.''' - factory = os.path.join(real_root, 'factory') + orig = os.path.join(version_root, 'orig') - self.status(msg='Creating factory subvolume') - cliapp.runcmd(['btrfs', 'subvolume', 'create', factory]) - self.status(msg='Copying files to factory subvolume') - cliapp.runcmd(['cp', '-a', temp_root + '/.', factory + '/.']) + self.status(msg='Creating orig subvolume') + cliapp.runcmd(['btrfs', 'subvolume', 'create', orig]) + self.status(msg='Copying files to orig subvolume') + cliapp.runcmd(['cp', '-a', temp_root + '/.', orig + '/.']) - # The kernel needs to be on the root volume. - self.status(msg='Copying boot directory to root subvolume') - 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.''' + def create_run(self, version_root): + '''Create the 'run' snapshot.''' - self.status(msg='Creating factory-run subvolume') - factory = os.path.join(real_root, 'factory') - factory_run = factory + '-run' + self.status(msg='Creating run subvolume') + orig = os.path.join(version_root, 'orig') + run = os.path.join(version_root, 'run') cliapp.runcmd( - ['btrfs', 'subvolume', 'snapshot', factory, factory_run]) + ['btrfs', 'subvolume', 'snapshot', orig, run]) - def create_fstab(self, real_root): + def create_fstab(self, version_root): '''Create an fstab.''' self.status(msg='Creating fstab') - fstab = os.path.join(real_root, 'factory', 'etc', 'fstab') + fstab = os.path.join(version_root, 'orig', 'etc', 'fstab') if os.path.exists(fstab): with open(fstab, 'r') as f: @@ -201,6 +199,18 @@ class WriteExtension(cliapp.Application): with open(fstab, 'w') as f: f.write(contents) + def install_kernel(self, version_root, temp_root): + '''Install the kernel outside of 'orig' or 'run' subvolumes''' + + self.status(msg='Installing kernel') + image_names = ['vmlinuz', 'zImage', 'uImage'] + kernel_dest = os.path.join(version_root, 'linux') + for name in image_names: + try_path = os.path.join(temp_root, 'boot', name) + if os.path.exists(try_path): + cliapp.runcmd(['cp', '-a', try_path, kernel_dest]) + break + def install_extlinux(self, real_root): '''Install extlinux on the newly created disk image.''' @@ -210,8 +220,9 @@ class WriteExtension(cliapp.Application): f.write('default linux\n') 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-run ' + f.write('kernel /systems/version1/linux\n') + f.write('append root=/dev/sda ' + 'rootflags=subvol=systems/version1/run ' 'init=/sbin/init rw\n') self.status(msg='Installing extlinux') |