This article summarizes the commands needed to manage our hard drives and file systems in the Linux operating system. When we add a hard drive to our system, what steps do we have to go through to actually use the drive? This can be roughly divided into the following steps:
(1) partition the disk, create a new partition that can be used;
(2) format the partition and format the partition as a file system that can be used by our operating system;
(3) To test the new file system;
(4) Create a mount point to mount the file system.
The following is a description of disk partitioning, formatting, checking, and mounting related commands.
The disk partition is carried out through the FDISK command, and the FDISK command is used in the basic method of "Fdisk [-l] Device name". After entering the FDISK command, you can view the help by pressing M. The more important commands are: D: delete a partition; N: Add a partition; P: Display the partition table on the screen; Q, leave the FDISK program without saving any settings;W: Writes the settings to the partitioned table. Of course, you can also view the current host's hard disk information and partition directly through the FDISK-L command. :
There are some caveats to using the FDISK command when we use the after the W command writes the settings to the partitioned table, a warning message may appear, let's restart to update the partition table information, because our disks are still in use and cannot be uninstalled, so the kernel Unable to re-obtain partition table information. In addition to rebooting, you can use the GNU Partprobe Utility Program to force the kernel to re-locate the partition table. In addition to the Fdisk command for more than 2TB of the disk can not be processed, this time you need to parted command to partition the disk.
The formatted command is done through the MKFS (make file System) command. It is used in the "Mkfs [-T file system format] device file name". MKFS is a comprehensive command, and when we use the "mkfs-t ext3 ..." command, the system invokes the MKFS.EXT3 command to format it accordingly. We can press the two tab key after entering the MKFS command to view mkfs supported file formats. The following are the file system formats that are supported on my system mkfs:
The VFAT format is supported in both Windows and Linux, so you can use this format for USB drives that you share in Windows and Linux. When using the mkfs command, you can specify the file system's volume label, block size, inode size, and so on, in addition to specifying the file system type. MKFS is a utility called Mke2fs to set these parameters,mke2fs is used as "mke2fs [-B blocksize] [-I inodesize] [-l volume label] [-CJ] Device".
fsck command is a command used to check and remediate file system errors. The fsck command uses this command only if it is a root user and the file system has a problem, otherwise this command is used normally, When you use the FSCK command to detect a disk, the problematic data is placed in the Lost+found directory of the file system. The top-most directory of each file system (which is the one that hangs under the Point directory) will have a lost +found directory. In addition to the FSCK command to detect file system errors, you can also use the Badlocks command to check if there is a bad track on the hard disk sector.
Next is the disk mount and unload, the concept of Mount has been told many times. The mount point must be a directory, which is the entry into the disk partition, access to the directory can access the file system data. The Mount command is a useful command for mounting file systems using the Mount command in Linux, which can mount Ext3/vfat/nfs and other file systems. The Mount command uses the following methods:
MOUNT-A: All non-mounted disks are mounted according to the data of the configuration file/etc/fstab;
mount-l: Just enter the mount command to display the current system mount information, plus the-l parameter can increase the label name;
Mount [-t file system] [-l label name] [-o extra option] [-n] Device file name mount point: Mount a device as specified.
The Mount command is very simple to use and does not even need to specify the type of file system with the-t parameter when it is actually mounted, because the file system has almost all super blocks and Linux automatically analyzes super when mounted Block and use the Linux own driver to test the mount, and if the test succeeds, immediately using that type of file system to mount the device. So when we insert a USB stick in the computer, if you want to use it, you also need to mount the USB flash drive using the Mount command. The Mount command can also be re-mounted via the-o remount parameter , which can be re-mounted when we enter single-user maintenance mode because the root directory is often mounted as read-only by the system.
In addition to mounting the device, the Mount--bind command also allows a directory mount to another directory, the subsequent access to the mount point is equivalent to access to the directory, of course, this effect can also be achieved through symbolic connection. The following is an example of mounting a directory using mount:
After mounting, you can use the Umount command to uninstall, umount using the Umount [-FN] device file name or mount point. You can use the device file name or mount point to uninstall, and after uninstallation you can use the DF command or the mount-l command to see if the file system also exists in the directory tree , but if you mount a directory instead of a disk device, it can only be uninstalled by Mount point. And when uninstalling, please note that you need to change the working directory to a directory other than the mount point (and its subdirectories).
2.6, the device file name of the hardware can be automatically generated by the system in real time, We do not need to create them manually, but we still know how to manually create the device files for a rainy moment. Creating a device file is done through the Mknod command, which is used as "Mknod device file name [bcp ] [Major] [Minor] ".
each file system has a file System volume label (label) that can be specified when the file system is formatted (MKFS), or it can be modified using the E2label command. E2label is used as: "E2label device name new label name". The name of the Linux file system is similar to the name of each disk in window (c-disk/D-disk, etc.). When mounted , we can also mount using the file system's volume name, while in CentOS, the/etc/fstab file is set to the default label name. What are the benefits of using a volume label name? No matter how your disk device file name changes, the system uses the label name to identify your hard drive, so no matter which interface your hard drive is plugged into, it will not affect it.
There are also TUNE2FS commands, the TUNE2FS command function is more extensive, can be self-man below. Hdparm command for the IDE interface of the hard disk, you can set a lot of advanced parameters, but for the SATA interface hard disk, it is not much use, the only thing you can do is to use "HDPARM-T device name" way to test the performance of the disk, But the test results are not very accurate and can only be used as a reference.
It is not convenient to mount the mount command manually, which allows the system to mount the file system automatically at boot time, mainly by modifying the/etc/fstab file to set up automatic mount. each time we use the Mount command to mount the filesystem, we are actually writing the corresponding parameters to the/etc/fstab file. There are six fields in the file that can be understood by nameThe meaning of each field. Where the device field is the name of the file that represents the disk device or the label name of the device, and the default is label name. The parameters representative of the fourth columnis the file system parameters, you can set a lot of parameters, such as synchronous or asynchronous, whether to allow users to mount and so on. The dump column refers to whether the file system can be performed by the dump commandBackup. 0 is not a backup, 1 is a daily dump backup, and 2 represents another variable date dump backup. The fsck column represents whether the file system is detected with the FSCK program, 0 means no detection, 1represents detection, 2 also represents detection, but is later than 1, so the file system where the root directory resides is set to 1, and the other is set to 2. When we modify the/etc/fstab file, in order to prevent the syntax error caused by our inability to boot, after the modification must use the DF command or the MOUNT-L command to test whether to get hang the information correctly.
in Linux, for an image file, we can access the data in the file without having to burn it to a CD. We can mount an image file directly using a special loop Mount , Mount-o Loop , and then access the mount point to access the data in the image file. Really very convenient, think about it. In Windows, we have to use third-party software to open the image file. In addition to the image file, for a large file, we can also use this way to mount, which is equivalent to We do not need to modify the partition table to create the partition we want. Here's how I mount the CentOS install image file using Mount-o loop:
Finally, we introduce the construction of Memory swap space (swap). When installing CentOS, the need to build swap (memory swap space) is explained. When the host is running out of physical memory, the kernel will move programs and data that are temporarily unused in physical memory to swap, thereby emptying the physical memory to load the program that needs to be executed. The function of swap is therefore to expand memory in the case of insufficient physical memory . If you forget to build swap when you install Linux, you can create swap by using the fsck command to divide a partition into a swap, and then use the MKSWAP command to format the partition as swap, and then use the Swapon The device file name "to start the swap device. can use Free This memory view command to see if swap is loaded correctly. In addition to building a partition into swap, you can use a large file to construct the swap, which is similar. you can also use Swapoff to release swap files when you use a file to build swap.
This chapter is a summary of Linux commands:
Fdisk,partprobe,mkfs,mke2fs,fsck,badlocks,mount,umount,mknod,e2label,tune2fs,hdparm,mkswap,swapon,swapoff, Free
Brother Bird's Linux private cuisine Basic study book note: Linux disk and File System Management (3)