From 4cd3a4060146a37cdef216ee4dc346c0f7229f8c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 2 May 2013 16:36:57 +0100 Subject: Add entry for / in fstab but only if there isn't one --- writeexts.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'writeexts.py') 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.''' -- cgit v1.2.1