** Description changed: Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet 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://www.futuredesktop.org/images/Add-to- panel2.png ) picture if you do not know about "Disk Mounter" applet. 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-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /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. + correct mount when there is UUID or LABEL in the first field. The code + has no ability to resolve the actual device name via "/etc/blkid.tab" + file. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount 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_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" 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[PATH_MAX]; 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_get_cache(&blk_cache, NULL) != 0) 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_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 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-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c 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-f7c6-41e3-b35b-a4110adc3fc2 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 "utils.c", get_root() function. 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_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" 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 ----
** Description changed: Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet 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://www.futuredesktop.org/images/Add-to- panel2.png ) picture if you do not know about "Disk Mounter" applet. 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-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /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. The code - has no ability to resolve the actual device name via "/etc/blkid.tab" + correct mount when there is UUID or LABEL in the first field. Pmount + has no ability to find the actual device name via "/etc/blkid.tab" file. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount 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_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" 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[PATH_MAX]; 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_get_cache(&blk_cache, NULL) != 0) 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_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 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-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c 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-f7c6-41e3-b35b-a4110adc3fc2 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 "utils.c", get_root() function. 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_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" 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 ---- -- Problem when mounting fixed harddrives (partitions) https://launchpad.net/bugs/69087 -- ubuntu-bugs mailing list ubuntu-bugs@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs