Tips for solving eight Linux hard drive problems

Source: Internet
Author: User

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:

  1. $ Fallocate-l 1G test4.img
  2. 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:

  1. $ Df

Or try a readable output format:

  1. $ Df-h

Some output content:

  1. FilesystemSizeUsedAvailUse % Mounted on
  2. /Dev/sda6 117G54G57G49%/
  3. Udev 993M4. 0K993M1%/dev
  4. Tmpfs 201m1_k200m1%/run
  5. None 5.0M05.0M0%/run/lock
  6. None 1002M01002M0%/run/shm
  7. /Dev/sda1 1.8G115M1.6G7%/boot
  8. /Dev/sda7 4.7G145M4.4G4%/tmp
  9. /Dev/sda9 9.4g628m8.20.7%/var
  10. /Dev/sda8 94G579M89G1%/ftpusers
  11. /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:

  1. Gzip/ftpusers/tmp/*. log
  2. Bzip2/ftpusers/tmp/large. file. name

2. Use the rm command in UNIX-like systems to delete unwanted files:

  1. Rm-rf/ftpusers/tmp/*. bmp

3. Use the rsync command to move files to other systems or external hard disks:

  1. Rsync -- remove-source-files-azv/ftpusers/tmp/*. mov/mnt/usbdisk/
  2. 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:

  1. Du-a/ftpusers/tmp | sort-n-r | head-n 10
  2. Du-cks * | sort-rn | head

5. Clear the specified file. This method is very effective for log files:

  1. Truncate-s 0/ftpusers/ftp. upload. log
  2. ### Bash/sh ##
  3. >/Ftpusers/ftp. upload. log
  4. # Perl ##
  5. Perl-e 'truncate "filename", length'

6. Find and delete large files displayed but deleted in Linux and UNIX:

  1. # Linux/Unix/OSX/BSD-based systems ##
  2. Lsof-nP | grep '(deleted )'
  3.  
  4. # Only based on Linux ##
  5. Find/proc/*/fd-ls | grep '(deleted )'

Clear it:

  1. # Linux, Unix, OSX, BSD, and other systems ##
  2. > "/Path/to/the/deleted/file. name"
  3. # Only based on Linux ##
  4. > "/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:

  1. $ Cat> file
  2. -Bash: file: Read-only file system

Run the mount command to check whether the mounted file system is in the read-only status:

  1. $ Mount
  2. $ Mount | grep '/ftpusers'

To fix this problem in a Linux-based system, you only need to remount the read-only file system:

  1. # 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:

  1. # 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:

  1. $ Df-I
  2. $ Df-I/ftpusers/

Some output content:

  1. FilesystemInodesIUsedIFreeIUse % Mounted on
  2. /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:

  1. Smartctl-a/dev/DEVICE
  2. # Check/dev/sda on a Linux Server
  3. 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:

  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.