Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Linux disk Management

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is a sample analysis of Linux disk management. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Linux disk management is a very important skill for Linux administrators. Linux disk management is directly related to the performance of the whole system.

1. Mounting and unmounting of storage devices Common operation commands for mounting and unmounting storage devices: fdisk -l, df, du, mount, mount.

fdisk -l command

1. Role

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

Note: Since Linux hardware exists as files, you can also view the partition information of the first hard disk by ls -l /dev/sda*.

DF command

1. Role

Statistics on disk space or file system usage, showing available disk space on disk partitions, in KB by default

2. Format

df [option]

3.[option] Main parameters

-a or-all: show all file systems-h or--human-readable: show information in a readable way-T or--print-type: show file system type

4. Application examples

View all file systems:

#df -a

du command

1. Role

To see how much disk space a file or directory is using, there are some differences between df and df. Note: ① If no directory name or file name is added after du, it means that only the directory size of the subdirectory below the current directory and the total size of the current directory are displayed ② Multiple files or directories can be viewed separated by spaces

2. Format

du [option] directory name or file name

3.[option] Main parameters

-a or-all: Displays the size of individual files in a directory-h or--human-readable: Displays in K, M, G units to improve readability of information-S or--separate-dirs: omits subdirectories under a specified directory and displays only the sum of the directories (note: this command is capitalized S)

4. application examples

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

#du -h -S ahao

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

#du -h haha1 haha2

Mount command

1. Role

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

② Adding parameters means mounting the storage device to a directory in Linux, thus associating the partition with the directory, so we only need to access this directory, which is equivalent to accessing the storage device.

Note: When a directory is preceded by files, the directory does not display the previous files after the device is mounted to the directory.

2. Format

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

3.[option] Main parameters

-t: File system type vfat means FAT32, iso9660 means CD or CD image, auto means system automatic identification (generally choose this convenient bar)

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 USB drive/dev/sdb1 to the/ahao directory:

#mount -t auto /dev/sdb1 /ahao

Attach the CD-ROM image file xxx.iso to the/peter directory:

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

umount command

1. Role

Unmount a file system that is already loaded. You can mount the file system using the device name or mount point, but it's best to unmount it through the mount point. When a device has multiple mount points, it's easy to cause confusion.

2. Format

①umount mount point (recommended)②umount device name

3. Application examples

When using the umount command to unmount a file system, you must ensure that the file system is not in a busy state. The file system is in a busy state when there are open files in the file system, the working directory of a process is in this system, and the cache file of the file system is being used. The most common error is unmounting under the mount point directory.

Unmount/ahao Mount points corresponding to mount:

#mount/ahao 2. Auto mount

Automatic mount implementation principle to achieve boot automatic mount only need to modify the/etc/fstab configuration file, you can use vi editor to modify or graphical interface with gedit command to modify the/etc/fstab configuration file interpretation

Open the/etc/fstab configuration file

Column 1: ① Device name/dev/sda1 or ② label or ③ Device UUID(Red Hat 6)(see device UUID blkid/dev/sda1)

(2) Column 2: Mount Point

Third column: File system type

(4) The fourth column: mount options, usually using defaults

(5) Fifth column: whether to backup, 1 means backup, 0 means no backup

(6) Column 6: Check file system, 1 means check, 0 means no check

application examples

To achieve the insertion of U disk automatically mount U disk to/usb directory, do not backup 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 drive. To avoid possible errors, use the mount -a command to verify whether the edited content is wrong.

Third, disk partition

When partitioning with fdisk in Linux, the most commonly used parameters are d, l, m, n, p, q, t, w, etc.

Note:

① The disk number of the primary partition and the extended partition is 1-4, that is, there are at most 4 primary partitions or extended partitions, and the disk number at the beginning of the logical partition is 5.

② If there are extended partitions on the hard disk, only logical partitions can be added, and extended partitions cannot be added.

fdisk command

1. Role

Partitioning the hard drive with a traditional question-and-answer interface

2. Format

1)fidsk disk name 2)[option]

Step 1: fidsk /dev/sdb: Select the disk to be operated on, here the sdb move disk is operated on

Step 2: Enter [option] to operate

3.[option] Main parameters

m: List commands that can be executed (help) p: View current partitions on disk n: Create new disk partitions l: List known partition types d: Delete existing partitions t: Change partition type w; Save partition operation and exit q: Exit without saving

partition process description

① Through the p parameter to view the hard disk partition table information. Determine future partitions based on information

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

③ Adding new partitions with n parameters

1) Select the new partition type. p is the primary partition and e is the extended partition (where e becomes l, i.e. logical partition, when extended partitions exist)

2) Set the partition number. Primary or extended partitions are 1-4, logical partitions start at 5

3) Set the starting position of the partition. (Generally enter default is good)

4) Set the partition end position. (100 units are sectors,+100M units are M,+100K units are K)

④ Confirm partition establishment successfully through p parameter

5 Exit through parameter w or q (w means save and exit, q means exit without saving)

Note: When adding partitions, their types are the default Linux Native. If you need to change some of them to other types, you can change them by command t. When typing "t" to change the partition type, the system will prompt you which partition to change and what type to change (type l to see the supported partition types and their corresponding partition class models).

IV. Disk formatting

After partitioning the hard disk, the partition needs to be formatted before it can be used. 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 that the OS uses to define the files on the storage device or partition, i.e., the method of organizing files on the storage device.

mkfs command

1. Role

Format partitions, create file systems on partitions

2. Format

①mkfs[options] Device name ②mkfs. [-v]device name

3.[option] Main parameters

-t: Select the type of file system you want to create, such as ext3, ext4, etc. Different versions of Linux have different default file systems-V: Show more output, including information about the file system (note: -V must precede-t)

4. Application examples

Format the/dev/sdb1 partition and display the following information:

#mkfs -V -t vfat /dev/sdb1#mkfs.vfat -v /dev/sdb1 Thank you for reading! About "Linux disk management example analysis" This article is shared here, I hope the above content can have some help for everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report