Bug 368175 - Error creating new partition with KDE auto-mount enabled
Summary: Error creating new partition with KDE auto-mount enabled
Status: RESOLVED FIXED
Alias: None
Product: partitionmanager
Classification: Applications
Component: general (other bugs)
Version First Reported In: 3.0
Platform: Fedora RPMs Linux
: NOR major
Target Milestone: ---
Assignee: Andrius Štikonas
URL:
Keywords:
: 364890 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-09-03 07:25 UTC by Mattia
Modified: 2017-06-12 22:08 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: kpmcore 3.1.1, partitionmanager 3.1.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mattia 2016-09-03 07:25:26 UTC
A user on KDE bugzilla has reported problems with partitioning and formatting an hard drive. I believe this is due to KDE automount of removable media feature that, if enabled, mounts the new partition before PM has finished his tasks. See https://bugzilla.redhat.com/show_bug.cgi?id=1371755

Is there something that PM can do to avoid this error? Maybe temporarily disable KDE automount feature when it runs?

Reproducible: Didn't try
Comment 1 Mattia 2017-04-07 18:46:53 UTC
This still applies to PM 3.0.1
Comment 2 Andrius Štikonas 2017-04-07 18:57:23 UTC
(In reply to Mattia from comment #1)
> This still applies to PM 3.0.1
Yeah, there were no changes so far :(. I tried asking other Plasma people but nobody knew how to disable automount...
Comment 3 Rahul Prabhakar 2017-05-29 16:51:10 UTC
Steps to disable automount in KDE Plasma 5.

1. Run "System Settings" from Application Menu or 
   launch konsole / terminal and run "systemsettings5" [Quotes excluded].
2. Scroll down and click "Removable Storage" under section "Hardware".
3. Click "Removable Devices" in the left pane.
4. Right pane will show section with Title 
   "Configure automatic handling of removable storage media".
5. Uncheck the option "Enable automatic mounting of removable media".
6. Click Apply [Bottom Right button].
7. Reboot and re-login.
Comment 4 Andrius Štikonas 2017-05-29 16:59:48 UTC
(In reply to Rahul Prabhakar from comment #3)
> Steps to disable automount in KDE Plasma 5.
> 
> 1. Run "System Settings" from Application Menu or 
>    launch konsole / terminal and run "systemsettings5" [Quotes excluded].
> 2. Scroll down and click "Removable Storage" under section "Hardware".
> 3. Click "Removable Devices" in the left pane.
> 4. Right pane will show section with Title 
>    "Configure automatic handling of removable storage media".
> 5. Uncheck the option "Enable automatic mounting of removable media".
> 6. Click Apply [Bottom Right button].
> 7. Reboot and re-login.

These are manually executed steps to completely disable automount. What we need is a way to non manually (e.g. call some program or dbus interface) suspend automount while KPM is running.
Comment 5 Rahul Prabhakar 2017-06-05 14:02:59 UTC
Small observation i wud like to share.

Under section "Configure automatic handling of removable storage media". if a user wud first uncheck "Automount on attach" & "Automount on login" for desired partition before Disabling Automount feature itself only then desired result is 
achieved. 

U might want to read through KDE systemsettings code to see what api call(s) is/are triggered when above mentioned change is applied.

Command: e2fsck -f -y -v /dev/sda7 is working correctly for me but in the associated bugreport from redhat user reported that e2fsck -f -y -v /dev/sda1 fails.

Only difference cud be i am creating logical partition and redhat user is creating primary partition.

KDE partition Manager log

Delete partition ‘/dev/sda7’ (229.07 GiB, ext4) 
Job: Delete file system on ‘/dev/sda7’ 
Delete file system on ‘/dev/sda7’: Success

Job: Delete the partition ‘/dev/sda7’ 
Delete the partition ‘/dev/sda7’: Success
Delete partition ‘/dev/sda7’ (229.07 GiB, ext4): Success

Create a new partition (229.07 GiB, ext4) on ‘/dev/sda’ 
Job: Create new partition on device ‘/dev/sda’ 
Create new partition ‘/dev/sda7’: Success

Job: Create file system ‘ext4’ on partition ‘/dev/sda7’ 
Command: mkfs.ext4 -qF /dev/sda7 
Create file system ‘ext4’ on partition ‘/dev/sda7’: Success

Job: Set the file system label on partition ‘/dev/sda7’ to "UserData" 
Command: e2label /dev/sda7 UserData 
Set the file system label on partition ‘/dev/sda7’ to "UserData": Success

Job: Check file system on partition ‘/dev/sda7’ 
Command: e2fsck -f -y -v /dev/sda7 
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

          11 inodes used (0.00%, out of 15015936)
           0 non-contiguous files (0.0%)
           0 non-contiguous directories (0.0%)
             # of inodes with ind/dind/tind blocks: 0/0/0
             Extent depth histogram: 2/1
     1220123 blocks used (2.03%, out of 60049152)
           0 bad blocks
           1 large file

           0 regular files
           2 directories
           0 character device files
           0 block device files
           0 fifos
           0 links
           0 symbolic links (0 fast symbolic links)
           0 sockets
------------
           2 files 
Check file system on partition ‘/dev/sda7’: Success
Create a new partition (229.07 GiB, ext4) on ‘/dev/sda’: Success
Comment 6 Andrius Štikonas 2017-06-05 14:10:00 UTC
Hmm, yeah, maybe I can just follow what systemsettings does even if there is no DBus API. Just need to remember the previous state and then restore it after operation is completed.
Comment 7 Andrius Štikonas 2017-06-05 14:48:52 UTC
*** Bug 364890 has been marked as a duplicate of this bug. ***
Comment 8 Andrius Štikonas 2017-06-05 19:29:00 UTC
Ok, looks like I found a way to temporary unload the whole kded module doing automounting. This will be better than following what automounter kcm does.

qdbus org.kde.kded5 /kded org.kde.kded5.unloadModule device_automounter
and
qdbus org.kde.kded5 /kded org.kde.kded5.loadModule device_automounter
Comment 9 Andrius Štikonas 2017-06-06 20:39:18 UTC
(In reply to Andrius Štikonas from comment #8)
> Ok, looks like I found a way to temporary unload the whole kded module doing
> automounting. This will be better than following what automounter kcm does.
> 
> qdbus org.kde.kded5 /kded org.kde.kded5.unloadModule device_automounter
> and
> qdbus org.kde.kded5 /kded org.kde.kded5.loadModule device_automounter

Hmm, these commands work manually but do not work from inside partition manager. The reason is that partition manager is running as root while automounter is running as normal user. Well it would of course work if we port to KAuth/Polkit but that is a very big task... I probably need to find some interim solution.
Comment 10 Andrius Štikonas 2017-06-07 13:20:34 UTC
(In reply to Andrius Štikonas from comment #9)
> (In reply to Andrius Štikonas from comment #8)
> > Ok, looks like I found a way to temporary unload the whole kded module doing
> > automounting. This will be better than following what automounter kcm does.
> > 
> > qdbus org.kde.kded5 /kded org.kde.kded5.unloadModule device_automounter
> > and
> > qdbus org.kde.kded5 /kded org.kde.kded5.loadModule device_automounter
> 
> Hmm, these commands work manually but do not work from inside partition
> manager. The reason is that partition manager is running as root while
> automounter is running as normal user. Well it would of course work if we
> port to KAuth/Polkit but that is a very big task... I probably need to find
> some interim solution.

Ok, I think I can solve this by running logname to get the username of the original user and then obtains UID of that user and run setuid before making QtDBus connection.
Comment 11 Andrius Štikonas 2017-06-07 17:24:37 UTC
Git commit 63b5c8c34cf257d29fb8e67b41da7b606b32aec0 by Andrius Štikonas.
Committed on 07/06/2017 at 17:21.
Pushed by stikonas into branch 'master'.

Suspend Plasma removable device automounting.

Before doing operations, we connect to DBus session of the original user
and stop kded module for device automounting.

M  +1    -0    CMakeLists.txt
M  +1    -0    src/CMakeLists.txt
M  +24   -3    src/core/operationrunner.cpp

https://commits.kde.org/kpmcore/63b5c8c34cf257d29fb8e67b41da7b606b32aec0
Comment 12 Andrius Štikonas 2017-06-12 15:25:46 UTC
I'll reopen this for now as this is only fixed on X11 and does not work on Wayland. Similar problem is encountered in bug #365882.
Comment 13 Andrius Štikonas 2017-06-12 22:07:53 UTC
Git commit 4e78cd9ff1d990fbe1db3f54469aa567d9f908fe by Andrius Štikonas.
Committed on 12/06/2017 at 22:06.
Pushed by stikonas into branch 'master'.

Pass DBUS_SESSION_BUS_ADDRESS environmental variable.

This is necessary for disabling Plasma automounter on Wayland.

M  +2    -1    src/util/guihelpers.cpp

https://commits.kde.org/partitionmanager/4e78cd9ff1d990fbe1db3f54469aa567d9f908fe