Windows.  Viruses.  Laptops.  Internet.  Office.  Utilities.  Drivers

I also had to face this problem. My one friend who has installed Ubuntu like an old one ASUS laptop, and who simply doesn’t want to use his brain sometimes, came to me with such a problem. The new Ubuntu 12.10 is installed on his laptop and very often the system simply does not want to boot, throwing it into a black screen or freezing on a purple background. But recently this message started popping up, something like “The operating system was unable to boot. Select for further actions the desired key..." And then there is a description of what needs to be pressed. I don’t remember exactly which keys the system suggests pressing, but the meaning is that to automatically correct errors, press such and such a key, for manual debugging another, and to ignore this message you are asked to press a third button. Automatic error correction did not lead to anything and the loading of the operating system never reached its logical conclusion. So I decided to try the famous team fsck.

First you need to boot from either bootable flash drive with Ubuntu (Lubuntu, Xubuntu, Kubuntu, etc.), or with Ubuntu disk Live CD. Now we need to find out which Ubuntu partition we need to scan to fix it file system. Launch Terminal (Ctrl-Alt-T) and execute the command:

sudo fdisk -l

This command will show us all the disks and flash drives that are mounted to the system. I'll give an example with my personal computer, and not with a friend's laptop. Here's what I got:

ubuntu@ubuntu:~$ sudo fdisk -l

Disk /dev/sda: 640.1 GB, 640135028736 bytes
255 heads, 63 sectors/track, 77825 cylinders, total 1250263728 sectors



Disk identifier: 0x0009d6f7


/dev/sda1 * 2048 61442047 30720000 83 Linux
/dev/sda2 61442048 73730031 6143992 82 Linux swap / Solaris
/dev/sda3 73730048 1250263039 588266496 83 Linux

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb9ff6f01

Device Boot Start End Blocks Id System
/dev/sdb1 * 16065 100197404 50090670 83 Linux
/dev/sdb2 105322201 976771071 435724435+ 5 Extended
/dev/sdb3 100197405 105322139 2562367+ 82 Linux swap / Solaris
/dev/sdb5 105322203 832110591 363394194+ 7 HPFS/NTFS/exFAT
/dev/sdb6 832112640 860755218 14321289+ 83 Linux
/dev/sdb7 860758016 862613503 927744 82 Linux swap / Solaris
/dev/sdb8 862615552 976771071 57077760 83 Linux

Partition table entries are not in disk order

Disk /dev/sdc: 8115 MB, 8115978240 bytes
250 heads, 62 sectors/track, 1022 cylinders, total 15851520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc3072e18

Device Boot Start End Blocks Id System
/dev/sdc1 * 32 15847625 7923797 b W95 FAT32

As you can see from the command output sudo fdisk -l, I have 2 hard drives(sda)640 GB and (sdb)500 GB, as well as a flash drive (sdc)8GB, from which I actually booted. I know that my base system with Ubuntu 12.04 is located on the sda ​​disk, and the partition with the operating system is called sda1.

Now that we know the partition that needs to be scanned, we can actually start checking it. In the Terminal:

sudo fsck -y -f -c /dev/sda1

If you see an error, you most likely need to unmount this partition:

sudo umount /dev/sda1

Command keys and parameters fsck:

y- always answer yes to all questions (there is an alternative: key p - starts checking in fully automatic mode);

f- forced check of the file system (even if the file system is marked as fully functional)

c- looks for bad blocks, and then marks them accordingly

/dev/sda1- device or partition that needs to be checked. Although the team may have a different appearance. For example:

sudo fsck -p /dev/sda1

IN in this case only the -p switch has been added. You just read about all the fsck command keys and add exactly the keys you need. To find out about all the program's capabilities, enter in the Terminal:

man fsck

This is what the Terminal produced after checking:

