Technical differences in storage media
The essential difference between mechanical hard drives and solid-state hard drives
Traditional mechanical hard disks (HDDs) adopt magnetic disks and robotic arm structures, and data is stored on rotating disks and read and write through magnetic heads. This physical characteristic leads to:
- Seeking time (usually several milliseconds)
- Speed indicator (5400/7200/10000RPM)
- Not friendly to random visits
- Significant performance fluctuations
In contrast, solid-state drives (SSDs) use NAND flash chips:
- No mechanical moving parts
- Access time is measured in microseconds
- Excellent random access performance
- Lower power consumption
- However, there is a write life limit
Technical principles for identifying SSDs
Linux systems provide a variety of underlying interfaces to expose storage device features:
- Block device properties: Rotational flag exposed through the /sys file system
- SMART data: Contains manufacturer's logo and device type information
- Performance characteristics: SSD-specific latency and throughput modes
- Kernel recognition: Device properties reported by the driver layer
Detailed explanation of basic identification methods
1. lsblk command: Quickly determine device type
lsblk
It is the simplest and most direct identification tool, by querying the topology information of block devices:
lsblk -d --output NAME,ROTA,SIZE,MODEL
Typical output example:
NAME ROTA SIZE MODEL sda 0 447.1G Samsung SSD 860 EVO sdb 1 1.8T WDC WD2003FZEX-0
Key indicator analysis:
-
ROTA=1
: Rotating Device (HDD) -
ROTA=0
: Non-rotating device (SSD) -
MODEL
Field: Directly display manufacturer and model
Advantages:
- No root permission required
- Instant display of all devices
- Can be combined with other fields (SIZE, TYPE, etc.)
2. /sys file system: query the kernel underlying data
The Linux kernel exposes device properties through the sysfs virtual file system:
cat /sys/block/sda/queue/rotational
Return value analysis:
-
0
:SSD -
1
:HDD
Advanced usage:
find /sys/block -name rotational | xargs -I{} sh -c 'echo {} $(cat {})'
Technical Principles:This value is set by the device driver and reflects the device characteristics recognized by the kernel. For NVMe devices, the kernel is automatically set to 0.
Intermediate identification scheme
3. smartctl tool: deep query SMART data
The smartmontools package providessmartctl
Full SMART information for readable disks:
sudo smartctl -i /dev/nvme0n1
Key information fields:
Rotation Rate: Solid State Device Device Model: INTEL SSDPEKKF256G8L
Installation method:
# Debian/Ubuntu sudo apt install smartmontools # RHEL/CentOS sudo yum install smartmontools
Special case handling:
Some old SSDs may report rotation rates incorrectly, and they need to be judged in combination with other indicators:
sudo smartctl -A /dev/sda | grep -i 'ssd\|solid'
4. hdparm tool: performance characteristics analysis
hdparm can test the basic performance of the equipment:
sudo hdparm -Tt /dev/sda
Typical results comparison:
- SSD: Buffered reading > 500MB/s, direct reading > 300MB/s
- HDD: Buffered read 200-300MB/s, direct read 80-160MB/s
Advanced usage:
sudo hdparm -I /dev/sda | grep Nominal
Advanced Identification Technology
5. fio benchmark test: through performance fingerprint recognition
Characterization analysis is performed using industry standard tools:
sudo fio --filename=/dev/sda --rw=read --bs=4k --iodepth=64 \ --runtime=20 --numjobs=4 --time_based --group_reporting \ --name=ssd_test --output=ssd_result.txt
Indicator analysis:
- SSD: 4K Random Read IOPS Normally >10,000
- HDD: 4K Random Read IOPS Normally <200
Automatic judgment script:
#!/bin/bash DEVICE=$1 RESULT=$(sudo fio --filename=$DEVICE --rw=randread --bs=4k \ --iodepth=1 --runtime=5 --numjobs=1 --time_based \ --group_reporting --name=quick_test --output-format=json | \ jq '.jobs[0].') if (( $(echo "$RESULT > 1000" | bc -l) )); then echo "SSD detected (IOPS: $RESULT)" else echo "HDD suspected (IOPS: $RESULT)" fi
6. Kernel log analysis
Check the device detection record when the system starts:
dmesg | grep -i 'ssd\|nvme\|rotating'
Typical log clues:
[ 2.368104] sd 0:0:0:0: [sda] SSD with 128KiB cache [ 2.752893] sd 2:0:0:0: [sdb] 625142448 512-byte logical blocks (3.00 TB/2.72 TiB) [ 2.752896] sd 2:0:0:0: [sdb] 4096-byte physical blocks [ 2.752899] sd 2:0:0:0: [sdb] Write Protect is off
Production environment practice guide
Example of automated detection scripts
#!/bin/bash check_ssd() { local dev=$1 local sys_rotational local lsblk_rota local smart_model local result="" # Check /sys rotational sys_rotational=$(cat /sys/block/${dev#/dev/}/queue/rotational 2>/dev/null) # Check lsblk lsblk_rota=$(lsblk -d -o ROTA "$dev" | tail -n 1) # Check SMART data if available if command -v smartctl &>/dev/null; then smart_model=$(sudo smartctl -i "$dev" | grep -i 'model\|rotation' | tr '\n' ' ') fi # Determine result if [[ "$sys_rotational" == "0" || "$lsblk_rota" == "0" ]]; then result="SSD" else result="HDD" fi printf "%-8s %-4s (sys:%-1s lsblk:%-1s smart:%-20s)\n" \ "$dev" "$result" "$sys_rotational" "$lsblk_rota" "$smart_model" } # Main execution echo "Device Type Details" echo "======================" for dev in /dev/sd? /dev/nvme?n?; do [[ -e "$dev" ]] || continue check_ssd "$dev" done
Special considerations in container environments
Pay attention to when identifying storage devices in containers:
- The host device file needs to be mounted:
docker run -v /dev:/dev --privileged -it ubuntu bash
- It can be used in Kubernetes environment:
volumes: - name: dev hostPath: path: /dev containers: - securityContext: privileged: true
Cloud environment recognition skills
Virtual disk recognition for mainstream cloud platforms:
- AWS: EBS types can be queried through the API
aws ec2 describe-volumes --volume-ids vol-12345 --query 'Volumes[0].VolumeType'
- Azure: Use LSI logical device name
- GCP: Persistent disks are displayed as SCSI devices
Performance optimization suggestions
Key configuration adjustments after identifying SSDs:
- File system optimization:
# Ext4 recommended mount optionsdefaults,noatime,discard,data=writeback,barrier=0
- Kernel parameter adjustment:
# Improve IO queue depthecho 256 > /sys/block/sda/queue/nr_requests
-
Database optimization:
- MySQL:
innodb_io_capacity=2000
- PostgreSQL:
random_page_cost=1.1
- MySQL:
Scheduler selection:
echo kyber > /sys/block/sda/queue/scheduler
Frequently Asked Questions
1. Deal with the situation of identifying the result conflict
When different tools report inconsistent:
- Check the kernel version (the old kernel may recognize errors)
- Verify that the device passes the RAID controller
- View vendor whitelists (certain enterprise-level SSD emulation HDD features)
2. Identification of hybrid storage environments
For servers that contain multiple storage types:
lsblk -d -o NAME,ROTA,SIZE,MODEL,TRAN | grep -v usb
3. Special handling of NVMe devices
NVMe devices are naturally SSDs and can be checked by special tools:
nvme list sudo nvme smart-log /dev/nvme0
Technology development trends
- ZNS SSD: Emerging partition namespace technology, requiring special recognition methods
- Computational storage: Intelligent SSD with processing capabilities
- Open Channel SSD: The host directly manages the flash memory chip
More professional identification tools may be needed in the future:
sudo nvme zns identify-ns /dev/nvme0n1
Summarize
Accurately identifying SSDs is the first step in Linux system optimization. This article introduces a variety of identification methods from basic to advanced, each solution has its own advantages and disadvantages:
method | accuracy | Complexity | Required Permissions | Applicable scenarios |
---|---|---|---|---|
lsblk | high | Low | User level | Quick check |
/sys query | Extremely high | Low | User level | Script integration |
smartctl | Extremely high | middle | root | Detailed report |
fio test | high | high | root | Performance Verification |
In actual production environment, it is recommended:
- Develop automated inspection scripts for regular audits
- Incorporate storage type information into the CMDB system
- Dynamically adjust system parameters according to device type
- Establish performance baselines to detect abnormalities in a timely manner
With the rapid development of storage technology, administrators need to continuously update their knowledge reserves, master the identification and management methods of new storage devices, and ensure that the system always operates in the optimal state.
The above is the detailed explanation of the SSD disk recognition method in Linux system. For more information about Linux SSD disk recognition, please pay attention to my other related articles!