diff options
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): |