ubuntu@ubuntu:~$ sudo fsck -y -f -c /dev/sda1
fsck from util-linux 2.20.1
e2fsck 1.42.5 (29-Jul-2012)
Checking for bad blocks (read-only test): 0.00% done, 0:00 elapsed. (0/0/0 errdone
/dev/sda1: Updating bad block inode.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

Did Linus Torvalds, when creating his brainchild, imagine that Linux would be used in embedded systems, not only in cheap home routers, but also in such serious telecom solutions as AVAYA PBX?

Recently we had to restore the functionality of the AVAYA PBX of one large Customer. This is an Avaya G650 gateway (chassis) with an Avaya S8400 server (processor). Where in quality system disk 2 GB CompactFlash media is used. Which can be considered conditionally SSD disk with IDE interface.
And imagine my surprise when, having connected the CF drive through a card reader, I saw a familiar structure Linux file systems. Which, of course, simplified the procedure for checking the functionality of the CF drive.

How to check a Linux disk file system for errors

The MicroSoft DOS operating system (oh yes, I remember version 5.0, which fit on one floppy disk!) had a CHKDSK disk check command. And something similar exists in Linux.
To check Linux disk For file system errors, you need to find out the file system names to check:

# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda 20G 4.0G 15G 21% / /dev/sdd1 1G 455M 555M 46% /media/Np%blsl3648B4Jjeiedgyy /dev/sdd6 1G 98M 902M 10% /media/ 10.13-23dd none 246M 0 246M 0% /dev/shm

For the tested drive, CF is /dev/sdd1 And /dev/sdd6
Next, you need to unmount the file systems under test:

#sudo umount /dev/sdd1 #sudo umount /dev/sdd6

#fsck -y /dev/sdd1 #fsck -y /dev/sdd6

Parameter -y will automatically answer yes to all questions, which is what most users usually do.

Results of the Lunux FSCK file system check utility

In my case, there were errors on one of the partitions, which the utility corrected. After which the CF drive was returned to its place and the functionality of the Avaya PBX was restored.

Any computer is a complex device that consists of many components and no one is immune from failures of any of them. In this article we will look at how to promptly recognize one of the serious problems with information storage devices, whether HDD or a flash drive, how a disk is checked for bad sectors in linux.

Any drive consists of many small blocks (sectors) that store information in the form of zeros or ones (bits). If, for some reason, operating system cannot write a bit of information to a certain sector, then it can be considered “broken”.

A sector can become damaged for various reasons:

  • Manufacturing defects
  • Turn off the computer's power while recording information.
  • Physical wear and tear of the drive.

A small number of bad sectors are found on almost any drive. But it is worth paying attention if their number increases over time. This may indicate the imminent physical death of the drive and it’s time for you to think about replacing it.

Let's look at which Linux utilities we can use to check a disk for bad Linux sectors.

Checking the drive for bad sectors using badblocks.

Badblocks - standard utility Linux to check for bad sectors. It is installed by default in almost any distribution and can be used to check both a hard drive and an external drive.

First, let's look at what drives are connected to our system and what partitions they have. To do this, we need another standard Linux utility - fdisk.

Naturally, you need to execute commands with superuser rights:

Parameter -l we tell fdisk that we need to show the list of partitions and exit.

Now that we know what partitions we have, we can check them for bad sectors. To do this we will use the badblocks utility as follows:

$ sudo badblocks -v /dev/sda1 > badsectors.txt

To check, we specify the following parameters:

  • -v— detailed output of information about the test results.
  • /dev/sda1- the section that we want to check for bad sectors.
  • > badsectors.txt— output the result of the command to the badsectors.txt file.

If, as a result, bad sectors were found, then we need to instruct the operating system not to write information to them in the future. For this we need Linux utilities for working with file systems:

  • e2fsck. If we fix a partition with Linux file systems (ext2,ext3,ext4).
  • fsck. If we patch a file system other than ext.

Enter the following commands:

$ sudo e2fsck -l badsectors.txt /dev/sda1

Or, if our file system is not ext:

$ sudo fsck -l badsectors.txt /dev/sda1

Parameter -l we tell the utility to use the list of bad sectors from the file badsectors.txt, which we obtained earlier when checking with the badblocks utility.

Checking a drive for bad sectors in Linux in smartmontools

Now let's look at a more modern and reliable way check the disk for bad linux sectors. Modern ATA/SATA, SCSI/SAS, SSD drives have a built-in self-monitoring system S.M.A.R.T (Self-Monitoring, Analysis and Reporting Technology, Self-monitoring, analysis and reporting technology), which monitors drive parameters and will help determine the deterioration of drive parameters in the early stages. To work with S.M.A.R.T in Linux there is a smartmontools utility.

Let's install it first. If your distribution is based on Debian\Ubuntu, then enter:

$ sudo apt install smartmontools

If you have a distribution based on RHEL\CentOS, then enter:

$ sudo yum install smartmontools

by Admin

Let's look at ways to check and diagnose hdd in linux systems. Information about HDD operation will help analyze the status and, if necessary, replace the failed media, thereby preventing system crash or data loss. Additionally, we add monitoring of smart HDD to our zabbix monitoring system

We get a list of connected drives in the system

To determine what is mounted where, let’s do

Look busy place on one or another drive

If there is a soft ride, let's check it with the following command

root@big:~# cat /proc/mdstat
Personalities:
md1: active raid1 sdb3 sda3
965888832 blocks super 1.2

md0: active raid1 sdb1 sda1
9756544 blocks super 1.2
unused devices:
root@big:~#

what raid is installed (assembled)
md0- raid device name
sda sdb- included devices in this raid
- state of disks in the RAID array

Install the necessary packages

aptitude install hdpparm sysstat smartmontools

We look at the read speed status from the drive

With help iostat(as part of sysstat) we analyze the load on our HDDs

We look at the data output for all disks at intervals of 10 seconds

You can define the drive to analyze by adding

Using this utility, we will determine the load on our devices, I/O statistics and percentage utilization.

avg-cpu: %user %nice %system %iowait %steal %idle
0,16 0,00 1,89 23,75 0,00 74,21

Checking the status of drives

First, let's check our HDD for bad blocks, if necessary, select them and mark them to be ignored.

badblocks /dev/sda3 -sv > /root/badblockSDA3
Checking for bad blocks (read-only test): 27.93% done, 36:12 elapsed. (0/0/0 errors)

/dev/sda3- name of the device being tested
s- displaying percentage information
v- turn on verbose mode
> /root/badblockSDA3- write bad sectors to a file

Marking bad blocks (in the future, marked blocks will be ignored by the system):

e2fsck -l /root/badblockSDA3 /dev/sda3

Bad blocks are marked and you can work with the disk.

ATTENTION!!! This operation must be performed on an unmounted media or in read-only mode

ATTENTION!!! The verified device and the device on which will be marked bad blocks must be the same!

We receive S.M.A.R.T data on HDD operation

Where /dev/sdX is the name of the device that needs to be checked.
You will get the output of the S.M.A.R.T. attributes, the meaning of each of which is well described in the wiki

Monitoring S.M.A.R.T status of hard drives in Zabbix

For each drive we check SMART support

root@big:~# smartctl -i /dev/sda |grep SMART
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
root@big:~#

If it is supported but not enabled, then enable it

smartctl -s on -S on -o on /dev/sda

check the status with the command

smartctl -H /dev/sda |grep "test"| cut -f2 -d: |tr -d " "

root@big:/etc/zabbix# smartctl -H /dev/sda |grep "test"| cut -f2 -d: |tr -d " "
PASSED
root@big:/etc/zabbix#

IN configuration file zabbix agent agent enable the smart check parameter for the disk

UserParameter=HDD_smart.[*],sudo smartctl -H /dev/$1 |grep "test"| cut -f2 -d: |tr -d " "

Where HDD_smart- key for zabbix element

V sudoers add an entry

zabbix ALL=NOPASSWD:/usr/sbin/smartctl

restart sudo and zabbix agent.

To be sure of correctness, let’s log in as a zabbix user and check the execution of our command

root@big:/etc/zabbix# su - zabbix -s /bin/bash
Directory missing or inaccessible, login with HOME=/
zabbix@big:/$ sudo smartctl -H /dev/sda |grep "test"| cut -f2 -d: |tr -d " "
PASSED
zabbix@big:/$

Let's create a zabbix agent on the zabbix server ( Active) data element

Name- arbitrary
Type- Zabbix agent (Active)
Key- HDD_smart. - for the first disk, for the second, respectively...
Type- Symbol

And after some time we observe the data

If, during boot, the operating system reports that there are errors in the file system on one of the partitions, then you should immediately check the disks and correct the file system errors.

Any self-respecting user should not forget that periodic checking hard drives for bad sectors and checking disks for errors is an example of common sense.

Important! Launch and Execution FSCK on a mounted file system may cause data corruption, soUse this material at your own risk. The author is not responsible for any damage you may cause.

In order to protect yourself you need to:

  • Switch to Single user mode and unmount the file system
  • Boot your computer into recovery mode using the installation CD

So, you need to check the disks and fix file system errors, let's get started.

1) Single user mode

