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

Linux disk partition

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1. Capacity of disks and directories

List the overall disk usage of the file system

(1) df command

-a: lists all file systems, including system-specific / proc and other file systems;-k: displays file systems in the capacity of KBytes. -m: displays each file system in the capacity of MBytes. -h: self-display in reading formats such as GBytes, MBytes, KBytes, etc., commonly used. -H:1M=1000K replaces 1M=1024k 's carry mode. -T: also listed along with the file system name of the partition (such as "xfs"). -I: do not need disk capacity to show However, the number of inode shows [root@localhost ~] # df-hT # to execute the command file system type capacity used. Available mount point / dev/mapper/centos-root xfs 39G 4.2G 35G 11% / devtmpfs devtmpfs 895M 0895m 0% / devtmpfs tmpfs 911M 0911m 0% / dev/shmtmpfs tmpfs 911M 11M 901m 2% / runtmpfs tmpfs 911M 0911M 0% / sys/fs/cgroup/dev/mapper/centos-home xfs 19G 33M 19G 1% / home/dev/sda1 xfs 1014M 170M 845M 17% / boottmpfs tmpfs 183M 8.0K 183M 1% / run/user/42tmpfs tmpfs 183M 0183M 0% / run/user/0 [root@localhost ~] # df-h / etc # Show the available disk capacity under / etc in an easy-to-read capacity format to show the file system capacity used used mount point / dev/mapper/centos-root 39G 4.2G 35G 11% / [root@localhost ~] # df-ih / etc # query the number of inode available in this directory file system Inode is available (I) used (I)% mount point / dev/mapper/centos-root 20m 154K 19M1 /

(2) du command

Evaluate the disk usage of the file system (commonly used in the estimated directory capacity)

Option:-a: list the capacity of all files and directories. By default, only the number of files under the directory is counted. -h: displayed in an easy-to-read capacity format (GUnip M), commonly used. -s: list the total amount, but not the capacity occupied by each individual directory, commonly used. -S: does not include the total under the subdirectory, which is somewhat different from-s and is not commonly used. -k: displayed in KBytes list capacity. -m: displayed in MBytes list capacity

Common parameters

[root@localhost] # du-sh / etc # Statistics / etc directory total usage 37m / etc

two。 Entity links and symbolic links

In general, when using hard link to set up linked files, the disk space and the number of inode will not change!

Hard link only writes one more related data to the block in a certain directory, which will neither increase the inode nor consume the number of block.

(1) ln command

Function:

Create a link, which can be used as a shortcut to create in windows.

The difference between soft links and hard links:

Links can be divided into soft links and hard links. Soft links create a shortcut in Windows, while hard links are equivalent to copying a copy directly to a specified location.

The difference between the two: soft links take up a small space, hard links take up a large space, when the source file does not exist, the soft link also fails, while the hard link is fine, it is equivalent to a completely independent individual

Option:-s: if you link without any parameters, it is the hard link that is created, and the "- s" option is to create a soft link. -f: if the target file exists, take the initiative to remove the target file directly and then create it.

Example

# soft connection example: [root@localhost ~] # ln-s / etc/passwd / tmp/password # create a soft connection [root@localhost ~] # ls-ld / etc/passwd / tmp/password # View the source file and link file-rw-r--r--. 1 root root 2342 July 14 22:46 / etc/passwdlrwxrwxrwx 1 root root 11 August 17 22:54 / tmp/password-> / etc/passwd# you can see that the linked file has great permissions But the actual permissions are subject to the source file [root@localhost ~] # du-sh / etc/passwd / tmp/password 4.0K / etc/passwd0 / tmp/password # you can see that the size of the soft connection file is basically negligible # hard link example: [root@localhost ~] # ln / etc/passwd / tmp/password2 # create a hard link # View the size of the source file and the connection file respectively [root@localhost ~ ] # du-sh / etc/passwd4.0K / etc/passwd [root@localhost ~] # du-sh / tmp/password24.0K / tmp/password2# can see the same size [root@localhost ~] # ls-ld / etc/passwd / tmp/password2# file attributes are also the same-rw-r--r--. 20 root 2277 August 17 22:58 / etc/passwd-rw-r--r--. 20 root 2277 August 17 22:58 / tmp/password2

3. Observe the disk partition status:

Lsblk command

List all disks on the system

Option:-d: only the disk itself is listed, not the partition data for that disk. -f: also lists the file systems on the disk. -I: use ASCII segment output without complex coding (useful in some environments). -m: at the same time, output the permission data (rwx data) of the device under / dev. -p: lists the full file name of the disk device, not just the last name. -t: list the detailed data of the disk device, including the disk array mechanism, the amount of data pre-read and write, etc.

