Linux-based disk Management
About Disk Management in Linux we should start with the following four aspects to understand and learn the knowledge of Disk Management .
Structure of the 1th disk--hard disk
Parameters of the hard disk
structure: Disk disc, head, motor (mechanical keyboard )
Type: solid-state drives (SSB) and mechanical hard drives
Interface: Early IDE interface, now Sata,scsi,sas
There are capacity, speed, transmission speed, cache and so on.
Hard disk storage Terminology
Head: Head
Track: Tracks
Cylinder: Cylinder surface
SECOTR: Sector 512bytes (bytes)
Partition formatting of the 2nd disk
First, you need to understand why partitioning?
1 Optimizing I/O performance
2 Implementing disk space quotas
3 Improve Repair speed
4 Isolating systems and programs
5 Installing multiple OSes
6 Using different file systems
Next is the partitioning
There are two ways to partition: MBR, GPT
MBR: The early partition standard, which was born in 1982, supports partitions up to 2T and supports a maximum of 4 primary partitions. Typically stored in hard disk 0 track 0 sector 512bytes size space
GPT: Latest partition Standard, supports up to 128 primary partitions, supports up to 8z HDD size
Disk Partitioning Tool
FDISK: MBR partitioning standard supported
Gdisk: Supports GPT partition standard
Parted: Both partition standards support direct partitioning by command
Parted advanced partitioning operations (create, copy, resize, and so on)
Partprobe re-setting the kernel partition table version in memory
Parted
Parted/dev/sdb Mklabel GPT
Change partition for GPT to kill disk data directly
Parted/dev/sdb Mkpart Primary 1 1000
The size of the disk on the real-time effect
-fdisk
Fdisk/dev/device
Interactive directives
n Create a new partition
D Delete Partition
P Display the current partition table
t change the partition type
L LIST the types of all supported partitions
Q Do not save exit
Wq Save exit
Create a partition directly from the command line
Echo-e "n\np\n1\n\n+2g\nw\n |fdisk/dev/sdx mind to sober step-by-step,
-gdisk
Gdisk/dev/device
Interaction instructions and Fdisk are not much different.
FDISK will be gdisk.
-parted
Parted/dev/device Creating partitions interactively
parted [options]/dev/device [cmd] Options ... Create a partition directly from the command line
Parted/dev/sdb Mkpart Primary 1 1G Create a 1G-sized partition with 1 and 1G representing the starting point respectively
Formatting tools
Mkfs. [Type] Universal formatting tool
MKE2FS Ext Series Formatting tools
Mkawap Format swap partition
Common file systems in Linux
ext2 ext3 ext4 xfs btrfs Swap iso9660 NFS ...
Mkfs
-t specifies the file system type, MKFS-T type is equivalent to mkfs.type-l the specified volume label MKFS.XFS/DEV/SDB1 format partition into XFS partition
Mke2fs
Usage: mke2fs [options]/dev/device options:-T Specify the file system type Ext2/ext3/ext4-b Specify the block size 1024/2048/4096-l Specify the volume label-l ' LABEL '-M administrator reserved space-M 5: Reserved 5%-o Enable or disable function modules such as:-O ^has_journal turn off log function-n Create how many inode numbers-I specify how many directly correspond to an inode number Example: Mke2fs-t ext4-b 2048-l ' first '-M 5-o ^has_journal-i 2048/dev/sdb1 tune2fs-l/dev/sdb1 View File system Whether the creation was successful
Three disk quotas
Disk quotas are objects that are directories, and the directory must be mounted to a separate partition. Its main role is to limit the user to create file size and number of files. Create a process: ①, re-mount the catalog to enable the Quota function module Method 1:mount -o remount,usrquota,grpquota /home # #前提:/home must be mounted separately to a partition Method 2: Modify/etc/fstab, The feature options are defined as Defaults,usrquota,grpquota, and then re-mount the ② with remount, close selinux setenforce 0 do not close selinux, the following creation process will be error ③ , Initialize database quotacheck # #执行该命令, you can create Quota.user and quota.group two database ④, enable quota function in the/home directory quotaon /home ⑤, edit Quotas edquota username Adjust file limit size and quantity ⑥, test su - username switch to the user for quota testing
Soft RAID does not introduce the production of mostly hard raid
Four Logical Volume managers
Create a logical volume process # #sdb  SDC is two new hard disk ①, creating a physical volume pv (Physical volume) pvcreate /dev/sd{b,c} # #可使用pvdisplay查看是否创建成功 ②, create Volume group vg (volume Group) vgcreate -s 16m vg_test /dev/sd{b,c} # #创建卷组 and add PV to the volume group,-s specify PE size # #PE: Create basic unit of LV, PE value should not be too small, otherwise, disk may produce fragmentation, affect disk performance. ③, creating logical Volumes lv (logical volume) lvcreate -l 2g -n lv_test vg_test ## Create a 2G-size logical Volume ④, create file system mkfs.xfs /dev/vg_test/lv_test # #创建xfs文件系统 ⑤, mounting mount /dev/vg_test/lv_test /mnt/lv_test Extending logical volumes lvextend -r -l +3g lv_test ## Extend the space and file system together reduce logical volume ①, un-mount umount /mnt/lv_test ②, check file system e2fsck -f /dev/vg_test/lv_test ③, shrink file system resize2fs|xfs_grows lv_test 5G # #resize2fs针对ext系列文件系统缩减, xfs_grows reduces ④, reduces space for XFS file systems lvreduce -l 5g /dev/vg_test/lvtest # #注意, File system and space reduction sizes must be consistent  Remove disk/DEV/SDB process ①, transfer/dev/sdb data pvmove /dev/sdb ②, after the data transfer is complete, remove the/DEV/SDB from the disk vgreduce /dev/sdb ③, delete pv pvremove /dev/sdb Create a snapshot lvcreate snap_test -l 1g -s -p r /dev/vg_test/lv_test -L Specify the snapshot size -s specify that the logical volume is snapshot -p r Configure this snapshot as read-only
It is recommended that LVM and RAID array disks be used together!
Linux-based Disk Management