要檢查 Linux 系統(tǒng)中的磁盤錯(cuò)誤,可使用 fsck 和 smartctl 工具。1. 使用 fsck 檢查文件系統(tǒng)錯(cuò)誤,需先卸載分區(qū)再執(zhí)行 sudo fsck /dev/sdX1,支持參數(shù) -t 指定文件系統(tǒng)類型、-y 自動(dòng)修復(fù)、-n 僅查看問題;注意不要對(duì)掛載的根分區(qū)操作,除非在 recovery 模式下。2. 使用 smartctl 檢測(cè)硬盤健康狀態(tài),需先安裝 smartmontools,檢查 SMART 狀態(tài)、啟用 SMART 后運(yùn)行全面檢測(cè),并查看自檢結(jié)果;若 Reallocated_Sector 或 Pending_Sector 不為 0,說明硬盤有壞道。3. 定期監(jiān)控磁盤狀態(tài),可通過 cron 定期執(zhí)行檢測(cè)并發(fā)送報(bào)告,或使用 dmesg、journalctl 查看內(nèi)核日志中的磁盤錯(cuò)誤信息,也可借助 GNOME 等桌面環(huán)境自帶的磁盤工具進(jìn)行圖形化監(jiān)控。
檢查 Linux 系統(tǒng)中的磁盤錯(cuò)誤其實(shí)不難,但很多人不知道具體怎么操作。如果你發(fā)現(xiàn)系統(tǒng)運(yùn)行變慢、文件讀寫異?;蛘哳l繁崩潰,可能就是磁盤出問題了。這時(shí)候,手動(dòng)檢查磁盤錯(cuò)誤就能提前發(fā)現(xiàn)問題,避免數(shù)據(jù)丟失。

使用 fsck
檢查文件系統(tǒng)錯(cuò)誤
fsck
是 Linux 下最常用的文件系統(tǒng)檢查工具,可以用來修復(fù)磁盤錯(cuò)誤。不過它最好在系統(tǒng)啟動(dòng)時(shí)運(yùn)行,或者在文件系統(tǒng)卸載的狀態(tài)下執(zhí)行,否則可能會(huì)有風(fēng)險(xiǎn)。
使用方法如下:

- 停止對(duì)目標(biāo)分區(qū)的訪問,比如卸載分區(qū):
sudo umount /dev/sdX1
- 然后運(yùn)行:
sudo fsck /dev/sdX1
常見參數(shù)說明:
-t
指定文件系統(tǒng)類型,比如-t ext4
-y
自動(dòng)回答“是”以便自動(dòng)修復(fù)-n
不做修改,只查看問題
注意:別對(duì)正在掛載的根分區(qū)直接操作,除非你是在 recovery 模式下。

用 smartctl
檢測(cè)硬盤健康狀態(tài)
fsck
主要檢查文件系統(tǒng),而 smartctl
可以用來查看硬盤本身的物理狀態(tài)。它屬于 smartmontools
包,很多發(fā)行版默認(rèn)沒裝,需要手動(dòng)安裝。
安裝后,你可以這樣檢查:
- 查看硬盤是否支持 SMART:
sudo smartctl -i /dev/sdX
- 啟用 SMART(如果被禁用):
sudo smartctl -s on /dev/sdX
- 運(yùn)行一次全面檢測(cè):
sudo smartctl -t long /dev/sdX
- 查看檢測(cè)結(jié)果:
sudo smartctl -l selftest /dev/sdX
如果發(fā)現(xiàn)硬盤有 Reallocated_Sector 或者 Pending_Sector 數(shù)值不為 0,說明硬盤已經(jīng)開始出現(xiàn)壞道,建議盡快備份數(shù)據(jù)。
定期監(jiān)控磁盤狀態(tài)的小技巧
除了手動(dòng)檢查,還可以設(shè)置一些自動(dòng)監(jiān)控手段,避免問題積累:
- 利用
cron
定期運(yùn)行smartctl
檢測(cè),并把結(jié)果發(fā)到郵箱 - 安裝
smartmontools
后,它的服務(wù)默認(rèn)會(huì)每天掃描一次 - 使用
dmesg
或journalctl
查看內(nèi)核日志中是否有磁盤錯(cuò)誤信息,比如:dmesg | grep -i error
另外,有些桌面環(huán)境(比如 GNOME)自帶磁盤工具,也可以圖形化查看磁盤健康狀態(tài)和運(yùn)行 SMART 測(cè)試。
基本上就這些方法了。雖然看起來有點(diǎn)步驟,但每一步都不復(fù)雜,關(guān)鍵是定期檢查,別等硬盤掛了才想起來看。
The above is the detailed content of how to check for disk errors in linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

Firefox browser is the default browser for most modern Linux distributions such as Ubuntu, Mint, and Fedora. Initially, its performance might be impressive, however, with the passage of time, you might notice that your browser is not as fast and resp

When encountering DNS problems, first check the /etc/resolv.conf file to see if the correct nameserver is configured; secondly, you can manually add public DNS such as 8.8.8.8 for testing; then use nslookup and dig commands to verify whether DNS resolution is normal. If these tools are not installed, you can first install the dnsutils or bind-utils package; then check the systemd-resolved service status and configuration file /etc/systemd/resolved.conf, and set DNS and FallbackDNS as needed and restart the service; finally check the network interface status and firewall rules, confirm that port 53 is not

If you find that the server is running slowly or the memory usage is too high, you should check the cause before operating. First, you need to check the system resource usage, use top, htop, free-h, iostat, ss-antp and other commands to check CPU, memory, disk I/O and network connections; secondly, analyze specific process problems, and track the behavior of high-occupancy processes through tools such as ps, jstack, strace; then check logs and monitoring data, view OOM records, exception requests, slow queries and other clues; finally, targeted processing is carried out based on common reasons such as memory leaks, connection pool exhaustion, cache failure storms, and timing task conflicts, optimize code logic, set up a timeout retry mechanism, add current limit fuses, and regularly pressure measurement and evaluation resources.

As a system administrator, you may find yourself (today or in the future) working in an environment where Windows and Linux coexist. It is no secret that some big companies prefer (or have to) run some of their production services in Windows boxes an

Frankly speaking, I cannot recall the last time I used a PC with a CD/DVD drive. This is thanks to the ever-evolving tech industry which has seen optical disks replaced by USB drives and other smaller and compact storage media that offer more storage

In Linux systems, 1. Use ipa or hostname-I command to view private IP; 2. Use curlifconfig.me or curlipinfo.io/ip to obtain public IP; 3. The desktop version can view private IP through system settings, and the browser can access specific websites to view public IP; 4. Common commands can be set as aliases for quick call. These methods are simple and practical, suitable for IP viewing needs in different scenarios.

Built on Chrome’s V8 engine, Node.JS is an open-source, event-driven JavaScript runtime environment crafted for building scalable applications and backend APIs. NodeJS is known for being lightweight and efficient due to its non-blocking I/O model and
