diff options
author | James Thomas <james.thomas@codethink.co.uk> | 2015-02-04 11:30:03 +0000 |
---|---|---|
committer | James Thomas <james.thomas@codethink.co.uk> | 2015-02-04 12:09:48 +0000 |
commit | a85ef8ca229d26ff35787f53b30713fe774ee88a (patch) | |
tree | 63516bc017f22ef1cf15dd022a9d30d950d3f776 /morphlib/writeexts.py | |
parent | edf5232690a648b715a2649f37393c0565bc127f (diff) | |
download | morph-a85ef8ca229d26ff35787f53b30713fe774ee88a.tar.gz |
Add support for updating existing fstab files to writeexts/ssh-rsync
When upgrading (using ssh-rsync) from an existing rawdisk image, there
will already be an fstab. This patch adds support to update the UUID
when a fstab file already exists
Diffstat (limited to 'morphlib/writeexts.py')
-rw-r--r-- | morphlib/writeexts.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py index 6ab2dd55..6948f7f5 100644 --- a/morphlib/writeexts.py +++ b/morphlib/writeexts.py @@ -74,9 +74,11 @@ class Fstab(object): self.text += line + '\n' - def write(self): + def write(self, writepath=None): '''Rewrite the fstab file to include all new entries.''' - with morphlib.savefile.SaveFile(self.filepath, 'w') as f: + if writepath is None: + writepath = self.filepath + with morphlib.savefile.SaveFile(writepath, 'w') as f: f.write(self.text) @@ -348,7 +350,8 @@ class WriteExtension(cliapp.Application): filepath = os.path.join(existing_state_dir, filename) cliapp.runcmd(['mv', filepath, subvolume]) - def complete_fstab_for_btrfs_layout(self, system_dir, rootfs_uuid=None): + def complete_fstab_for_btrfs_layout(self, system_dir, rootfs_uuid=None, + temp_fstab=None): '''Fill in /etc/fstab entries for the default Btrfs disk layout. In the future we should move this code out of the write extension and @@ -368,9 +371,15 @@ class WriteExtension(cliapp.Application): fstab = Fstab(os.path.join(system_dir, 'etc', 'fstab')) existing_mounts = fstab.get_mounts() + old_root_device = None if '/' in existing_mounts: root_device = existing_mounts['/'] + new_root_device = (None if rootfs_uuid is None else + 'UUID=%s' % rootfs_uuid) + if new_root_device is not None and root_device is not new_root_device: + old_root_device = root_device + root_device = new_root_device else: root_device = (self.get_root_device() if rootfs_uuid is None else 'UUID=%s' % rootfs_uuid) @@ -385,7 +394,9 @@ class WriteExtension(cliapp.Application): '%s /%s btrfs subvol=%s,defaults,rw,noatime 0 2' % (root_device, state_dir, state_subvol)) - fstab.write() + if old_root_device is not None: + fstab.text = fstab.text.replace(old_root_device, root_device) + fstab.write(temp_fstab) return state_dirs_to_create def find_initramfs(self, temp_root): |