HDD Management (partition, SWAP,LVM)
DPT: Partition table (64)
Partition mode: MBR,GPT
MSDOS: The total size of the hard disk is less than 2T (15 partitions)
1 partitions occupy 16 bytes, msdos can be divided into 4 partitions. Primary partition, extended partition, logical partition
HD SD VD
HD HD (IED)
SDA1 SD Indicates the interface type of the hard disk (SATA,SAS,SCSI); A represents the first hard drive; 1 represents the First partition
SDB2 B represents the second hard drive, 2 for the second partition
SDA5 5th partition (logical partition)
About size: B-KB-MB-GB-TB-PB-EB-ZB-YB unit 1024
Disk partitioning
FDISK-L//query all storage device status (including partition table)
Df-h//View mount status
Fdisk device files//Use the Fdisk Disk Management tool to manage disks
M View Help
n Add a new partition
P Show partition Table
D Delete Partition
Q Do not save and exit
W Save and exit
T change the partition's type number (type_id), note that this function does not actually work just to differentiate the function of the partition
Example: Fdisk/dev/vdb
Command (M for help): N//Create new partition
Command action//type of new partition created
E extended//"E" stands for extended partition
P primary partition (1-4)//"P" stands for primary partition range (1-4)
P//Create primary partition
Partition number (1-4): 1//Partition No. "1"
First cylinder (1-20805, default 1)://Start cylinder, default is "1"
Using Default value 1
Last cylinder, +cylinders or +size{k,m,g} (1-20805, default 20805): +500m
End cylinder or specific size, the specific size needs to be added "+" and the unit, only the number represents the cylinder number
Command (M for help): P//view partition table
disk/dev/vdb:10.7 GB, 10737418240 bytes
Heads, Sectors/track, 20805 cylinders
Units = Cylinders of 1008 * 516096 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x42e92285
Device Boot Start End Blocks Id System
/DEV/VDB1 1 1017 512536+ Linux
Command (M for help): N//New partition
Command Action
E Extended
P primary partition (1-4)
E//type is extended partition
Partition number (1-4): 4
First cylinder (1018-20805, default 1018):
Using Default Value 1018
Last cylinder, +cylinders or +size{k,m,g} (1018-20805, default 20805): +5g
Command (M for help): N
Command Action
L logical (5 or over)
P primary partition (1-4)
L//type is a logical partition, this option only appears if you have created an extended partition
First cylinder (1018-11421, default 1018):
Using Default Value 1018
Last cylinder, +cylinders or +size{k,m,g} (1018-11421, default 11421): +1g
Command (M for help): W
The partition table has been altered!
Calling IOCTL () to re-read partition table.
Syncing disks.
The appropriate configuration file appears without a warning prompt
[Email protected] ~]# ll/dev/vdb*
BRW-RW----. 1 root disk 252, 9 13:45/dev/vdb
BRW-RW----. 1 root disk 252, 9 13:45/dev/vdb1
BRW-RW----. 1 root disk 252, 9 13:45/DEV/VDB4
BRW-RW----. 1 root disk 252, 9 13:45/DEV/VDB5
BRW-RW----. 1 root disk 252, 9 13:45/DEV/VDB6
If a warning prompt appears, no corresponding configuration file is generated and a restart or command is required to regenerate
Partx-a/dev/vdb
Using partitions
1. partition, after generating partition file
2. Formatting mkfs.ext4/dev/vdb1
3. Mount Mount
Unmount partition
1. Uninstalling Umount
2. Go to the partition table to delete
Note: The use of the command is temporary and you want to permanently take care of the configuration file/etc/fstab
UUID//Device Unique identifier
Blkid//view UUID for all devices
UUID can be used when mounted
GPT Partitioned table partitioning (supports up to 2TB of hard disk partitions, up to 128 partitions)
Using the partitioning tool parted
[Email protected] ~]# PARTED/DEV/VDB
GNU Parted 3.1
Using/dev/vdb
Welcome to GNU parted! Type ' help ' to view a list of commands.
(parted) Help//View assistance
Align-check type N check partition N for TYPE (min|opt) alignment
Help [COMMAND] Print general help, or help on COMMAND
Mklabel,mktable Label-type Create a new Disklabel (partition table)
Mkpart Part-type [Fs-type] START END make a partition
Name Number name name partition number as name
Print [devices|free|list,all| Number] Display the partition table, available devices,
Free space, all found partitions, or a particular partition
Quit Exit Program
Rescue start END Rescue a lost partition near START and end
RM Number Delete Partition number
Select Device Choose the DEVICE to edit
Disk_set flag State Change the FLAG on selected device
Disk_toggle [flag] toggle the state of flags on selected device
Set number flag state change the FLAG on partition number
Toggle [Number [FLAG]] toggle the state of FLAG on partition number
Unit unit Set the default unit to unit
Version display the version number and copyright
Information of GNU Parted
(parted) Mklabel GPT//change the hard disk partition table to GPT
(parted) Mkpart primary 0-1//partitioning the entire disk into one partition
Warning:the resulting partition is not properly aligned for best performance.
Ignore/cancel? Ignore
(parted) print//view partition table
Model:virtio Block Device (VIRTBLK)
Disk/dev/vdb:10.7gb
Sector size (logical/physical): 512b/512b
Partition TABLE:GPT
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 10.7GB 10.7GB Primary
(parted) Quit//exit
[[email protected] ~]# MKFS.XFS/DEV/VDB1//Format the partition
META-DATA=/DEV/VDB1 isize=256 agcount=4, agsize=655298 blks
= sectsz=512 attr=2, projid32bit=1
= Crc=0
data = bsize=4096 blocks=2621191, imaxpct=25
= Sunit=0 swidth=0 blks
Naming =version 2 bsize=4096 ascii-ci=0 ftype=0
Log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 Blks, lazy-count=1
Realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]# MOUNT/DEV/VDB1/MNT//Mount use
[Email protected] ~]# df-h//view
Filesystem Size used Avail use% mounted on
/dev/mapper/vg--rhel7-root 18G 3.0G 15G 18%/
Devtmpfs 488M 0 488M 0%/dev
Tmpfs 498M 84K 497M 1%/DEV/SHM
Tmpfs 498M 6.8M 491M 2%/run
Tmpfs 498M 0 498M 0%/sys/fs/cgroup
/dev/mapper/vg--rhel7-home 497M 26M 472M 6%/Home
/DEV/VDA1 497M 119M 379M 24%/boot
/DEV/VDB1 10G 33M 10G 1%/mnt
Swap partition//virtual memory partition
1. How to use partitioning
1) Create a partition
2) format Partition MKSWAP/DEV/VDB1
3) Activate swap SWAPON/DEV/VDB1
4) View Swap Swapon-s
5) View all the information in memory free-m
2. Use large file mode
1) Create large file dd If=/dev/zero of=/tmp/swap bs=1m count=500
2) format large file Mkswap/tmp/swap
3) Activating Swapon/tmp/swap
4) View Swap Swapon-s
5) View all the information in memory free-m
Disk quotas
Role: Can limit the user to the hard disk can be space or the maximum number of files created, and there is a soft/hard limit
Soft limit: The user is prompted when a soft limit is reached, but allows the user to continue using it for a specified period of time
Hard limit: Prompts the user when a hard limit is reached, forcing the user to terminate the operation
Quotacheck//Detect disk quota usage for getting disk (create, check, and repair disk quotas)
If no files are generated quota.user and quota.group two files
Quota parameters//To display disk quota information for a user or group
Parameter user name or group name
-G to list the group's disk space display
Quotaon//disk quota function for activating the specified file system in the Linux kernel
Repquota//Export the specified partition or disk quota information for the file system in the format of the report
Edquota//Quota quota limit for super users to edit other users
-u Edit user's quota limit
-G Edit User Group quota limit
1. Create a partition
2. Formatting
3. Mount with option-O Usrquota,grpquota
The corresponding files in the 4./etc/skel directory are copied to the home directory
5. Change the permissions of the home directory, the owner and the owning group
6. Turn off SELinux Setenforce 0
7. Detect Quotacheck-cugm/home/student//will create two files in home directory
8. Activate disk quotas Quotaon/home/student!!! Quotaoff//Deactivate when you want to cancel disk quotas
9. View the report Repquota/home/student
10. Editing Quotas Edquota Student
11. View the user's disk quota information quota student
12. Verification
13. If you want to cancel disk quotas
[[email protected] ~]# fuser -vm /dev/sdb5(查看用户使用情况,会出现一个对应的pid,kill即可,别把root的删了!)
LVM (logical volume management)
PV VG LV
PV: Physical volume entire disk or disk partition
VG: A volume group consists of one or more PV
LV: Logical volume takes a portion of the space from the volume group to use
Partition---PV-----VG-----LV
Steps to create
1. Partitioning
2. Create PV PVCREATE/DEV/VDB1/DEV/VDB5/DEV/VDB6
3. Create the VG vgcreate VGTEST/DEV/VDB1/DEV/VDB5/DEV/VDB6
4. Create the LV lvcreate-n lvfile-l 1G vgtest
5. Formatting of LV Mkfs.ext4/dev/vgtest/lvfile
6. Mounting
View
PVS//View PV
Pvdisplay//Detailed View PV
VGS//View VG
Vgdisplay//Detailed view of VG
LVS//View LV
Lvdisplay//Detailed View LV
LV Storage directory/dev/vgtest/lvfile
/dev/mapper/vgtest-lvfile
Extended LV
First, make sure the VG is not enough
1.VG Sufficient condition
Lvextend/dev/vgtest/lvfile-l +1g//Extended LV
Resize2fs/dev/vgtest/lvfile//Extended file system
If the XFS file system needs to use Xfs_growfs/dev/vgtest/lvfile to extend the file system
2.VG of Insufficient condition
1) Add a hard drive
2) Create PV
3) Extended VG Vgextend vgtest/dev/vdb3
4) Extended LV Lvextend/dev/vgtest/lvfile-l +1g//Extended LV
5) Extended File system Resize2fs/dev/vgtest/lvfile//Extended file system
Zoom Out LV
Note: Rhel7 XFS file systems cannot be scaled down;
Steps to zoom Out
1.umount/media
2. Detection: e2fsck-f/dev/123/lv123//detection, total space, free space
3. Shrink file system: resize2fs/dev/123/lv123 1G//Reduce the LV file system to 1G
4. Reduce lv:lvresize/dev/123/lv123-l -2g//decrease LV space by 2G
The shrinking of the VG
Vgreduce VG's name PV location//Take some PV from the VG (here if you only use a partition or a hard disk to create PV, is not available)
Linux basic Commands (vii)