Home Operation and Maintenance Linux Operation and Maintenance Common commands for disk management under Linux

Common commands for disk management under Linux

Aug 02, 2017 pm 04:04 PM
linux Commonly used manage

Linux Disk Partition Tool

The hard disk can be divided into several partitions, and each partition can be used as an independent disk. The partition scheme of the hard disk is recorded in the "disk partition table". Usually the table consists of 4 parts, each part defines the information of a partition. Therefore, in the original concept, a hard disk can only create up to 4 partitions, called "primary partition table". Partition". As hard disks become larger and larger, four partitions are no longer unable to meet the needs of users, so the concept of "extended partition" is introduced. The extended partition is maintained by the extended disk partition table, and a primary partition can be divided into several smaller "logical partitions" as an extended partition. In theory, if the hard disk space is sufficient, any number of partitions can be created.
The recommended partitions on Linux are: swap partition, which is virtual memory; boot partition, which stores the kernel of the operating system; root partition, which is the root directory of the entire operating system; /var partition, which can prevent the log file size from getting out of control; /home Partition controls the amount of space occupied by users.

Disk partitioning tools include:

fdisk: A powerful disk partitioning tool, not only suitable for Linux, but also widely used in Windows and MS-DOS. -l displays the partition table of the current device. -s /dev/sda1 displays the size of the specified partition. -s /dev/sda displays the sum of the sizes of all partitions on the device. -v displays the version number of fdisk. fdisk /dev/sda can enter the command interactive mode. The internal commands include m: display command help; p: display the current partition table; q: exit; etc. )

parted: Disk partitioning and partition adjustment tool under Linux. parted /dev/sda can enter interactive mode.

sfdisk: -l displays partition information. -s displays disk or partition size.


Commonly used disk management commands

##badblocks: Check the device for bad blocks. (-s displays check progress.)


