Eight solutions for Linux hard disk problems

  

Can't write data on the hard disk of Linux or UNIX-like systems? Want to solve the problem of disk corruption on the server? Want to know why you always see the words "Disk is full" on the screen? Want to learn how to deal with these problems? Try these 8 tips for solving Linux and UNIX server hard drive problems.

#1 - Error: No free space on the device

When your UNIX-like system disk is full, you will see this message on the screen. In this case, I run the fallocate command and my system will prompt that the disk space is exhausted:
$ fallocate -l 1G test4.imgfallocate: test4.img: fallocate failed: No space left on device

first The step is to run the df command to view the total disk space and free space of a partitioned file system:
$df

or try a more readable output format:
$df -h

Partial output:
Filesystem Size Used Avail Use% Mounted on/dev/sda6 117G 54G 57G 49% /udev 993M 4.0K 993M 1% /devtmpfs 201M 264K 200M 1% /runnone 5.0M 0 5.0M 0 % /run/locknone 1002M 0 1002M 0% /run/shm/dev/sda1 1.8G 115M 1.6G 7% /boot/dev/sda7 4.7G 145M 4.4G 4% /tmp/dev/sda9 9.4G 628M 8.3G 7 % /var/dev/sda8 94G 579M 89G 1% /ftpusers/dev/sda10 4.0G 4.0G 0 100% /ftpusers/tmp

Using the df command output, you can clearly see that the total is 4.0 under the /dev/sda10 partition. The space of Gb is completely filled.

Fixing disk fullness problems

1. Compress uncompressed logs and other files with gzip, bzip2 or tar commands:
gzip /ftpusers/tmp/*.logbzip2 /ftpusers /tmp/large.file.name

2. Use the rm command to delete unwanted files on a UNIX-like system:
rm -rf /ftpusers/tmp/*.bmp

3. Move with the rsync command Files to other systems or external hard drives:
rsync --remove-source-files -azv /ftpusers/tmp/*.mov /mnt/usbdisk/rsync --remove-source-files -azv /ftpusers/tmp/*.mov server2:/path/to/dest/dir/

4. Find the directory or file that has the most disk space in a UNIX-like system:
du -a /ftpusers/tmp |  Sort -n -r |  Head -n 10du -cks * |  Sort -rn |  Head

5. Clear the specified file. This trick is very effective for log files:
truncate -s 0 /ftpusers/ftp.upload.log### bash/sh etc##>/ftpusers/ftp.upload.log## perl ##perl -e 'truncate "filename", LENGTH'

6. Find and delete large files that have been displayed but have been deleted in Linux and UNIX:
## Based on Linux/Unix/OSX/BSD, etc.## Lsof -nP |  Grep '(deleted)'## is based only on Linux ##find /proc/*/fd -ls |  Grep '(deleted)'

Clear it:
## Based on Linux/Unix/OSX/BSD and other systems##> "/path/to/the/deleted/file.name"## Based on Linux ##> "/proc/PID-HERE/fd/FD-HERE"

#2 - Is the file system read-only?

When you try to create or save a file, you may end up with an error such as the following:
$ cat > file-bash: file: Read-only file system

Run the mount command Check if the mounted file system is read-only:
$ mount$ mount |  Grep '/ftpusers'

To fix this problem in a Linux-based system, simply remount the file system in read-only mode:
# mount -o remount,rw /ftpusers/tmp

(LCTT: If the hard disk fallsback to read-only mode due to hardware failure, it is recommended not to change back to read-write mode, but to replace the hard disk quickly)

In addition, I re-hang it in rw mode The root directory of the FreeBSD 9.x server:
# mount -o rw /dev/ad0s1a /

#3 - Am I running out of inodes?

Sometimes the df command can display The disk has free space but the system claims that the file system is full. At this point you need to check the inode that identifies the file and its properties in the file system:
$ df -i$ df -i /ftpusers/

Partial output:
Filesystem Inodes IUsed IFree IUse% Mounted on/dev/sda8 6250496 11568 6238928 1% /ftpusers

