Fix detect HDDs and thinking about the elephant in the room
I have posted about detecting if a drive is solid-state or rotating-platters (HDD):
https://bkhome.org/news/202012/put-disabled-hdd-into-deep-sleep-mode.html
https://bkhome.org/news/202003/easyos-clean-shutdown-and-ssd-trim.html
I was very surprised a couple of days ago, to discover that the Linux kernel thinks USB flash drives are HDDs!
I searched online and found that this "bug" has always been there. In the initrd, the kernel correctly identifies the NMVE PCIe internal drive on my PC as not-rotational, and the internal HDD as rotational -- but, reports the external USB flash stick as rotational.
In most Linux distributions, there is a udev rule to post-process
this, and report correctly. I say "most", but don't really know
what distributions have an appropriate udev rule. I think that
some distributions have a udev rule that just sees if it is a USB
drive and assumes non-rotational.
In the initrd, there is no udev, so I have modified the detection like this, in the 'init' script:
HDDflg="$(cat /sys/block/${WKG_DRV}/queue/rotational)"
if [ "$HDDflg" != "0" ];then #0 it is an SSD
#20220522 the kernel gets it right for internal nvme ssd, wrong for usb flash...
hdparm -I /dev/${WKG_DRV} | grep -q 'Solid State Device'
[ $? -eq 0 ] && HDDflg="0"
fi
Note, the full 'hdparm' utility is required, as the busybox one cannot detect USB drives.
Banishing the elephant
Changing the subject completely, I posted yesterday about rethinking the architecture of EasyOS:
https://bkhome.org/news/202205/a-rethink-of-easyos-architecture.html
What I ignored in that post is the "elephant in the room", which
is containers. They will be writing directly to the
working-partition. To remove writes to the drive would require a
zram top-layer for each container, similar to how it is done in
the above link.
In the back of my mind was the thought, take the elephant out of the room. In other words, remove the inbuilt support for containers.
Yes, I know that container support has been an integral feature of EasyOS right from the start in 2017. However, other security strategies have emerged, such as running each application as its own user (and in the case of Firefox and seaMonkey they already have their own sandboxes, which are light-weight containers). Also there is bootup and run totally in RAM, with the option of disabling drives. And now, this new zram top layer, which disconnects from the drive and allows shutdown without saving -- which is another security measure.
EDIT 2022-05-26:
No, hdparm is bad news, it only works with SATA drives. I
originally tested "hdparm -I /dev/sdb" on my SanDisk Extreme
64GB USB3.0 stick, and it worked. However, later I tested on a
SanDisk Extreme 64GB USB3.1 stick, and it failed. Tested on
other USB-sticks, all fail. Tested on USB NVME stick, fail. USB
HDD, success. USB SATA SSD, success.
The 'lsblk' utility does not help, as it only reads /sys/block/sdb/queue/rotational.
Weird, but it looks like there is no
consistent way to determine if a USB drive is solid state.
Perhaps a read-speed test that would require the HDD head to
move right across the platter?
Tags: easy