# EXT errors

## Nicias

I've been getting these errors everyone so often:

```
Dec 09 22:07:17 [kernel] [784634.848851] EXT4-fs (sda3): error count since last fsck: 1

Dec 09 22:07:17 [kernel] [784634.848855] EXT4-fs (sda3): initial error at time 1512259322: ext4_mb_generate_buddy:758

Dec 09 22:07:17 [kernel] [784634.848859] EXT4-fs (sda3): last error at time 1512259322: ext4_mb_generate_buddy:758
```

and earlier:

```
Nov 29 11:19:58 [kernel] [1552192.479561] EXT4-fs (sda3): error count since last fsck: 710

Nov 29 11:19:58 [kernel] [1552192.479565] EXT4-fs (sda3): initial error at time 1511004226: ext4_mb_complex_scan_group:1972

Nov 29 11:19:58 [kernel] [1552192.479569] EXT4-fs (sda3): last error at time 1511596639: ext4_mb_generate_buddy:758
```

```
Nov 28 10:51:58 [kernel] [1464112.095562] EXT4-fs (sda3): error count since last fsck: 710

Nov 28 10:51:58 [kernel] [1464112.095566] EXT4-fs (sda3): initial error at time 1511004226: ext4_mb_complex_scan_group:1972

Nov 28 10:51:58 [kernel] [1464112.095570] EXT4-fs (sda3): last error at time 1511596639: ext4_mb_generate_buddy:758
```

Is this a sign of a bad disk? A bad motherboard? Something else?

This is in a quite-old (it has a Core 2 Duo) laptop with an about 6 year old SSD in it. 

Any suggestions about how to proceed would be helpful.

----------

## NeddySeagoon

Nicias,

Maybe all of these things, maybe none of them.

What other errors are there in dmesg?

Put it all on a pastebin site please.

The output of 

```
smartctl -a /dev/sda
```

would be useful.

Don't run fsck unless you have a known good set of backups.

fsck often makes a bad situation worse.

----------

## Nicias

got a ton of new errors in the last day:

https://pastebin.com/s7KVxKmR

but SMART looks fine.

