First, the storage device is mounted and uninstalled
Common operations commands for mounting and unmounting storage devices: fdisk -l, df, du, mount, umount.
Fdisk -l command
Function
View the partition information of all hard disks, including the partitions and USB devices that are not mounted. You need to use this command to view the name of the partition or USB device when mounting, such as when mounting a USB flash drive.
Note: Since the hardware exists in Linux as a file, you can also view the partition information of the first hard disk by ls -l /dev/sda*.
Df command
Function
Count disk space or file system usage, showing the available disk space on the disk partition. The default display unit is KB.
2. Format
Df [option]
3.[option] main parameters
-a or -all: display all file systems
-h or --human-readable: display information in a more readable manner
-T or --print-type: display the type of file system
4. Application examples
View all file systems:
#df -a
Du command
Function
Looking at the space used by the disk of a file or directory, there are some differences between the df command and the df command. Note: If you do not add a directory name or file name after 1du, it means that only the directory size of the subdirectory under the current directory and the total size of the current directory are displayed. 2 You can view multiple files or directories separated by spaces.
2. Format
Du [option] directory name or file name
3.[option] main parameters
-a or -all: display the size of individual files in the directory
-h or --human-readable: display in K, M, G units to improve information readability
-S or --separate-dirs: omit the subdirectories under the specified directory, only the sum of the directories (note: the command is uppercase S)
4. Application examples
View the size of the ahao directory in an easy-to-read format and ignore the subdirectories:
#du -h -S ahao
View the size of haha1 files and haha2 files in an easy-to-read format:
#du -h haha1 haha2
Mount command
Function
1 This command does not add any parameters to view all the file systems that have been mounted.
2 Adding parameters means that the storage device is mounted to a directory in Linux, thereby associating the partition with the directory, so that by simply accessing this directory, it is equivalent to accessing the storage device.
Note: When there is a file before a directory, after the device is mounted to this directory, the directory does not display the previous file.
2. Format
Mount [option] device name mount point (must already exist)
3.[option] main parameters
-t <file system type>: file system type vfat means FAT32, iso9660 means CD or CD image, auto means the system automatically recognizes (usually this is convenient)
4. Application examples
Mount the partition /dev/sda5 of the FAT32 file system to the /ahao directory:
#mount -t auto /dev/sda5 /ahao
Mount the U disk /dev/sdb1 to the /ahao directory:
#mount -t auto /dev/sdb1 /ahao
Attach the CD image file xxx.iso to the /peter directory:
#mount -t iso9660 xxx.iso /peter -o loop
Umount command
Function
Unload the file system that has already been loaded. You can umount the file system by using the device name or the mount point, but it is better to uninstall it through the mount point. When a device has multiple mount points, it is easy to cause confusion.
2. Format
1umount mount point (recommended for this method)
2umount device name
3. Application examples
When using the umount command to unmount the file system, you must ensure that the file system cannot be in the busy state. The file system is in the busy state. There are open files in the file system, the working directory of a process is in this system, and the file system is The cache file is being used, etc. The most common error is to uninstall under the mount point directory.
Unmount the mount corresponding to the /ahao mount point:
#umount /ahao
Second, automatic mounting
Automatic mount implementation principle
To achieve automatic booting, just modify the /etc/fstab configuration file, you can use the vi editor to modify or use the gedit command to modify the graphical interface.
/etc/fstab configuration file interpretation
Open the /etc/fstab configuration file
(1) First column: 1 device name / dev / sda1 or 2 label label or 3 device UUID (Red Hat 6) (view device UUID blkid / dev / sda1)
(2) Second column: mount point
(3) Third column: file system type
(4) The fourth column: mount options, usually using defaults
(5) The fifth column: whether to perform backup, 1 means backup, 0 means no backup
(6) Sixth column: Whether to check the file system, 1 means inspection, 0 means no inspection
Application examples
Realize the USB flash drive to automatically mount the USB flash drive to the /usb directory, do not back up and do not check the file system:
/dev/sdb1 /usb auto defaults 0 0
Add the above command to the /etc/fstab configuration file to complete the automatic mounting of the USB flash drive. To avoid possible errors, use the mount -a command to verify that the edited content is faulty.
Third, the disk partition
When using fdisk to partition in Linux, the most commonly used parameters are d, l, m, n, p, q, t, w, etc.
note:
1 The primary and extended partitions have disk numbers 1-4, which means that there are up to 4 primary or extended partitions. The logical partition starts with a disk number of 5.
2 If there is an extended partition on the hard disk, you can only add logical partitions, and you cannot add extended partitions.
Fdisk command
Function
Partition the hard drive with a traditional Q&A interface
2. Format
1) fidsk disk name
2) [option]
The first step: fidsk /dev/sdb: select the disk to be operated, here is the operation of the sdb mobile disk
Step 2: Enter [option] to operate
3.[option] main parameters
m: list the commands that can be executed (help)
p: View the current partition status of the disk
n: Create a new disk partition
l: List known partition types
d: delete the existing partition
t: change the partition type
w; save and exit the partition operation
q: Do not save and exit
Partition process description
1 Use the p parameter to view the hard disk partition table information. Determine future partitions based on information
2 Delete the existing hard disk partition by d parameter one by one, if you want to completely change the partition format of the hard disk
3 increase the new partition by the n parameter
1) Select the new partition type. p is the primary partition, and e is the extended partition (where e will become l when the extended partition exists, that is, logical partition)
2) Set the partition number. The primary or extended partition is 1-4, and the logical partition is 5
3) Set the starting position of the partition. (General return to the default is good)
4) Set the partition end position. (100 units are sectors, +100M units are M, +100K units are K)
4 Confirm that the partition is successfully established by p parameter
5 Exit by parameter w or q (w is save and exit, q is exit without saving)
Note: When adding a partition, its type is the default Linux Native. If you need to change some of the partitions to other types, you can change it by the command t. When you type "t" to change the partition type, the system will Prompt which partition to change, change the type (type l to see the partition type supported by the system and its corresponding partition type number).
Fourth, disk formatting
After partitioning the hard disk, you need to format the partition to use. The main purpose of formatting the partition is to create a file system in the partition. The file system is the method and data structure used by the OS to explicitly store files on the device or partition. The method of organizing files on a storage device.
Mkfs command
Function
Format the partition and create a file system on the partition
2. Format
1mkfs[options] device name
2mkfs.<file system type> [-v] device name
3.[option] main parameters
-t<filesystem type>: Select the type of filesystem to be created, such as ext3, ext4, etc. Different versions of Linux have different default filesystems.
-V: Display more output, including information about the file system (note: -V must be placed before -t)
4. Application examples
Format the /dev/sdb1 partition and display the specific information:
#mkfs -V -t vfat /dev/sdb1
#mkfs.vfat -v /dev/sdb1
Terminal Blocks Connector,Pluggable Terminal Blocks,Pcb Screw Terminal Blocks,Transformer Terminal Blocks
Shenzhen Hongyian Electronics Co., Ltd. , https://www.hongyiancon.com