On the basis of answers to this question
what is the command line equivalent of safely remove drive
I wrote this script.
#!/bin/bash
echo "This script works on sdb and sdb1"
echo "Have a look at the following and if all is well continue."
lsblk
read -p "press the Enter key if you want to continue..." key
udisksctl unmount --block-device /dev/sdb1
sudo fsck /dev/sdb1
udisksctl power-off --block-device /dev/sdb
I think the instruction "have a look at the following and if all is well continue" means that if the output from lsblk
shows that the drive that we want to remove is the logical drive sdb1
then continue.
The output from lsblk
is
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
├─sda1 8:1 0 549M 0 part
├─sda2 8:2 0 115.9G 0 part
├─sda3 8:3 0 833M 0 part
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 107.9G 0 part /
└─sda6 8:6 0 7.8G 0 part [SWAP]
sdb 8:16 1 14.5G 0 disk
└─sdb1 8:17 1 14.5G 0 part /media/jack/Flash
sr0 11:0 1 1024M 0 rom
loop0 7:0 0 89.5M 1 loop /snap/core/6130
loop1 7:1 0 89.5M 1 loop /snap/core/6034
loop2 7:2 0 88.2M 1 loop /snap/core/5897
The drive to be removed is indeed the logical drive sdb1
.
This script worked well with Ubuntu 16.04 for the past 2.5 years. I use this script on average about twice a week. Then in December 2018 invoking the script caused my external mouse (Logitech Trackman) to stop working (on 2 occasions) or for Ubuntu to completely hang with a garbled screen (on 1 occasion).
Given that Ubuntu changes via apt
it would seem that either Ubuntu has a new bug or that the script is obsolete. What is the correct solution or the correct script given the state of Ubuntu now.
set -x
after#!/bin/bash
orstrace -f scriptname.sh
to see diagnostic output and pinpoint at which command issues occur. The script shouldn't be obsolete asudisksctl
is still used andfsck
too. If external drive and mouse share same USB hub ( it's quite possible the two ports are in fact on the same hub internally ) it could make sense that both were powered off, though this would need some tracing to be confirmed. Ubuntu changes toapt
seem irrelevant also in this case – Sergiy Kolodyazhnyy Dec 18 '18 at 20:27