Tips for solving eight Linux hard drive problems
Cannot I write data to a Linux or UNIX-like hard disk? Do you want to solve the problem of disk damage on the server? Want to know why you always see the word "Disk Full" on the screen? Do you want to learn how to solve these problems? Try these eight tips to solve the hard drive problem of Linux and UNIX servers.
#1-error: no space left on the device
When your UNIX-like system disk is full, you will see such information on the screen. In this example, I run the fallocate command and then my system will prompt that the disk space is exhausted:
- $ Fallocate-l 1G test4.img
- Fallocate: test4.img: fallocate failed: No space left on device
The first step is to run the df command to view the total disk space and available space of a partitioned File System:
- $ Df
Or try a readable output format:
- $ Df-h
Some output content:
- FilesystemSizeUsedAvailUse % Mounted on
- /Dev/sda6 117G54G57G49%/
- Udev 993M4. 0K993M1%/dev
- Tmpfs 201m1_k200m1%/run
- None 5.0M05.0M0%/run/lock
- None 1002M01002M0%/run/shm
- /Dev/sda1 1.8G115M1.6G7%/boot
- /Dev/sda7 4.7G145M4.4G4%/tmp
- /Dev/sda9 9.4g628m8.20.7%/var
- /Dev/sda8 94G579M89G1%/ftpusers
- /Dev/sda10 4.0g4.00000100%/ftpusers/tmp
Using the df command output, we can clearly find that the total space of GB in the/dev/sda10 partition is full.
Fixed the problem of Disk Full writing.
1. Use the gzip, bzip2, or tar command to compress uncompressed logs and other files:
- Gzip/ftpusers/tmp/*. log
- Bzip2/ftpusers/tmp/large. file. name
2. Use the rm command in UNIX-like systems to delete unwanted files:
- Rm-rf/ftpusers/tmp/*. bmp
3. Use the rsync command to move files to other systems or external hard disks:
- 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 occupies the most disk space in UNIX-like systems:
- Du-a/ftpusers/tmp | sort-n-r | head-n 10
- Du-cks * | sort-rn | head
5. Clear the specified file. This method is very effective for log files:
- Truncate-s 0/ftpusers/ftp. upload. log
- ### Bash/sh ##
- >/Ftpusers/ftp. upload. log
- # Perl ##
- Perl-e 'truncate "filename", length'
6. Find and delete large files displayed but deleted in Linux and UNIX:
- # Linux/Unix/OSX/BSD-based systems ##
- Lsof-nP | grep '(deleted )'
-
- # Only based on Linux ##
- Find/proc/*/fd-ls | grep '(deleted )'
Clear it:
- # Linux, Unix, OSX, BSD, and other systems ##
- > "/Path/to/the/deleted/file. name"
- # Only based on Linux ##
- > "/Proc/PID-HERE/fd/FD-HERE"
#2-is the file system in read-only mode?
When you try to create or save a file, you may eventually get the following errors:
- $ Cat> file
- -Bash: file: Read-only file system
Run the mount command to check whether the mounted file system is in the read-only status:
- $ Mount
- $ Mount | grep '/ftpusers'
To fix this problem in a Linux-based system, you only need to remount the read-only file system:
- # Mount-o remount, rw/ftpusers/tmp
(LCTT Note: if the hard disk fallback to read-only mode due to hardware failure, we recommend that you do not forcibly change back to read/write mode, but replace the hard disk quickly)
In addition, I re-mount the root directory of the FreeBSD 9.x server in rw mode as follows:
- # Mount-o rw/dev/ad0s1a/
#3-Am I running out of inodes?
Sometimes, the df command shows the available space on the disk, but the system claims that the file system is full. In this case, you need to use the following command to check the index nodes that can identify files and their attributes in the file system:
- $ Df-I
- $ Df-I/ftpusers/
Some output content:
- FilesystemInodesIUsedIFreeIUse % Mounted on
- /Dev/sda8 62504961156862389281%/ftpusers
The above/ftpusers has a total of 11,568, 50, and 496KB index nodes, but only KB is used. You can create a, kb file at the/ftpusers location. If your index node 100% is used, try the following options:
- Find an unwanted file and delete it, or move it to another server.
- Find a large file you don't want and delete it, or move it to another server.
(LCTT Note: If a partition stores too many small files, the inode is used up and the storage sector is idle, in this case, you can either clear small files or package them into a large file without independent access; or save the data and repartition it, and set the-t news attribute of the partition to add inode allocation)
#4-is my hard drive down?
The input/output errors in the log file (for example,/var/log/messages) indicate that the hard disk has some problems and may have become invalid. You can use the smartctl command to view hard disk errors, this is a command to control and monitor the hard disk status in UNIX-like systems. Syntax:
- Smartctl-a/dev/DEVICE
- # Check/dev/sda on a Linux Server
- Smartctl-a/dev/sda
You can also use the "Disk Utility" software to obtain the same information.
Figure 01: Gnome Disk tool (Applications> System Tools> Disk Utility)
Note: Do not expect the S. M. A. R. T. tool to be too high. It may not work in some situations. We need to back up regularly.
For more details, please continue to read the highlights on the next page: