diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-05-02 16:36:57 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-05-02 16:36:57 +0100 |
commit | a436a24e5db3262db210e5b0d8686fbdf703e42f (patch) | |
tree | 7dc0c17b8810b2f359aff36e11ad569ad3999bfb /morphlib/writeexts.py | |
parent | 6e7dd9db82e8c18dd278f8d38a8da2017bae0676 (diff) | |
download | morph-a436a24e5db3262db210e5b0d8686fbdf703e42f.tar.gz |
Add entry for / in fstab but only if there isn't one
Diffstat (limited to 'morphlib/writeexts.py')
-rwxr-xr-x | morphlib/writeexts.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py index af48b375..2cdba86f 100755 --- a/morphlib/writeexts.py +++ b/morphlib/writeexts.py @@ -179,10 +179,26 @@ class WriteExtension(cliapp.Application): def create_fstab(self, real_root): '''Create an fstab.''' - self.status(msg='Creating fstab') + self.status(msg='Creating fstab') fstab = os.path.join(real_root, 'factory', 'etc', 'fstab') + + if os.path.exists(fstab): + with open(fstab, 'r') as f: + contents = f.read() + else: + contents = '' + + got_root = False + for line in contents.splitlines(): + words = line.split() + if len(words) >= 2 and not words[0].startswith('#'): + got_root = got_root or words[1] == '/' + + if not got_root: + contents += '\n/dev/sda / btrfs defaults,rw,noatime 0 1\n' + with open(fstab, 'w') as f: - f.write('/dev/sda / btrfs defaults,rw,noatime 0 1\n') + f.write(contents) def install_extlinux(self, real_root): '''Install extlinux on the newly created disk image.''' |