ldm icon indicating copy to clipboard operation
ldm copied to clipboard

Feature: eject without root

Open Nidrop opened this issue 3 years ago • 3 comments

Eject requires root privilegies. It will be nice if ldmc take care of ejecting device without root. It is relevant for external HDD's to spin-down the drive

Nidrop avatar Apr 21 '21 23:04 Nidrop

What's the output of eject -v /dev/whatever? Adding the whole code of eject.c into ldm is a no-go and you can't use the callback facility as the scripts are not executed as root... I'll have to think of how to implement this.

LemonBoy avatar Apr 22 '21 09:04 LemonBoy

I don't have HDD with me now, but there is output from USB stick if needed:

user@user-pc:~$ sudo eject -v /dev/sdc
eject: имя устройства - '/dev/sdc'
eject: /dev/sdc: не примонтирован
eject: /dev/sdc: is whole-disk device
eject: /dev/sdc: trying to eject using CD-ROM eject command
eject: CD-ROM eject command failed
eject: /dev/sdc: trying to eject using SCSI commands
eject: SCSI eject succeeded

Also the author of pmount wrote the article about how he implements safe removal feature long time ago, maybe it helps

Nidrop avatar Apr 22 '21 15:04 Nidrop

now I have 2 external HDDs: Seagate: ST1000LM048-2E7172 and Western Digital: WD5000LMVW-11VEDS2. Both works differently. Also I found that hdparm can change power mode: -S for active/idle, -y for standby, -Y for sleeping.

Seagate after eject it left in lsblk output and in active/idle power state:

[user@user-pc ~]$ lsblk
NAME         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda            8:0    1  14,4G  0 disk 
├─sda1         8:1    1   150M  0 part 
└─sda2         8:2    1  14,3G  0 part 
sdb            8:16   0 931,5G  0 disk 
└─sdb1         8:17   0 931,5G  0 part 
mmcblk0      179:0    0  29,1G  0 disk 
├─mmcblk0p1  179:1    0   300M  0 part /boot/efi
├─mmcblk0p2  179:2    0     4G  0 part [SWAP]
└─mmcblk0p3  179:3    0  24,8G  0 part /
mmcblk0boot0 179:8    0     4M  1 disk 
mmcblk0boot1 179:16   0     4M  1 disk 
[user@user-pc ~]$ sudo eject -v /dev/sdb
eject: имя устройства - `/dev/sdb'
eject: /dev/sdb: не примонтирован
eject: /dev/sdb: is whole-disk device
eject: /dev/sdb: trying to eject using CD-ROM eject command
eject: CD-ROM eject command failed
eject: /dev/sdb: trying to eject using SCSI commands
eject: SCSI eject succeeded
[user@user-pc ~]$ lsblk
NAME         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda            8:0    1  14,4G  0 disk 
├─sda1         8:1    1   150M  0 part 
└─sda2         8:2    1  14,3G  0 part 
sdb            8:16   0 931,5G  0 disk 
└─sdb1         8:17   0 931,5G  0 part 
mmcblk0      179:0    0  29,1G  0 disk 
├─mmcblk0p1  179:1    0   300M  0 part /boot/efi
├─mmcblk0p2  179:2    0     4G  0 part [SWAP]
└─mmcblk0p3  179:3    0  24,8G  0 part /
mmcblk0boot0 179:8    0     4M  1 disk 
mmcblk0boot1 179:16   0     4M  1 disk 
[user@user-pc ~]$ sudo hdparm -C /dev/sdb

/dev/sdb:
 drive state is:  active/idle

switching power states works fine:

[user@user-pc ~]$ sudo hdparm -S 0 /dev/sdb

/dev/sdb:
 setting standby to 0 (off)
[user@user-pc ~]$ sudo hdparm -C /dev/sdb

/dev/sdb:
 drive state is:  active/idle
[user@user-pc ~]$ sudo hdparm -y /dev/sdb

/dev/sdb:
 issuing standby command
[user@user-pc ~]$ sudo hdparm -C /dev/sdb

/dev/sdb:
 drive state is:  standby

Also when sleeping mode is active, it takes 10-15 seconds to wake it up with -C command. After waking up it is in standby mode.

Western Digital eject does not work:

[user@user-pc ~]$ sudo eject -v /dev/sdb
eject: имя устройства - `/dev/sdb'
eject: /dev/sdb: не примонтирован
eject: /dev/sdb: is whole-disk device
eject: /dev/sdb: trying to eject using CD-ROM eject command
eject: CD-ROM eject command failed
eject: /dev/sdb: trying to eject using SCSI commands
eject: SCSI eject failed
eject: /dev/sdb: trying to eject using floppy eject command
eject: floppy eject command failed
eject: /dev/sdb: trying to eject using tape offline command
eject: tape offline command failed
eject: невозможно извлечь

hdparm output looks unpromising but works mostly ok:

[user@user-pc ~]$ sudo hdparm -C /dev/sdb

/dev/sdb:
SG_IO: bad/missing sense data, sb[]:  70 00 01 00 00 00 00 0a 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 drive state is:  unknown
[user@user-pc ~]$ sudo hdparm -y /dev/sdb

/dev/sdb:
 issuing standby command
SG_IO: bad/missing sense data, sb[]:  70 00 01 00 00 00 00 0a 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[user@user-pc ~]$ sudo hdparm -Y /dev/sdb

/dev/sdb:
 issuing sleep command
SG_IO: bad/missing sense data, sb[]:  70 00 01 00 00 00 00 0a 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

I heard the disk stop in standby mode. Sleeping mode takes time to wake up but it seems it can't completely wake up after that, subsequent commands with this drive take more time to execute.

Summary Eject can't spin-down the drive. I suggest using standby power mode. I'm not sure about sleeping mode, who knows how it will work with other devices.

Nidrop avatar Jun 28 '21 20:06 Nidrop