summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-05-02 16:36:57 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-05-02 16:36:57 +0100
commit4cd3a4060146a37cdef216ee4dc346c0f7229f8c (patch)
tree5581077b6a2507864d718a6f8921e1dbee9e6ae2
parent2fa5a589912f660ddc2a08024eb511479042e29e (diff)
downloaddefinitions-4cd3a4060146a37cdef216ee4dc346c0f7229f8c.tar.gz
Add entry for / in fstab but only if there isn't one
-rwxr-xr-xwriteexts.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/writeexts.py b/writeexts.py
index af48b375..2cdba86f 100755
--- a/writeexts.py
+++ b/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.'''