```
# smartctl -a /dev/sda

smartctl 6.4 2015-06-04 r4109 [x86_64-linux-4.12.12-gentoo] (local build)

Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===

Model Family:     Samsung based SSDs

Device Model:     Samsung SSD 840 Series

Serial Number:    S14CNEACA81371V

LU WWN Device Id: 5 002538 55002d356

Add. Product Id:  00000000

Firmware Version: DXT06B0Q

User Capacity:    120,034,123,776 bytes [120 GB]

Sector Size:      512 bytes logical/physical

Rotation Rate:    Solid State Device

Device is:        In smartctl database [for details use: -P show]

ATA Version is:   ACS-2, ATA8-ACS T13/1699-D revision 4c

SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 3.0 Gb/s)

Local Time is:    Mon Dec 18 06:47:20 2017 EST

SMART support is: Available - device has SMART capability.

SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===

SMART overall-health self-assessment test result: PASSED

General SMART Values:

Offline data collection status:  (0x80)   Offline data collection activity

               was never started.

               Auto Offline Data Collection: Enabled.

Self-test execution status:      (   0)   The previous self-test routine completed

               without error or no self-test has ever 

               been run.

Total time to complete Offline 

data collection:       (  240) seconds.

Offline data collection

capabilities:           (0x53) SMART execute Offline immediate.

               Auto Offline data collection on/off support.

               Suspend Offline collection upon new

               command.

               No Offline surface scan supported.

               Self-test supported.

               No Conveyance Self-test supported.

               Selective Self-test supported.

SMART capabilities:            (0x0003)   Saves SMART data before entering

               power-saving mode.

               Supports SMART auto save timer.

Error logging capability:        (0x01)   Error logging supported.

               General Purpose Logging supported.

Short self-test routine 

recommended polling time:     (   2) minutes.

Extended self-test routine

recommended polling time:     (  30) minutes.

SCT capabilities:           (0x003d)   SCT Status supported.

               SCT Error Recovery Control supported.

               SCT Feature Control supported.

               SCT Data Table supported.

SMART Attributes Data Structure revision number: 1

Vendor Specific SMART Attributes with Thresholds:

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE

  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0

  9 Power_On_Hours          0x0032   095   095   000    Old_age   Always       -       24961

 12 Power_Cycle_Count       0x0032   097   097   000    Old_age   Always       -       2075

177 Wear_Leveling_Count     0x0013   094   094   000    Pre-fail  Always       -       52

179 Used_Rsvd_Blk_Cnt_Tot   0x0013   100   100   010    Pre-fail  Always       -       0

181 Program_Fail_Cnt_Total  0x0032   100   100   010    Old_age   Always       -       0

182 Erase_Fail_Count_Total  0x0032   100   100   010    Old_age   Always       -       0

183 Runtime_Bad_Block       0x0013   100   100   010    Pre-fail  Always       -       0

187 Uncorrectable_Error_Cnt 0x0032   100   100   000    Old_age   Always       -       0

190 Airflow_Temperature_Cel 0x0032   067   053   000    Old_age   Always       -       33

195 ECC_Error_Rate          0x001a   200   200   000    Old_age   Always       -       0

199 CRC_Error_Count         0x003e   100   100   000    Old_age   Always       -       0

235 POR_Recovery_Count      0x0012   099   099   000    Old_age   Always       -       214

241 Total_LBAs_Written      0x0032   099   099   000    Old_age   Always       -       2562291420

SMART Error Log Version: 1

No Errors Logged

SMART Self-test log structure revision number 1

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error

# 1  Short offline       Completed without error       00%      1035         -

# 2  Extended offline    Completed without error       00%      1023         -

# 3  Short offline       Completed without error       00%      1000         -

# 4  Short offline       Completed without error       00%       999         -

# 5  Short offline       Completed without error       00%       975         -

# 6  Short offline       Completed without error       00%       951         -

# 7  Short offline       Completed without error       00%       927         -

# 8  Short offline       Completed without error       00%       903         -

# 9  Short offline       Completed without error       00%       869         -

#10  Extended offline    Completed without error       00%       855         -

#11  Short offline       Completed without error       00%       832         -

#12  Short offline       Completed without error       00%       831         -

#13  Short offline       Completed without error       00%       807         -

#14  Short offline       Completed without error       00%       783         -

#15  Short offline       Completed without error       00%       759         -

#16  Short offline       Completed without error       00%       735         -

#17  Short offline       Completed without error       00%       711         -

#18  Extended offline    Completed without error       00%       687         -

#19  Short offline       Completed without error       00%       664         -

#20  Short offline       Completed without error       00%       663         -

#21  Short offline       Completed without error       00%       633         -

SMART Selective self-test log data structure revision number 1

 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS

    1        0        0  Not_testing

    2        0        0  Not_testing

    3        0        0  Not_testing

    4        0        0  Not_testing

    5        0        0  Not_testing

  255        0    65535  Read_scanning was never started

Selective self-test flags (0x0):

  After scanning selected spans, do NOT read-scan remainder of disk.

If Selective self-test is pending on power-up, resume after 0 minute delay.

```

I have a known good backup.

----------

## NeddySeagoon

Nicias,

There are no underlying drive errors in dmesg nor in smartclt.

If you know your backup is good, remake the filesystem and restore the backup.

If the backup was made with those filesystem errors, you don't know that its good, even if it seems to be.

Try fsck but be warned that all it does it make the filesystem metadata self consistent.  It may trash your user data in the process of fixing the metadata.

That's because in the face of missing or conflicting information, it guesses and it can guess incorrectly.

All the bits that fsck doesn't know what to do with end up in /lost+found, which should always be empty.

You cannot fsck a mounted partition.

----------

## Nicias

I have done fsck as recently as a couple of weeks ago. (from a sysrescuecd usb) 

This is just the system drive, it has no actual data on it, so I'm not worried about data loss. I'd clobber the whole thing and do a reinstall except for the time that would take.

I'll wipe the disk and reinstall from the last backup. Why would these errors keep popping up?

----------

## NeddySeagoon

Nicias,

Unclean shutdows, PSU problems of some sort. Maybe even RAM issues.

Its worth a few cycles of memtest86.  Be aware that memtest86 uses most of the rest of the system, so not all errors reported by memtest are due to RAM.

----------

## Nicias

I'll run memtest and see what if finds. The machine is an old laptop. It never shuts down on its own, comes unplugged, or has the power drop.

----------

## Nicias

Memtest ran for 24 hours and found no errors.

fsck found a ton of errors on sda3. sdb1 had no errors. sda is an internal sata ssd. sdb1 is externally (usb) attached spinning rust.

Any suggestions? Bad drive? Bad motherboard/controler?

