Summary of basic Linux disk management knowledge (detailed) and basic linux knowledge

Source: Internet
Author: User

Summary of basic Linux disk management knowledge (detailed) and basic linux knowledge

I. Attaching and detaching storage devices

Common operation commands for mounting and detaching storage devices: fdisk-l, df, du, mount, and umount.

Fdisk-l command

1. Role

View partition information of all hard disks, including unmounted partitions and USB devices. You need to use this command to view the partition or USB device name, such as when mounting a USB flash disk.

Note: in Linux, since the hardware exists as a file, you can also use ls-l/dev/sda * to view the partition information of the first hard disk.

Df command

1. Role

Disk space or file system usage statistics show available disk space on the disk partition. The default unit is KB.

2. Format

Df [option]

3. [option] Main Parameters

-A or-all: displays all file systems

-H or -- human-readable: displays information in a readable manner.

-T or -- print-type: displays the type of the file system.

4. Application Example

View All file systems:

# Df-

Du command

1. Role

The disk space used to view files or directories is different from the df command. Note: If you do not add a directory name or file name after ① du, only the directory size of the subdirectories under the current directory and the total size of the current directory are displayed. ② multiple files or directories can be viewed and separated by space characters.

2. Format

Du [option] Directory Name or file name

3. [option] Main Parameters

-A or-all: displays the size of individual files in the directory.

-H or -- human-readable: displayed in the unit of K, M, G to improve information readability

-S or -- separate-dirs: The subdirectories in the specified directory are omitted, and only the total number of directories is displayed (Note: The command is in uppercase S)

4. Application Example

View the size of the ahao directory in readable form and ignore the subdirectory:

# Du-h-S ahao

View the size of the haha1 and haha2 files in readable form:

# Du-h haha1 haha2

Mount command

1. Role

① This command is followed by no parameter to view all mounted file systems

② Adding parameters means attaching the storage device to a directory in Linux and connecting the partition with the directory. Therefore, we only need to access this Directory, which is equivalent to accessing this storage device.

Note: When a directory contains files and the device is mounted to this directory, the directory does not display the previous files.

2. Format

Mount [option] device name mount point (must already exist)

3. [option] Main Parameters

-T <file system type>: The file system type vfat indicates FAT32, The iso9660 indicates a CD or a CD image, and the auto indicates automatic identification of the system (this is usually convenient)

4. Application Example

Mount the partition/dev/sda5 of the FAT32 File System to the/ahao directory:

# Mount-t auto/dev/sda5/ahao

Mount the USB flash drive/dev/sdb1 to the/ahao directory:

# Mount-t auto/dev/sdb1/ahao

Mount xxx. iso from the CD image file to the/peter directory:

# Mount-t iso9660 xxx. iso/peter-o loop

Umount command

1. Role

Detach a file system. You can use the umount file system by using the device name or mount point. However, it is recommended that you uninstall the file by using the mount point. When multiple mount points of a device are prone to confusion.

2. Format

① Umount mount point (recommended)

② Umount device name

3. Application Example

When you use the umount command to uninstall a file system, you must ensure that the file system cannot be in the busy state, so that the file system is in the busy state: There are opened files in the file system, the working directory of a process is in this system, and the cached files of the file system are being used. The most common error is the unmount operation under the mount point directory.

Mount the mount point corresponding to the unmount/ahao mount point:

# Umount/ahao

Ii. automatic mounting

Principle of automatic mounting

To enable automatic mounting upon startup, you only need to modify the/etc/fstab configuration file, which can be modified using the vi editor or the gedit command on the graphic interface.

Interpretation of the/etc/fstab configuration file

Open the/etc/fstab configuration file

(1) first column: ① device name/dev/sda1 or ② volume label or ③ device UUID (Red Hat 6) (view device UUID blkid/dev/sda1)

(2) Column 2: mount point

(3) Column 3: File System Type

(4) Column 4: mount option, which is usually available using ults

Column 5: whether to back up; 1 indicates backup; 0 indicates no backup

Column 6: whether to check the file system. 1 indicates the check, and 0 indicates that the check is not performed.

Application Example

Enable the usb flash drive to automatically mount the usb flash drive to the/usb directory without backing up and checking the file system:

/Dev/sdb1/usb auto ults 0 0

Add the preceding command to the/etc/fstab configuration file to automatically mount the USB flash drive. To avoid possible errors, run the mount-a command to check whether the edited content is correct.

Iii. Disk partitioning

When fdisk is used for partitioning in Linux, the most common parameters are d, l, m, n, p, q, t, w, and so on.

Note:

① Number of disks in the primary and extended partitions: 1-4, that is, a maximum of four primary or extended partitions. the disk number starting with the logical partition is 5.