Blkid command

List parameters such as UUID of disk devices

[root@localhost ~] # blkid # query disk UUID and file system / dev/sda1: UUID= "cfcc42fb-78c0-4bf6-84ec-bc3f52803d14" TYPE= "xfs" / dev/sda2: UUID= "fLk953-Bcni-gHbP-E6Sq-F5o6-55pz-LScGyM" TYPE= "LVM2_member" / dev/mapper/centos-root: UUID= "9693181b-8904-4ead-94d8-eb7638055f7a" TYPE= "xfs" / dev/mapper/centos-swap: UUID= "c5c51833-e6a5-4223-b848-aa02d2128dfe" TYPE= Swap / dev/mapper/centos-home: UUID= "5a05f8d3-3211-401b-8f22-99ef3681777f" TYPE= "xfs"

Parted command

List the partition table type and partition information of the disk

[root@localhost ~] # parted / dev/sda print # lists the relevant data of / dev/sda disk. You need to add the "print" parameter Model: VMware, VMware Virtual S (scsi) Disk / dev/sda: 64.4GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags: # the following is the partition data Number Start End Size Type File system flag 1 1049kB 1075MB 1074MB primary xfs startup 2 1075MB 64.4GB 63.3GB primary lvm

Gdisk command

Make a series of changes to the disk, such as partitioning, using GPT mode for partitioning, and another mode is MBR partitioning format, using the fdisk command, the operations of the two partitions are more or less the same

You can use fdisk-l to list the information of all hard disk devices and their partitions in the current system

File system corresponding to ID number: 83:XFS82:swap86:NTFS8e:LVM Volume

Gdisk / dev/sda starts to create partitions after entering

* p look at the partition table * n create a partition (p is the primary partition. E is a logical partition) * m can view help information for various instructions

Mkfs command

After partitioning the disk, you need to use this command to format it.

XFS file system mkfs.xfs

EXT4 file system mkfs.ext4

The options are as follows:

[root@localhost ~] # mkfs.xfs / dev/sdb1 # format this disk Disk details meta-data=/dev/sdb1 isize=512 agcount=4, agsize=1310655 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=5242619 will be output Imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0, rtextents=0 [root@localhost ~] # grep 'processor' / proc/cpuinfo # query number of CPU processor: the result is only one CPU You can set relevant parameters to optimize the read and write performance of the file system.

Xfs_repair command

Verify the file system.

Option:-f: the device followed is actually a file rather than a physical device. -n: simply checking does not modify any data in the file system (just checking). -d: it is usually used in single-person maintenance mode to check and repair the root directory (/). It is very dangerous and should not be used casually.

Fsck command

It is often used to check the ext4 file system and try to fix errors, usually only if you are a root user and there is a problem with the file system, otherwise, using the fsck command under normal conditions is likely to damage the system. In addition, if you suspect that there is a problem with a successfully formatted hard drive, you can also use this command to check

Using fsck to check and repair file systems is risky, especially when hard disk errors are very serious, so when a corrupted file system contains valuable data, be sure to back it up first!

Option:-a: automatically repair the file system without any prompt. -r: adopt interactive repair mode and ask before modifying the file, so that the user can confirm and decide how to handle it. -A: check all file systems listed in the file according to the contents of the / etc/fstab configuration file. -t: the file system type specifies the type of file system to check. -C: displays the progress bar for checking the partition. -f: mandatory detection, the general fsck command will not detect if there is no problem with the partition. If it is mandatory, it will be detected regardless of whether a problem is found or not. -y: auto fix, consistent with-a, but some file systems only support-y. -D: optimize the configuration for directories under the file system. -b: followed by the location of superblock, this option is generally not needed, but if your uperblock is damaged due to a failure, you can use this parameter to try to rescue the superblock backed up in the file system. Generally speaking, superblock backups are placed at: 1K block at 8193 block at 2K block at 16384K block at 32768.

Mount command

Mount the file system

Before mounting, it is as follows: (recommended) * single file system should not be mounted repeatedly in different mount points (directories) * single directory should not be mounted multiple file systems repeatedly * directories should be used as mount points, in theory, they should all be empty directories.

The options are as follows:

Umount command

Unmount the file system

Option:-f: force uninstall, which can be used in situations like the Network File system (NFS) that cannot be read. -l: unmount the file system immediately, which is better than "- f". -n: uninstall without updating / etc/mtab.

Some restrictions on system mount:

Set some parameters that can be set when auto-mount is started.

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

Servers

Wechat

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

12
Report