LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 06-21-2014, 09:25 PM   #1
Archy1
Member
 
Registered: Jan 2014
Distribution: Debian
Posts: 95

Rep: Reputation: 2
Ejecting eSATA & SATA drives.


I have a SATA to SATA drive caddy taking up one of my 5.25" bays so that I can hot-swap my SATA drives on the fly.

Since Linux saw the drive as internal (how would it know?) normal users can't mount any of the partitions. I fixed that with udev:
Code:
udevadm info -q path -n /dev/sdb
# Replace sdb with the relevant drive.
# The stuff after "host4/" is not relevent and will be replaced with a wildcard.

nano /etc/udev/rules.d/10-esata.rules
	# [nano]
	DEVPATH=="/devices/pci0000:00/0000:00:1f.2/host4/*", ENV{UDISKS_SYSTEM_INTERNAL}="0"
	# Replace "/devices/pci0000:00/0000:00:1f.2/host4/*" with the output of "udevadm info -q path -n /dev/sdb"
	# [/nano]

udevadm control --reload-rules
Yay, now Linux will list it as an external device and I'll have the option to safely eject my drives! Except while that fixed the "standard user mounting problem," it didn't fix the safely eject problem.

After doing some research on the Internet I came across this set of commands to safely eject an eSATA/SATA drive:
Code:
# replace all instances of sdb with the relevant drive
# unmount everything (is there a command to unmount all partitions of a drive?)
sync
hdparm -y /dev/sdb
echo offline > /sys/block/sdb/device/state
echo 1 > /sys/block/sdb/device/delete
# take drive out of caddy
That is great but of course standard users can't eject drives that way.

Is there any way to eject a SATA drive that a standard user could utilize without sudo privileges? Kinda like with USB flash drives?

Relevant installed software:
Debian 7.5 amd64
LXDE desktop (full install)
pcmanfm
gnome-disk-utility

Last edited by Archy1; 06-22-2014 at 04:36 PM. Reason: spelling
 
Old 06-22-2014, 11:32 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Hey Archy,


From the eject man page
Quote:
Eject first SCSI device:

eject sda
Though you'd want to use" eject -n (no ops, test only) -v (verbose) sdb" to test the process.
 
Old 06-22-2014, 02:24 PM   #3
widget
Senior Member
 
Registered: Oct 2008
Location: S.E. Montana
Distribution: Debian Testing, Stable, Sid and Manjaro, Mageia 3, LMDE
Posts: 2,628

Rep: Reputation: 497Reputation: 497Reputation: 497Reputation: 497Reputation: 497
Quote:
Originally Posted by dijetlo View Post
Hey Archy,


From the eject man page

Though you'd want to use" eject -n (no ops, test only) -v (verbose) sdb" to test the process.
And if that works the way you want you should be able to add it to the menu options in your file manager.
 
Old 06-22-2014, 05:16 PM   #4
Archy1
Member
 
Registered: Jan 2014
Distribution: Debian
Posts: 95