----------

## Ant P.

Could also be a bad cable, but any of those things would likely show up in the SMART logs.

----------

## NeddySeagoon

Nicias,

Bad SSD firmware ?

Do you use trim/discard?

There are SSDs with problem firmware where trim can erase the wrong things.

There is one famous example where LBA 0 (the boot sector) would be trimmed, making the system impossible to boot.

-- edit --

Hmm ... 

```
Device Model:     Samsung SSD 840 Series
```

Lets just add that that device has some history

----------

## Nicias

I don't have trim or discard set.

So it seems like maybe I should get a new drive :/

----------

## NeddySeagoon

Nicias,

I wouldn't go that far yet.

You have 

```
Model Family:     Samsung based SSDs

Device Model:     Samsung SSD 840 Series 
```

with 

```
Firmware Version: DXT06B0Q
```

Is there a newer firmware?

What does it fix?

This tool may help. Its probably Windows only.

In increasing order of risk.

Its worth doing nothing, and see if the problems recur.

Its worth making a new filesystem and restoring from backup.

That will issue a trim command to the entire partition at the start of mke2fs.

If the backup is not known to be good, it may not help.

Reinstall after making a new filesystem.

Very last - update the drive firmware, if there is an update.

----------

## Nicias

The backup is file-level not file-system level.  Doesn't that mean that if it is an accurate copy of a bad file-system that it will just have files that are screwed up, not a corrupted file-system?

So if I reformat the drive, recreate the file system and restore from backup then I might just have some bad files, not a bad file-system. In that case would doing a emerge -e world (and recompile the kernel) fix those files?

----------

## NeddySeagoon

Nicias,

That's correct.

You run the risk that something important like glibc is broken, so you won't be able to boot, or something in the toolchain is broken, so you won't be able to build packages.

However, challenges like that can be fixed if they arise.  

You would have noticed both of those particular examples already though but you get the idea.

Its possible that the restored backup will not work as expected.

----------

## Nicias

Thanks! Wish me luck!

----------

## NeddySeagoon

Nicias,

Good luck!

----------

## Nicias

So far everything is running smoothly.

Reformatted and reinstalled from backup, then rebuilt toolchain, kernel, and world. Now doing the gcc upgrade for PIE (and world rebuild) no fs errors yet. When this world rebuild is done I'll reboot to a live usb to check for fs errors.

In terms of trim/discard, it seems like best practice is to do that via a cron job. Is this correct?

----------

## NeddySeagoon

Nicias,

There are divided opinions on the use of trim/discard.

Once you issue a trim command, your data can be removed by the drive at any time.  

There is generally no possibility of recovering data from trimmed space. 

If that might matter to you, run fstrim manually when you are sure you wont want anything back.

Beware that some drives take a long time to become ready after a fstrim.

I have one that takes over 10min.  If they are online, that's fine, if you reboot, you might get a fright as the drive seems to have failed.

Personally, I have the discard option in /etc/fstab but only the installed system is on the SSD.

/home is on rotating rust, so trim/discard does not apply.

----------

## Nicias

NeddySeagoon,

There is not data on the SSD here either, so I put a daily fstrim cron job. 

Thanks for all of your help. After it finished emerging, I restarted from a thumb drive. Checked the filesystems, no errors. Hopefully this fixes it.

-Nick

----------

## NeddySeagoon

Nicias,

We don't know what happened, so cannot take any steps to stop it happening again.

All you can do is to watch for the errors recurring.

----------

## Jaglover

The hours on the drive are near to 25,000, last test was ran at 1,000.

----------

## Nicias

And it's back:

```
Jan 07 03:20:37 [kernel] [126524.735529] EXT4-fs warning (device sda3): ext4_trim_all_free:5185: Error -117 loading buddy information for 305

Jan 07 04:23:56 [kernel] [130323.424237] EXT4-fs (sda3): error count since last fsck: 1

Jan 07 04:23:56 [kernel] [130323.424241] EXT4-fs (sda3): initial error at time 1515230488: ext4_mb_generate_buddy:756

Jan 07 04:23:56 [kernel] [130323.424245] EXT4-fs (sda3): last error at time 1515230488: ext4_mb_generate_buddy:756

fstrim: /: FITRIM ioctl failed: Structure needs cleaning
```

Maybe time for a firmware update?

----------

## Nicias

Firmware update seems to have solved the problem. No ext errors in almost two months.

----------

