Because the file system is a very important part of the system, the task of maintaining the file system is also very important. This task includes checking, fixing the file system, and adjusting the tree to fit the changes in the system, adding new storage devices, etc.
Check your hard drive
There is no problem with the file system when using FreeBSD under normal circumstances. However, in some cases, if the computer's power is cut off without a normal shutdown operation, a file system problem will occur. In addition, for system maintenance purposes, it is also necessary to regularly check the correctness of the disk. This requires the use of the file System Check tool fsck.
# fsck /dev/wd0s3e
** /dev/rwd0s3e
** Last Mounted on /var
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
573files,3387used,26340free(132frags,3276blocks,0.4%fragmentation)
FSCK uses raw mode to access the disk, so even if the normal block device/dev/wd0s3e is used as a parameter, fsck will use the corresponding raw method device file/dev/rwd0s3e to operate. To avoid conflicts with the current disk's access operation, the file system is required to be uninstalled before checking, otherwise the file system status is always incorrect (not properly uninstalled).
In order not to affect the process running in the system, for disk maintenance, it is best to enter the Single-user state first. In this state, all unnecessary processes are turned off, the system installs only the root file system, the other files are not installed, and even the root file system is installed as read-only, which guarantees that no access conflicts will occur, resulting in an error in the file system.
Once the disk is checked for errors, Fsck prompts the administrator to make changes and can use the "-y" parameter to enable fsck to automatically fix the work without prompting for any prompts. Every time the system starts, it uses this parameter to automatically check and repair the file system.
To adjust the directory structure of a file system
A different file system is installed on the directory tree when the system is installed. Over time, some directories use file systems that are filled with file data, while in some directories the file system is rarely used, making the file system less suitable for system requirements, or adding new hard disk devices. or adjust the file to a different file system.
For example, if the FreeBSD system is used as a news server, the reader publishes the article will be saved in the/var directory of the file system, and the default/var directory space is limited, then the directory will be filled. If you continue to install a variety of applications in your system, the file system where the/usr/loc Al directory resides will be filled, and so on. Managers need to adjust according to the actual situation, you can use the DF command to view the file system's current state information.
# df
Filesystem 512-blocks Used Avail Capacity Mounted on
/dev/wd0s3a 63550 50822 7644 87% /
/dev/wd0s3f 1693228 977436 580334 63% /usr
/dev/wd0s3e 59454 6772 47926 12% /var
profs 8 8 0 100% /proc
/dev/wd0s1 2055744 2032096 23648 99% /mnt/dosc
The information reported by DF includes the size of the filesystem and the amount of space remaining (including the use size, the remaining size, and the percentage of space used) if there is not enough space in one file system and the other file system is left with sufficient space to make the most of the existing space.
Sometimes, DF reports that the percentage of used space is more than 100%, due to the availability of some redundant space in the UFs file system. This gives the user an opportunity to make sure that the data can be stored correctly in the file system by clearing the file system from the other unnecessary files in the same file system without interrupting the file system for the full number of files that are currently being written.
The basic way to adjust the file system space is to use symbolic connections, you can either transfer or copy the data in one subdirectory of the filesystem to another directory in the other file system, then rename or delete the original directory, and then create a symbolic connection to the new directory to achieve the goal. For example, you can transfer the/usr/local directory to another file system that is installed to/disk2:
# cd /usr/local
# tar cf - * | (cd /disk2; tar xf -)
# mv /usr/local /usr/local.old
# ln -s /disk2/local /usr/local
To ensure data security, the example here does not use MV to move data directly, but instead uses tar to copy data to another directory, using tar instead of the cp-r command to preserve the consistency of their owner and permission control attributes when copying files and directories.