Original Poster
Rep: Reputation: 2
Code:
$ eject -v /dev/sdb
eject: device name is `/dev/sdb'
eject: expanded name is `/dev/sdb'
eject: `/dev/sdb' is not mounted
eject: `/dev/sdb' is not a mount point
eject: `/dev/sdb' is a multipartition device
eject: using device name `/dev/sdb' for ioctls
eject: unable to open `/dev/sdb'
As root:
Code:
# eject -v /dev/sdb
eject: device name is `/dev/sdb'
eject: expanded name is `/dev/sdb'
eject: `/dev/sdb' is not mounted
eject: `/dev/sdb' is not a mount point
eject: `/dev/sdb' is a multipartition device
eject: using device name `/dev/sdb' for ioctls
eject: trying to eject `/dev/sdb' using CD-ROM eject command
eject: CD-ROM eject command failed
eject: trying to eject `/dev/sdb' using SCSI commands
eject: SCSI eject failed
eject: trying to eject `/dev/sdb' using floppy eject command
eject: floppy eject command failed
eject: trying to eject `/dev/sdb' using tape offline command
eject: tape offline command failed
eject: unable to eject, last error: Inappropriate ioctl for device
 
Old 06-22-2014, 07:07 PM   #5
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Hi Archy

Could you post the output of the mount command (just "#mount", you don't have to sudo to run it) as well as your /etc/fstab? How many partitions on this disk have mount points in the local file system?
The other thing I'm wondering is, mounting and umounting are one thing, removing a drive from powered bay is another. Once you've umounted the partitions on sdb, the files system wont care what happens to them however the hard drive may not react well to being powered down like that. If you've already thought of that and made allowances (tolerant drives, for example) don't worry about it.
 
Old 06-27-2014, 12:51 PM   #6
Archy1
Member
 
Registered: Jan 2014
Distribution: Debian
Posts: 95

Original Poster
Rep: Reputation: 2
Output of mount with sdb inserted, powed on, and unmounted:
Code:
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,relatime,size=10240k,nr_inodes=2052916,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=1643716k,mode=755)
/dev/mapper/d--t-lvroot on / type ext4 (rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=3287420k)
/dev/sda2 on /boot type ext2 (rw,relatime,errors=continue)
/dev/sda1 on /boot/efi type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=utf8,shortname=mixed,errors=remount-ro)
/dev/mapper/d--t-lvhome on /home type ext4 (rw,relatime,user_xattr,barrier=1,data=ordered)
/dev/mapper/d--t-tmp on /tmp type ext4 (rw,relatime,user_xattr,barrier=1,stripe=4,data=ordered)
/dev/mapper/d--t-usr on /usr type ext4 (rw,relatime,user_xattr,barrier=1,data=ordered)
/dev/mapper/d--t-var on /var type ext4 (rw,relatime,user_xattr,barrier=1,data=ordered)
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
/dev/sr0 on /media/cdrom0 type iso9660 (ro,nosuid,nodev,noexec,relatime,user=archy)
Output of /etc/fstab:
Code:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/d--t-lvroot /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda2 during installation
UUID=bafae4a0-3a0e-41b5-9847-30a92590087a /boot           ext2    defaults        0       2
# /boot/efi was on /dev/sda1 during installation
UUID=C93D-3E54  /boot/efi       vfat    defaults        0       1
/dev/mapper/d--t-lvhome /home           ext4    defaults        0       2
/dev/mapper/d--t-tmp /tmp            ext4    defaults        0       2
/dev/mapper/d--t-usr /usr            ext4    defaults        0       2
/dev/mapper/d--t-var /var            ext4    defaults        0       2
/dev/mapper/d--t-lvswap none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0
Quote:
Originally Posted by dijetlo View Post
How many partitions on this disk have mount points in the local file system?
What are you asking? The SATA HDD in the external bay is mounted like a flash drive (when it is mounted) in a sub-folder of /media.

Quote:
Originally Posted by dijetlo View Post
The other thing I'm wondering is, mounting and umounting are one thing, removing a drive from powered bay is another. Once you've umounted the partitions on sdb, the files system wont care what happens to them however the hard drive may not react well to being powered down like that. If you've already thought of that and made allowances (tolerant drives, for example) don't worry about it.
Before removing the HDD from the external bay, I always first unmount all partitions on the drive, execute the script "sync; hdparm -y /dev/sdb; echo offline > /sys/block/sdb/device/state; echo 1 > /sys/block/sdb/device/delete" to spin the drive down and remove the driver from the system, I then power down the hard drive via external SATA bay power switch, and then physically remove the drive. This works fine and is safe, but the problem is not drive safety, it's letting normal users safely eject SATA drives without sudo privileges just like they can do with flash drive. When I connect SATA drives to the computer with a USB "converter" I can from gnome-disk-utility (safely) power down the drive without root access or sudo privileges. This is what I want to do but with SATA drives connected to SATA ports (though it doesn't necessarily have to be done via gnome-disk-utility). The HDD, the HDD bay, and the motherboard all support hot-plugging so there are no hardware or firmware issues.

Last edited by Archy1; 06-27-2014 at 12:53 PM.
 
Old 06-27-2014, 05:36 PM   #7
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
It's seeing the drive as a multi-partition, so I was just wondering are we trying to umount a single mount point of a multi-mount drive (sdb1 is /home, sdb2 is /usr/local/, sdb3 is...etc) and that's why it's failing.
Did you try to run eject against the mount point in /media?
The reason I keep coming back to eject is hdparm and ioctls are both going to require root access, so it seems like we're going to have to find a way to do this with "eject" if you're going to get it working for average users.
 
Old 06-27-2014, 07:42 PM   #8
Archy1
Member
 
Registered: Jan 2014
Distribution: Debian
Posts: 95

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by dijetlo View Post
It's seeing the drive as a multi-partition, so I was just wondering are we trying to umount a single mount point of a multi-mount drive (sdb1 is /home, sdb2 is /usr/local/, sdb3 is...etc) and that's why it's failing.
Standard users can eject the partitions just fine, it's powering down the device for safe removal that's the problem.

QUESTIONS: If all partitions are unmounted, would it be safe to just cut the power to the drive and then remove it?

Quote:
Originally Posted by dijetlo View Post
Did you try to run eject against the mount point in /media?
Code:
$ eject -v /media/63537a60-caf0-4c35-9de7-78c8540828f4/
eject: device name is `/media/63537a60-caf0-4c35-9de7-78c8540828f4'
eject: expanded name is `/media/63537a60-caf0-4c35-9de7-78c8540828f4'
eject: `/dev/sdb1' is mounted at `/media/63537a60-caf0-4c35-9de7-78c8540828f4'
eject: unmounting device `/dev/sdb1' from `/media/63537a60-caf0-4c35-9de7-78c8540828f4'
eject: `/dev/sdb1' is a multipartition device
eject: using device name `/dev/sdb' for ioctls
eject: unable to open `/dev/sdb'
Whoh! Eject just unmounted a partition! But this doesn't power down the device for safe removal

Example of USB eject:
Code:
$ eject -v /dev/sdc
eject: device name is `/dev/sdc'
eject: expanded name is `/dev/sdc'
eject: `/dev/sdc' is not mounted
eject: `/dev/sdc' is not a mount point
eject: `/dev/sdc' is a multipartition device
eject: unmounting `/media/A0DA-F24F'
eject: unmounting `/media/root'
eject: using device name `/dev/sdc' for ioctls
eject: trying to eject `/dev/sdc' using CD-ROM eject command
eject: CD-ROM eject command succeeded
Quote:
Originally Posted by dijetlo View Post
The reason I keep coming back to eject is hdparm and ioctls are both going to require root access, so it seems like we're going to have to find a way to do this with "eject" if you're going to get it working for average users.
I just discovered a command called "udisks" which can power down drives with the command "udisks --detach /dev/sdx" and does not require root access.

