Is there a unified command for checking a disk? <SOLVED>

Questions about hardware, drivers and peripherals
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
gemk65
Level 3
Level 3
Posts: 175
Joined: Thu Feb 09, 2017 2:37 pm

Is there a unified command for checking a disk? <SOLVED>

Post by gemk65 »

Hello!

I'm having trouble finding an answer to this one: Is there a single Terminal command to handle all 5 of the following tasks:

1. On the next computer restart, run a disk check on my (presumably unmounted) Linux system, including the root.
2. During the disk check, fix file system errors (I gather that these can result from crashes).
3. During the disk check, check for bad sectors ("bad blocks").
4. If bad sectors are found, attempt data recovery by rewriting the data to a healthy sector, and then close off the bad sector to any further use.
5. Produce a report and let me know the location of the report file.

I would also like to know whether my system automatically performs one or more of these 5 tasks periodically without my needing to make a special request.

I have:
- Linux Mint 18.1 64-bit
- Cinnamon 3.2.7
- Kernel 4.4.0-53-generic

I have BIOS/Intel and a dual-boot system. The partitions on my 165 GB Hitachi hard disk are as follows:

- Windows XP: /dev/sda1 (82GB; also called NTFS) -- not relevant to this discussion.
- Linux: /dev/sda2 (82GB; also called Extended partition)
- Linux: /dev/sda5 (79GB; used by Linux Mint - also called Ext4)
- Linux Swap: /dev/sda6 (3GB)

I do not currently have a file /forcefsck, though I could easily create one if necessary.
I do not currently have tune2fs.

I do have Gnome Disk Utility and I use it on occasion to perform its "SMART Data & Self-Tests". It reports that my disk is "Old-Age" and "Pre-Fail", though it reports an "OK" assessment on all test parameters. But I don't think that it fixes file system errors or performs data recovery from bad sectors. (It is my understanding that once a bad sector is found, then it is time to buy a new hard disk).

Thank you in advance for any guidance.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
richyrich

Re: Is there a unified command for checking a disk?

Post by richyrich »

This should get you started, e2fsprogs comes pre-installed in Mint . . :)

https://en.wikipedia.org/wiki/Badblocks

ps: please read all you can before using these commands, there are dangers ! (eg: the -w switch and what it does). Man pages are your best friends - https://linux.die.net/man/8/badblocks
Habitual

Re: Is there a unified command for checking a disk?

Post by Habitual »

I use

Code: Select all

sudo touch /forcefsck
and a reboot to "auto-magically" correct FileSystem errors.

Just sayin'
gemk65
Level 3
Level 3
Posts: 175
Joined: Thu Feb 09, 2017 2:37 pm

Re: Is there a unified command for checking a disk? <SOLVED>

Post by gemk65 »

Hello Habitual!

I liked your solution very much and I tried it; it was easy. Could you let me know where I can see the FileSystemCheck report (if one is created) or at least a text line somewhere that declares that the FileSystemCheck was done?

(Sorry if you see this message twice; I'm still getting my bearings using the Linux Mint Forum).
Habitual

Re: Is there a unified command for checking a disk? <SOLVED>

Post by Habitual »

gemk65 wrote:Hello Habitual!

I liked your solution very much and I tried it; it was easy. Could you let me know where I can see the FileSystemCheck report (if one is created) or at least a text line somewhere that declares that the FileSystemCheck was done?

(Sorry if you see this message twice; I'm still getting my bearings using the Linux Mint Forum).
Please don't PM with asking first, and receiving permission second.
We are volunteers. Thank you.

View the "Logs" System Utility for further information.
gemk65
Level 3
Level 3
Posts: 175
Joined: Thu Feb 09, 2017 2:37 pm

Re: Is there a unified command for checking a disk? <SOLVED>

Post by gemk65 »

Thanks, Habitual. Sorry I forgot about the PM rule. Good that you reminded me.

I found, after doing some reading, that the fsck result also seems to be displayed in the file /var/log/boot.log. In this file, I found two text lines that seemed relevant (and were evidently created at the relevant date and time):

Scanning for Btrfs filesystems
/dev/sda5: clean, 257448/4833280 files, 2140571/19320064 blocks

(I don't know why it says my file system is Btrfs, since the command "inxi -Fxz" returns the result that it is ext4).

I cannot find the relevant text line in the syslog file. Do you know what text string I should search? I tried "fsck", "Btrfs", "ext4", "force", and "init", but nothing relevant turned up.
DrM
Level 3
Level 3
Posts: 105
Joined: Sun Feb 23, 2014 4:03 pm

Using badblocks on optical media.

Post by DrM »

The badblocks command can also be used on optical drives to scan your CDs and DVDs for bad sectors. For example "badblocks -tv /dev/sr0" sr0 is the CD-ROM drive. A similar command for scanning optical media is cdck.
Locked

Return to “Hardware Support”