② If there are extended partitions on the hard disk, you can only add logical partitions, but not extended partitions.

Fdisk command

1. Role

Partitioning a hard disk using a traditional Q & A Interface

2. Format

1) fidsk disk name

2) [option]

Step 1: fidsk/dev/sdb: select the disk to operate. Here, the operation is performed on the sdb Mobile Disk.

Step 2: enter [option] For the operation

3. [option] Main Parameters

M: List executable commands (HELP)

P: view the current partition of the disk.

N: Create a new disk partition.

L: List known partition types

D: delete an existing partition.

T: Change the partition type.

W; Save the partition operation and exit

Q: Do not save and exit

Partition process description

① Check the partition table information of the hard disk by using the p parameter. Determine future partitions Based on Information

② Delete existing hard disk partitions one by one using the d parameter. If you want to completely change the hard disk partition format

③ Add new partitions using the n Parameter

1) Select the new partition type. P is the primary partition, and e is the extended partition. (If an extended partition exists, e becomes l, that is, the logical partition)

2) set the Partition Number. Primary partition or extended partition is 1-4, logical partition is 5

3) set the start position of the partition. (Generally, press Enter. The default value is good)

4) set the partition end position. (The unit of 100 is sector, the unit of + M is M, and the unit of + K is K)

④ Confirm that the partition is successfully created using the p Parameter

⑤ Exit with the w or q Parameter (w is saved and exited, and q is not saved and exited)

Note: When adding partitions, the types are all default Linux Native. If you need to change some of these partitions to other types, you can use the command t to change them, when you type "t" to change the partition type, the system will prompt Which partition to change and why (type l to view the supported partition types and their corresponding partition type numbers ).

Iv. disk formatting

After partitioning a hard disk, you must format the partition before using it. The main purpose of formatting a partition is to create a file system in the partition, A file system is a method and data structure used by the operating system to specify the files on a storage device or partition, that is, the method for organizing files on the storage device.

Mkfs command

1. Role

Format the partition and create a file system on the partition.

2. Format

① Mkfs [options] device name

② Mkfs. <file system type> [-v] device name

3. [option] Main Parameters

-T <file system type>: select the type of the file system to be created, such as ext3 and ext4. Different Versions of Linux have different default file systems.

-V: displays more output, including information about the file system (Note:-V must be placed before-t)

4. Application Example

Format the/dev/sdb1 partition and display the details:

# Mkfs-V-t vfat/dev/sdb1

# Mkfs. vfat-v/dev/sdb1

I. Attaching and detaching storage devices

Common operation commands for mounting and detaching storage devices: fdisk-l, df, du, mount, and umount.

Fdisk-l command

1. Role

View partition information of all hard disks, including unmounted partitions and USB devices. You need to use this command to view the partition or USB device name, such as when mounting a USB flash disk.

Note: in Linux, since the hardware exists as a file, you can also use ls-l/dev/sda * to view the partition information of the first hard disk.

Df command

1. Role

Disk space or file system usage statistics show available disk space on the disk partition. The default unit is KB.

2. Format

Df [option]

3. [option] Main Parameters

-A or-all: displays all file systems

-H or -- human-readable: displays information in a readable manner.

-T or -- print-type: displays the type of the file system.

4. Application Example

View All file systems:

# Df-

Du command

1. Role

The disk space used to view files or directories is different from the df command. Note: If you do not add a directory name or file name after ① du, only the directory size of the subdirectories under the current directory and the total size of the current directory are displayed. ② multiple files or directories can be viewed and separated by space characters.

2. Format

Du [option] Directory Name or file name

3. [option] Main Parameters

-A or-all: displays the size of individual files in the directory.

-H or -- human-readable: displayed in the unit of K, M, G to improve information readability

-S or -- separate-dirs: The subdirectories in the specified directory are omitted, and only the total number of directories is displayed (Note: The command is in uppercase S)

4. Application Example

View the size of the ahao directory in readable form and ignore the subdirectory:

# Du-h-S ahao

View the size of the haha1 and haha2 files in readable form:

# Du-h haha1 haha2

Mount command

1. Role

① This command is followed by no parameter to view all mounted file systems

② Adding parameters means attaching the storage device to a directory in Linux and connecting the partition with the directory. Therefore, we only need to access this Directory, which is equivalent to accessing this storage device.

Note: When a directory contains files and the device is mounted to this directory, the directory does not display the previous files.

2. Format

Mount [option] device name mount point (must already exist)

3. [option] Main Parameters

-T <file system type>: The file system type vfat indicates FAT32, The iso9660 indicates a CD or a CD image, and the auto indicates automatic identification of the system (this is usually convenient)

4. Application Example

Mount the partition/dev/sda5 of the FAT32 File System to the/ahao directory:

# Mount-t auto/dev/sda5/ahao

Mount the USB flash drive/dev/sdb1 to the/ahao directory:

# Mount-t auto/dev/sdb1/ahao

Mount xxx. iso from the CD image file to the/peter directory:

# Mount-t iso9660 xxx. iso/peter-o loop

Umount command

1. Role

Detach a file system. You can use the umount file system by using the device name or mount point. However, it is recommended that you uninstall the file by using the mount point. When multiple mount points of a device are prone to confusion.

2. Format

① Umount mount point (recommended)

② Umount device name

3. Application Example

When you use the umount command to uninstall a file system, you must ensure that the file system cannot be in the busy state, so that the file system is in the busy state: There are opened files in the file system, the working directory of a process is in this system, and the cached files of the file system are being used. The most common error is the unmount operation under the mount point directory.

Mount the mount point corresponding to the unmount/ahao mount point:

# Umount/ahao

Ii. automatic mounting

Principle of automatic mounting

To enable automatic mounting upon startup, you only need to modify the/etc/fstab configuration file, which can be modified using the vi editor or the gedit command on the graphic interface.

Interpretation of the/etc/fstab configuration file

Open the/etc/fstab configuration file

(1) first column: ① device name/dev/sda1 or ② volume label or ③ device UUID (Red Hat 6) (view device UUID blkid/dev/sda1)

(2) Column 2: mount point

(3) Column 3: File System Type

(4) Column 4: mount option, which is usually available using ults

Column 5: whether to back up; 1 indicates backup; 0 indicates no backup

Column 6: whether to check the file system. 1 indicates the check, and 0 indicates that the check is not performed.

Application Example

Enable the usb flash drive to automatically mount the usb flash drive to the/usb directory without backing up and checking the file system:

/Dev/sdb1/usb auto ults 0 0

Add the preceding command to the/etc/fstab configuration file to automatically mount the USB flash drive. To avoid possible errors, run the mount-a command to check whether the edited content is correct.

Iii. Disk partitioning

When fdisk is used for partitioning in Linux, the most common parameters are d, l, m, n, p, q, t, w, and so on.

Note:

① Number of disks in the primary and extended partitions: 1-4, that is, a maximum of four primary or extended partitions. the disk number starting with the logical partition is 5.

② If there are extended partitions on the hard disk, you can only add logical partitions, but not extended partitions.

Fdisk command

1. Role

Partitioning a hard disk using a traditional Q & A Interface

2. Format

1) fidsk disk name

2) [option]

Step 1: fidsk/dev/sdb: select the disk to operate. Here, the operation is performed on the sdb Mobile Disk.

Step 2: enter [option] For the operation

3. [option] Main Parameters

M: List executable commands (HELP)

P: view the current partition of the disk.

N: Create a new disk partition.

L: List known partition types

D: delete an existing partition.

T: Change the partition type.

W; Save the partition operation and exit

Q: Do not save and exit

Partition process description

① Check the partition table information of the hard disk by using the p parameter. Determine future partitions Based on Information

② Delete existing hard disk partitions one by one using the d parameter. If you want to completely change the hard disk partition format

③ Add new partitions using the n Parameter

1) Select the new partition type. P is the primary partition, and e is the extended partition. (If an extended partition exists, e becomes l, that is, the logical partition)

2) set the Partition Number. Primary partition or extended partition is 1-4, logical partition is 5

3) set the start position of the partition. (Generally, press Enter. The default value is good)

4) set the partition end position. (The unit of 100 is sector, the unit of + M is M, and the unit of + K is K)

④ Confirm that the partition is successfully created using the p Parameter

⑤ Exit with the w or q Parameter (w is saved and exited, and q is not saved and exited)

Note: When adding partitions, the types are all default Linux Native. If you need to change some of these partitions to other types, you can use the command t to change them, when you type "t" to change the partition type, the system will prompt Which partition to change and why (type l to view the supported partition types and their corresponding partition type numbers ).

Iv. disk formatting

After partitioning a hard disk, you must format the partition before using it. The main purpose of formatting a partition is to create a file system in the partition, A file system is a method and data structure used by the operating system to specify the files on a storage device or partition, that is, the method for organizing files on the storage device.

Mkfs command

1. Role

Format the partition and create a file system on the partition.

2. Format

① Mkfs [options] device name

② Mkfs. <file system type> [-v] device name

3. [option] Main Parameters

-T <file system type>: select the type of the file system to be created, such as ext3 and ext4. Different Versions of Linux have different default file systems.

-V: displays more output, including information about the file system (Note:-V must be placed before-t)

4. Application Example

Format the/dev/sdb1 partition and display the details:

# Mkfs-V-t vfat/dev/sdb1

# Mkfs. vfat-v/dev/sdb1

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.