Common commands for disk management under Linux

巴扎黑
Release: 2017-08-02 16:04:48
Original
1984 people have browsed it

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template