There is a total of 62,50,496KB inodes under /ftpusers but only 11,568KB is used. You can create additional files of size 62, 38, 928KB in the /ftpusers location. If your index node is 100% used, try the following options:
Find out unwanted files and delete them, or move them to other servers. Find out the big file you don't want and delete it, or move it to another server.

(LCTT: If a partition stores too many small files, the inode will run out and the storage sector will be idle. In this case, either the small file is cleared or the independent access is not required. Package them into a large file; either re-partition the data and set the -t news attribute of the partition to increase the inode allocation)

#4 - Is my hard drive smashed?

Input/output errors in the log file (eg /var/log/messages) indicate that the hard disk has some problems and may have expired. You can use the smartctl command to view the hard disk errors. This is a class. A command to control and monitor the state of a hard disk under a UNIX system. The syntax is as follows:
smartctl -a /dev/DEVICE# Check under Linux server /dev/sda smartctl -a /dev/sda

You can also use the "Disk Utility" software to get the same information.

Figure 01: Gnome Disk Utility (Applications & gt; System Tools & gt; Disk Utility)

Note: Do not expect too much on the SMART tool, it can not work under certain conditions We have to do backups on a regular basis.

#5 - Is my hard drive and server too hot?

High temperatures can cause servers to be inefficient, so you need to keep your servers and disks at a steady, appropriate temperature, which can even cause server downtime or damage to file systems and disks. Use hddtemp or smartctl to find out the hard drive temperature on your Linux or UNIX-based system by reading data from a hard disk that supports the S.M.A.R.T. function. Only modern hard drives have temperature sensors. The hddtemp function also supports reading S.M.A.R.T. information from a SCSI drive. hddtemp can be acquired as a simple command-line tools or from all the server daemon information:
hddtemp /dev /DISKhddtemp /dev /sg0

output portion follows:

FIG. 02: hddtemp is running

You can also use the smartctl command as shown below:
smartctl -d ata -A /dev/sda |  Grep -i temperature

How do I get the CPU temperature

You can use Linux hardware monitoring tools, such as the lm_sensor function based on Linux to get the CPU temperature:
sensors

Debian server the partial output:

FIG. 03: sensors command provides a CPU core temperature Linux computer and other information

# 6 - treated damaged file system

The file system on the server may be corrupted due to a hardware reboot or some other error such as a bad sector. You can use the fsck command to repair a corrupted filesystem:
umount /ftpusersfsck -y /dev/sda8

to see more information on how to deal with Linux file system failures.

#7 - Handling Soft Arrays in Linux

Enter the following command to view the recent state of the Linux soft array:
## Get the details of the disk array on /dev/md0# #mdadm --detail /dev /md0 ## check the status of ## cat /proc /mdstatwatch cat /proc /mdstat

partial output:

Figure 04: View Linux software command array state

You need to replace the faulty hardware driver, don't delete it. In this case, I replaced /dev/sdb (the second hardware drive in RAID 6). There is no need to rely on offline storage files to repair disk arrays on Linux, as this only works if your server supports hot-swappable hard disks:
## Remove disks from an md0 array##mdadm --manage /dev/md0 --fail /dev/sdb1mdadm --manage /dev/md0 --remove /dev/sdb1# Do the same for the rest of /dev/sdbX### Perform a shutdown if it is not a hot swappable hard drive ##shutdown -h now## Copy the partition table from /dev/sda to the new /dev/sdb##sfdisk -d /dev/sda |  Sfdisk /dev/sdbfdisk -l## Add##mdadm --manage /dev/md0 --add /dev/sdb1# Do the same for the rest of /dev/sdbX### Now md0 will sync again, through the display Screen View ## watch cat /proc/mdstat

Take a look at the tips for speeding up the synchronization of Linux disk arrays for more information.

#8 - Handling Hard Arrays

You can use the samrtctl command or vendor-specific commands to view the status of the disk array and the disks you manage:
## SCSI Disks smartctl -d scsi --all /dev/sgX## Adaptec Disk Array /usr/StorMan/arcconf getconfig 1## 3ware Disk Array tw_cli /c0 show

Replace your failed disk against vendor specific documentation.

Copyright © Windows knowledge All Rights Reserved