Change the initialization level and unmount the file system:

# init 1
# umount /home

Search for connected partitions:

# fsck /dev/sda1

2) Recovery mode from installation CD

Insert the installation CD into the drive and reboot the system:

Wait a while and after booting from the installation CD, run the command:

# linux rescue nomount

The NOMOUNT directive will disable mounting, so you can safely use FSCK.

After this, run FSCK on the partition with errors:

# fsck -yvf /dev/sda1

LVM (Logical Volume Manager)

The situation with LVM (Logical Volume Manager) sections are a little more complicated. For start FSCK For LVM partitions must first be found PV (Physical Volume), VG (Volume Group), LV (Logical Extension) and activate them, to do this, run the following commands in sequence:

# lvm pvscan
# lvm vgscan
# lvm lvchange -ay VolGroup00
# lvm lvscan

# fsck -yfv /dev/VolGroup00/LogVol00

Upon execution, FSCK will return the result in the form of code, this code is a unique number representing the sum of the following values:

0 - No errors;
1 - Filesystem errors corrected;
2 - System should be rebooted;
4 - Filesystem errors left uncorrected;
8 - Operational error;
16 - Errors when using or syntax errors(Usage or syntax error);
32 - Fsck canceled by user request;
128 - Shared-library error.

If you notice an error, select a piece of text and press Ctrl+Enter
SHARE: