Eject / safely remove vs umount
If you are using systemd
then use udisksctl
utility with power-off
option:
power-off
Arranges for the drive to be safely removed and powered off. On the OS side this includes ensuring that no process is using the drive, then requesting that in-flight buffers and caches are committed to stable storage.
I would recommend first to unmount all filesystems on that usb. This can be done also with udisksctl
, so steps would be:
udisksctl unmount -b /dev/sda1
udisksctl power-off -b /dev/sda
If you are not using systemd
then old good udisks
should work:
udisks --unmount /dev/sda1
udisks --detach /dev/sda
umount
is perfectly safe for the disk. Once you've done that you have successfully unmounted the filesystem and you needn't worry along those lines. The primary difference between eject and umount
doesn't concern the disk at all - rather it is about the USB port's 5v power output.
After umount
you can still see your disk listed in lsblk
because it is still powered on and attached. umount
an internal hard disk's file-system and you'll see the same behavior for the same reason. But when you eject a USB device you power it down and it ceases to draw the 5v it would typically - I think it trickles down to .5v but that class happened a long time ago.
lsblk -f /dev/disk/by-id/usb-SanDisk_Cruzer_200522428118F4325EC2-0:0
NAME FSTYPE LABEL UUID MOUNTPOINT
sdd
├─sdd1 vfat USBESP 3AD6-C7CC
└─sdd2 ext4 USBROOT 5afbfe93-6955-44ec-8c4f-cf381f8ef174
Here is its usb bus path...
cat /sys/bus/usb/devices/5-3/manufacturer
SanDisk
Even though I almost never mount it, it's been plugged in and blinking for a long time, I guess...
cat /sys/bus/usb/devices/5-3/power/{level,connected_duration}
on
1777877440
I should do something about that:
echo 1 | sudo tee /sys/bus/usb/devices/5-3/remove
Now I'll have a look at it again...
cat /sys/bus/usb/devices/5-3/power/level
cat: /sys/bus/usb/devices/5-3/power/level: No such file or directory
Hmmm...
lsblk -f /dev/disk/by-id/usb-SanDisk_Cruzer_200522428118F4325EC2-0:0
lsblk: /dev/disk/by-id/usb-SanDisk_Cruzer_200522428118F4325EC2-0:0: not a block device