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

Questions about hardware,drivers and peripherals
Forum rules
Before you post please read how to get help
Post Reply
gemk65
Level 2
Level 2
Posts: 95
Joined: Thu Feb 09, 2017 2:37 pm

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

Post by gemk65 » Sat Apr 15, 2017 9:32 am

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 gemk65 on Sat Apr 15, 2017 12:40 pm, edited 1 time in total.

User avatar
richyrich
Level 19
Level 19
Posts: 9075
Joined: Mon May 04, 2009 8:31 pm

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

Post by richyrich » Sat Apr 15, 2017 10:20 am

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
Level 13
Level 13
Posts: 4870
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

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

Post by Habitual » Sat Apr 15, 2017 11:04 am

I use

Code: Select all

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

Just sayin'

gemk65
Level 2
Level 2
Posts: 95
Joined: Thu Feb 09, 2017 2:37 pm

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

Post by gemk65 » Sat Apr 15, 2017 1:33 pm

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
Level 13
Level 13
Posts: 4870
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

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

Post by Habitual » Sun Apr 16, 2017 8:05 am

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 2
Level 2
Posts: 95
Joined: Thu Feb 09, 2017 2:37 pm

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

Post by gemk65 » Sun Apr 16, 2017 2:06 pm

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 2
Level 2
Posts: 87
Joined: Sun Feb 23, 2014 4:03 pm

Using badblocks on optical media.

Post by DrM » Mon Mar 19, 2018 5:32 pm

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.

Post Reply

Return to “Hardware Support”