1

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.

H2ONaCl
  • 10,039

1 Answers1

0

This is a known problem. Some kernels hang the OS. Details are at this link.

Since it is a kernel problem you can cause it to happen regardless of whether you use the GUI or the command line to "safely remove".

To quote from the linked page:

This is known problem with latest 4.4.0-139-generic, 4.4.0-140-generic and 4.4.0-141-generic Linux kernels. On launchpad it is known as bug 1803929 (currently confirmed by 5 users).

The temporary solution is to use 138 ( 4.4.0-138-generic ) kernel.

H2ONaCl
  • 10,039