On 5/1/26 01:34, [email protected] wrote:
"Alexander V. Makartsev"<[email protected]> wrote:
On 5/1/26 00:30,[email protected] wrote:
I have some USB-attached HDDs connected to a laptop running Debian
12. Recently I had a problem ejecting them using the file manager
and the Disks app, something on the drives was still "in use" even
when I had closed every open application.
Since then I've learned of the existence of 'lsof', but at the time
my experience of Windows and macOS suggested that, under these
kinds of circumstances, performing a shutdown will clear the holds
on the drives and cleanly eject them during the process. So as I
didn't know what else to do I shut down Debian using the menu.
The last thing I saw before the laptop powered off was a series of
messages reporting that both external drives had failed to unmount
cleanly, and this was confirmed by the nasty clunking noise from
the drives indicating sudden parking of the drive heads when the
USB power was unexpectedly removed. Following this incident I've
had to recover some several GBs of files from each drive.
Obviously this wasn't a very pleasant experience, so I'd like to
know what steps I can take to make Debian act more responsibly in
future.
IM(H)O part of the problem was that the first thing to get torn
down during the shutdown was the GUI, which meant that there was no
way for a user to intervene if there was a problem with ejecting
the drives cleanly. Windows and macOS will prompt the user using
the GUI if there's a problem that means a drive can't be
automatically ejected cleanly during a shutdown, giving users an
opportunity to abort. Can I modify the Debian shutdown sequence to
keep the GUI available until all drives are safely ejected?
I'd welcome any other suggestions to make Debian less likely to
cause data loss on external drives during shutdown.
It is a good habit to issue "sync" command, before disconnecting any
USB storage devices.
Some storage devices have very slow write speeds, so you have to wait
for the "sync" command to finish syncing cached writes.
When it finishes you can run it again, just to be sure it worked and
it should finish in an instant.
Now you can safely unmount and then physically disconnect USB storage
devices.
Why doesn't the OS run synce twice on every storage device when it's
shutting down?
I'm guessing "umount" command is just as good to safely unmount
filesystems during shutdown, but the actual process (systemd units?)
that does it could be getting interrupted by timeout.
IIRC 1 minute 30 seconds is the default timeout for systemd units.
If a slow USB storage device has a few gigabytes of cached writes it
won't make it in time.
SATA\M.2 connected storage devices are not affected because they are
many times faster and the connection is more robust.
I've never actually tested this and never tried to shutdown a PC with a
few terabytes of pending writes to the root filesystem.
Like I said, I have a good habit to type "sync" whenever I need to flush
all cached writes to all storage devices and it never failed me.
As an additional thought, there could be something wrong with the OP's
HDD drive, like bad\remapped sectors, or any other issue, making its
write speed even slower.
--
With kindest regards, Alexander.
Debian - The universal operating system
https://www.debian.org