du: Statistics of disk space occupied by files and directories. (If no file or directory name is specified, statistics will be calculated on the current directory by default. -s only displays the number of blocks occupied by the file or directory, and the default block is equal to 1024 bytes. -b counts in bytes; -k counts in 1024 The unit is bytes; -m is in 1024K; -c displays the total at the same time; -h displays K, M or G as needed. -a displays the number of data blocks occupied by all files and their subdirectories. Example: du ~tommy, Statistics of tommy's home directory. )

df: Display the file system disk space usage. (If the file system is not specified, the available space of all currently mounted file systems is displayed. By default, the space is displayed in 1KB units, unless the environment variable POSIXLY_CORRECT is specified, in which case it is displayed in 512-byte units. -i Inode mode display, the listed numbers are all inodes; -h displays in a readable manner, displaying K, M or G as needed; -t type only displays the information of the specified file system, such as df -t ext3; -x type and -t On the contrary, do not display disks of the specified disk type)

fdformat: Format the disk. (-n means no verification will be performed after formatting is completed.)

hdparam: Display and set hard disk parameters. (-C displays power management, -d 1 turns on DMA mode. Example: hdparm /dev/sda1.)

mkfs: Set the file system of the disk. (Example: mkfs -t ext4 /dev/sda2.)

mkswap: Set the swap area. (Example: mkswap /dev/hda4, specify hda4 as a new swap partition. -c checks for bad blocks before creating the swap partition; -v0 creates an old swap area, and -v1 creates a new swap area.)

mkisofs: Create ISO9660/JOLIET/HTS file system. (Example: mkisofs -o myiso myfile makes myfile into an image file named myiso.)

mkinitrd: Create an image file of ramdisk. (Example: mkinitrd myfile.img 2.2.5-15 creates an image file named myfile.img with a kernel number of 2.2.5-15. It is not supported on Ubuntu.)

mt: Tape drive operation. (Syntax: mt operation device. Operations include rewind, erase, etc. The rmt command is a remote tape transfer protocol module that can remotely control the tape drive to perform backup and restore backup operations through inter-process communication.)

mzip: Eject the disk from the Zip/Jaz device. (-e ejects the disk; -f and -e are used together to force ejection; -q queries the status.)

sync: Write the data in the buffer to the disk. (Before uninstalling the mobile hard disk, you can use sync to write the memory data to the disk.)

rsync: remote synchronization. (Example: rsync -av -e ssh /home/share/*.doc root@teacher.example.com:/usr/local/share backs up all doc files under /home/share to /usr on the teacher host through ssh /local/share directory. Only modified files and directories are synchronized. -a: Archive mode; -v: Redundant mode)


## Disk quota management
/etc/fstab file: Defines the mounting method of the partition. (The file format is: . Example: /dev/sda1 / ext4 errors=remount-ro,user_xattr 0 1. To enable disk quota management, you need to add usrquota and grpquota options, for example: /dev/sda2 /mnt/disk ext4 defaults, usrquota, grpquota 0 1. After changing this file, you need to reboot or remount to make the configuration file take effect: mount -o remount /dev/sda2. Note that after a new partition is created, you need to use mkfs to specify the file type of the partition, otherwise an error that the file system cannot be found will occur when mounting. )

quotacheck: Check the disk usage space and restrictions. (After modifying the /etc/fstab file and adding the usrquota and grpquota options, you can use the command quotacheck -avugc to create the two files aquota.user and aquota.group, where -c means to recreate the quota file, and -a scans the / All mounted non-NFS file systems in the etc/mtab file; -u calculates the number of directories and files occupied by each user, and creates the aquota.user file; -g calculates the number of directories and files occupied by each user group, and creates aquota.group file; -v displays the command execution process. The contents of /etc/mtab are similar to /etc/fstab. /etc/fstab indicates that it is loaded by default when the system is started. partition, and /etc/mtab represents the partition currently being loaded by the system. The created aquota.user and aquota.group files are located in the location where the partition with the usrquota and grpquota options is mounted, such as /mnt/disk. )

edquota: Set disk quotas for users or user groups. (The aquota.user and aquota.group files are too complex to be edited directly and can only be edited with the edquotaa command. -u username sets the disk quota for the user, and -g groupname sets the disk quota for the user group. By default -u is used. The file format is: Filesystem blocks soft hard inodes soft hard, where bolocks is the space used by the user, in blocks, and one block is 1024 bytes. The corresponding inodes are the number of used i nodes. soft is the soft limit. When this limit is reached, the system will issue a warning message, but the user can still continue to use it; hard is a hard limit, and the user cannot write when this limit is reached. The previous soft and hard correspond to the block. Soft and hard limits, and the following soft and hard correspond to the soft and hard limits of the inode. -p copies quota settings, such as edquota -p usr1 -u usr2 usr3; -t sets soft time limit. )

quota: Displays the used space and quota limits of the disk. (-u View users, the default option; -g View user groups.)

quotaoff: Turn off disk space restrictions. (-a turns off all disk quotas listed in /etc/fstab; -g user group quotas; -u user quotas; -p lists status.)

quotaon: Enable disk space quota restrictions. (The syntax is the same as quotaoff.)

quotastats: Displays the disk space limit.

repquota: Statistics on the disk quota of the file system.


Logical Volume Management (LVM)

The relevant definitions in LVM are:

Physical volume (PV) is equivalent to A standard primary partition or logical partition of a hard drive;

A physical extent (PE) is a piece of disk space. A physical volume is divided into multiple PEs of equal size;

Logical volume (LV) is a collection of LEs;

Logical extent (PE) is associated with a PE Corresponding, the size is the same;

Volume group (VG) is a collection of LVs.

pvdisplay: View the physical volumes that make up the LVM volume.

pvcreate: Create a physical volume. (Can be created on the hard disk or on one of the partitions.)

vgcreate: Create a volume group. (Example: vgcreate myvolumn /dev/sdd1 /dev/sdc2. Both sdd1 and sdc2 are physical volumes.)

vgextend: Add a new physical volume to the volume group. (Example: vgextend myvolumn /dev/sdd3.)

lvdisplay: View logical volumes.

lvcreate: Create a logical volume. (Example: lvcreate -l 50 myvolumn -n mylogical creates a new device of /dev/myvolumn/mylogical, which can be used to mount: mkfs -j /dev/myvolume/mylogical, mount -t ext3 /dev/myvolumn/mylogical / mnt/mynewdisk. -l 50 means the size is 50 PEs, each PE size may be 4.0M, and -L specifies the size of the LV. -n specifies the name of the LV)

lvextend: Extend the logical volume. . (If there are extra PEs, you can extend the size of the logical volume. Example: lvextend -L 800M /dev/myvolumn/mylogical.)

The above is the detailed content of Common commands for disk management under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

See all articles