DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
$ 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
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.
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
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
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.
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.
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
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.