Bug 305469 - Adding a new mount point using 'Edit mount point' deleted existing entries in /etc/fstab
Summary: Adding a new mount point using 'Edit mount point' deleted existing entries in...
Status: RESOLVED FIXED
Alias: None
Product: partitionmanager
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Andrius Štikonas
URL:
Keywords:
: 378977 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-20 02:08 UTC by Syam
Modified: 2017-09-16 19:54 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 3.2
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Syam 2012-08-20 02:08:02 UTC
In my fstab file, I have some partitions specified using UUIDs and some using device nodes.
Using KDE Partition Manager, I tried to add a mount point for a partition. In the dialog, I selected 'identify by UUID' and entered other fields. Finally, after completion of the operation, I checked my fstab file and found that pre-existing entries specified by device nodes were deleted. i.e. only those entries specified by UUIDs were present, along with the newly created entry.

Reproducible: Didn't try
Comment 1 Luis Fernando P.C. 2013-03-15 23:48:21 UTC
I couldn't start the program partition manager, ask me for a privileges that I don't know how to get these
Comment 2 Jekyll Wu 2013-03-16 02:08:47 UTC
(In reply to comment #1)
> I couldn't start the program partition manager, ask me for a privileges that
> I don't know how to get these

Just fill your password. And bugs.kde.org is not a help forum, so such question should go to forum.kde.org. Even it is, it is not good to hijack other's thread .
Comment 3 Edward Donovan 2017-03-13 04:52:55 UTC
I experienced this problem, under Fedora 25.  When KPM added an fstab entry, it removed the entry for '/'.  That was scary. :)

I'll try to double-check, but I believe in this case, the removed line did include a UUID.
Comment 4 Edward Donovan 2017-03-13 06:43:42 UTC
Ok, I'm trying to learn more about this program; I see that 3.0 is out. My crash occurred under 2.2.1 on fedora.  I don't have a KDE neon installation, but I'm hoping to, soon.  When I can, I'll test under 3.0, if still needed.

Here are the fstab files before and after partitionmanager altered the file.  They seem simple enough to paste rather than attach, but I have to note that in the "before" version, the first line was blank.  I haven't done the testing yet to see if that makes a difference.
before:
"""

#
# /etc/fstab
# Created by anaconda on Thu Feb 16 23:54:23 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=aca13ca8-0061-455f-982e-e35c3e072f7b /                       btrfs   subvol=root,noatime           0 0
UUID=cd538f0b-aa1d-461e-83fe-33d775f5eb24 /boot                   ext4    defaults,noatime              1 2
UUID=aca13ca8-0061-455f-982e-e35c3e072f7b /home                   btrfs   subvol=home,noatime           0 0
UUID=0c29ed65-c366-4798-8137-299f33a0c840 swap                    swap    defaults                      0 0
"""


After:
"""
UUID=cd538f0b-aa1d-461e-83fe-33d775f5eb24       /boot   ext4    defaults        1       2
UUID=aca13ca8-0061-455f-982e-e35c3e072f7b       /home   btrfs   subvol=home     0       0
UUID=0c29ed65-c366-4798-8137-299f33a0c840       swap    swap    defaults        0       0
/dev/sdb1       /mnt    xfs     noatime,nodiratime      0       0
"""

Ideally I would like to retain the comments, as well.  

Hopefully I can add more later -- thank you.
Comment 5 Andrius Štikonas 2017-04-19 21:11:02 UTC
*** Bug 378977 has been marked as a duplicate of this bug. ***
Comment 6 Andrius Štikonas 2017-04-19 21:12:07 UTC
(In reply to Edward Donovan from comment #4)
> Ok, I'm trying to learn more about this program; I see that 3.0 is out. My
> crash occurred under 2.2.1 on fedora.  I don't have a KDE neon installation,
> but I'm hoping to, soon.  When I can, I'll test under 3.0, if still needed.

Well, this wasn't fixed, so 3.0 wouldn't start to work magically.

Basically, KPM reads info from fstab that it recognizes and discards everything else. Then it recreates it from the information it knows.
Comment 7 Andrius Štikonas 2017-06-04 22:11:20 UTC
The latest commit should improve behaviour a bit when there are multiple mount points corresponding to the same device.

https://cgit.kde.org/partitionmanager.git/commit/?id=6889a3b17ce1dced3d728aa54f664c795acb8c21)

This bug will need more work later but at least it will work better than before.
Comment 8 Andrius Štikonas 2017-06-04 22:45:35 UTC
Looks like preserving comments might be a bit harder.

We use mntent from glibc to read fstab (by the way, GParted also uses it for reading mount points). getmntent does not read comments at all.

Maybe it can be fixed by only replacing one line in fstab instead of rewriting the whole file.
Comment 9 Andrius Štikonas 2017-09-13 22:02:45 UTC
I added fstab parsing function to kpmcore, so that we don't have to rely on glibc's getmntend

https://cgit.kde.org/kpmcore.git/commit/?id=34712dd2ed499dd2c78ea07de9b3b499f32c86f7

It reads comments as well. However, partition manager still needs to be ported to use this new code.
Comment 10 Andrius Štikonas 2017-09-16 19:41:36 UTC
Git commit baec1573149498404a0ce9af670be787ff893b21 by Andrius Štikonas.
Committed on 16/09/2017 at 19:40.
Pushed by stikonas into branch 'master'.

Add a function to write fstab file.

M  +53   -0    src/core/fstab.cpp
M  +1    -0    src/core/fstab.h

https://commits.kde.org/kpmcore/baec1573149498404a0ce9af670be787ff893b21
Comment 11 Andrius Štikonas 2017-09-16 19:43:25 UTC
Git commit 454845e14e1c34762cffa3021be7a552b1c64c46 by Andrius Štikonas.
Committed on 16/09/2017 at 19:41.
Pushed by stikonas into branch 'master'.

Port from MountEntry to FstabEntry.

This helps to preserve comments in fstab file

M  +2    -2    src/gui/editmountoptionsdialog.cpp
M  +5    -1    src/gui/editmountpointdialog.cpp
M  +54   -167  src/gui/editmountpointdialogwidget.cpp
M  +9    -8    src/gui/editmountpointdialogwidget.h

https://commits.kde.org/partitionmanager/454845e14e1c34762cffa3021be7a552b1c64c46
Comment 12 Andrius Štikonas 2017-09-16 19:51:50 UTC
Git commit 8dd1e70b2121047840b8d74fd7ae6d56ba31b90b by Andrius Štikonas.
Committed on 16/09/2017 at 19:50.
Pushed by stikonas into branch 'master'.

Fix inline comment handling.

M  +2    -2    src/core/fstab.cpp

https://commits.kde.org/kpmcore/8dd1e70b2121047840b8d74fd7ae6d56ba31b90b
Comment 13 Andrius Štikonas 2017-09-16 19:54:04 UTC
Ok, this should be fixed now. Comments are fully preserved. No fstab entries should be deleted. Only whitespace inside fstab lines is not preserved, e.g. spaces can be replaced with tabs. But it should be good enough now.