Let's try it on a SATA drive:
Code:
$ udisks --detach /dev/sdb
Detach failed: Device is not detachable
On a USB drive:
Code:
$ udisks --detach /dev/sdc

$ #No text displayed.

$ ls /dev/sdc?
ls: cannot access /dev/sdc?: No such file or directory

$ #Yay!
I wonder if it is possible to make udev view the hot-pluggable SATA port as detachable just as it was possible to make udev allow drives connected to that SATA port to be mounted, unmounted, and formatted by non root users without sudo access with:
Code:
udevadm info -q path -n /dev/sdb
# Replace sdb with the relevant drive.
# The stuff after "host4/" is not relevent and will be replaced with a wildcard.

nano /etc/udev/rules.d/10-esata.rules
	# [nano]
	DEVPATH=="/devices/pci0000:00/0000:00:1f.2/host4/*", ENV{UDISKS_SYSTEM_INTERNAL}="0"
	# Replace "/devices/pci0000:00/0000:00:1f.2/host4/*" with the output of "udevadm info -q path -n /dev/sdb"
	# [/nano]

udevadm control --reload-rules

Last edited by Archy1; 06-27-2014 at 07:52 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues with pci-e esata card disconnecting drives. Springs Linux - Hardware 0 11-28-2012 01:44 PM
Disks getting caught when ejecting and the quality of drives mechanical construction. stf92 General 4 05-31-2011 11:18 PM
Is there a way to identify if a disk is SATA/eSATA. sridhargdm Linux - General 1 03-09-2010 07:03 AM
PCI SATA 2P eSATA/SATA namit Linux - Hardware 1 10-30-2008 05:39 PM
hot swappable esata drives cygnus-x1 Linux - Hardware 2 01-29-2008 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 05:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration