does not find devices by label/uuid
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pmount (Ubuntu) |
Fix Released
|
Medium
|
Vincent Fourmond |
Bug Description
Binary package hint: pmount
Problem when mounting fixed harddrives (partitions).
Hello,
I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC.
The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://
It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back.
"Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs.
When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount.
$ man pmount
I studied the source code of "pmount" utility and found at least two errors or "lack of functionality".
=========
Error 1:
=========
Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab.
It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions.
This my /etc/fstab.
$ cat /etc/fstab
# -------
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# /dev/sda1
UUID=465f0fb2-
# /dev/sda5
LABEL=BIGGY /media/sda5 ext3 defaults 0 2
# /dev/sda8
UUID=4c6f9d6b-
/dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0
/dev/ /media/floppy0 auto rw,user,noauto 0 0
# -------
As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that.
I downloaded source code for "pmount" program from
http://
It contains code for "pumount" as well.
Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both.
Let's examine these errors:
Download source code for "pmount".
Open "pmount.c" file and stydy the code in "main()" function.
The fstab_has_
.....
fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL );
if( mode == MOUNT && fstab_device ) {
if( arg2 )
return E_EXECMOUNT;
}
.....
-------
Open "policy.c" file and study the fstab_has_
I have added code that converts UUID= and LABEL= to the actual device name.
Eg. "UUID=465f0fb2-
and "LABEL=BIGGY" will give device name "/dev/sda5".
These changes reguire "libblkid-dev" library.
$ sudo apt-get install libblkid-dev
and include
#include <blkid/blkid.h>
Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration.
I just modified the Makefile and changed
LIBS = -lsysfs -lblkid
---
All new lines are marked with numbers 1 - 50.
const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid )
{
FILE* f;
struct mntent *entry;
char pathbuf[PATH_MAX];
static char fstab_device[
char* realdev;
char* uidopt;
1 blkid_cache blk_cache;
2 char *ret_type, *ret_val;
3 char *dev_name;
4
5 blkid_dev blk_dev;
if( !( f = fopen( fname, "r" ) ) ) {
perror( _("Error: could not open fstab-type file") );
exit( 100 );
}
while( ( entry = getmntent( f ) ) != NULL ) {
6 /* Get blkid_cache handle for /etc/blkid.tab file */
7 if (blkid_
8 {
9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") );
10 }
11
12 ret_type = ret_val = NULL;
13 blkid_parse_
14
15 if (!ret_val)
16 {
17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */
18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */
19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname );
20 }
21 else
22 {
23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */
24 /* Eg: UUID=160f3620-
25
26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */
27
28 debug("
29
30 blk_dev = NULL;
31 blk_dev = blkid_find_
32
33 /* blk_dev = blkid_verify(
34
35 if (blk_dev)
36 {
37 dev_name = blkid_dev_
38
39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name);
40
41 debug("
42
43 /* string_
44 }
45 }
46
47
48 /* if (blk_cache) --- Should we free this cache ??
49 blkid_free_
50 */
if( realpath( fstab_device, pathbuf ) )
realdev = pathbuf;
else
realdev = fstab_device;
if( !strcmp( realdev, device ) ) {
if( mntpt ) {
}
if( uid ) {
}
}
}
/* just for safety */
if( mntpt )
*mntpt = 0;
endmntent( f );
return NULL;
}
-------
I uploaded the code to
http://
Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main().
It performs the command similar to this:
$ sudo mount /dev/sda1
Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid:
$ sudo mount -U 465f0fb2-
and
$ sudo mount -L BIGGY
Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly.
-------
==============
Possible error 2:
==============
get_root() function does not give proper ROOT rights.
Mount command fails due to lack of root privileges. That's my theory ;-)
Study pmount's "utils.c" file, function get_root().
void get_root()
{
if( setreuid( -1, 0 ) ) {
perror( _("Internal error: could not change to effective uid root") );
exit( 100 );
}
}
I think that it should be
setresuid(0, 0, 0); or similar
instead of
setreuid(-1, 0);
At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the
execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..."
----
Anyway, I must study this issue more thoroughly.
Notice that "pmount" must have setuid (s) bit set.
The correct access rights are:
$ ls -l /usr/bin/pmount
-rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount
This is how to set the rights (group plugdev is a must in Debian and Ubuntu).
$ sudo chown root:plugdev pmount
Setuid (s bit)
$ sudo chmod 4754 pmount
-------
System information:
$ cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_
DISTRIB_
DISTRIB_
Ordninary 32 bits Edgy Eft.
$ uname -a
Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux
--- the end ----
Related report:
o--> https:/
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
The problem that pmount does not find UUID/LABEL mounts is already known, as you pointed out. Thanks a lot for your code contribution to fix this!
However, pmount is *designed* to not mount static fixed hard disk partitions for security reasons. It works pretty hard to ensure that the device to be mounted is indeed removable, otherwise the user could easily mess up system partitions, peek in other /home directories, etc.
The latter problem needs to be addressed in a different way, we'll talk about this on the next conference:
https:/ /features. launchpad. net/distros/ ubuntu/ +spec/mount- all-local- filesystems