Disk Management and Disk Quota under Linux

Overview of this article

①Disk basics
②Detect and confirm the new hard disk
③Plan the partitions in the hard disk
④Create a file system (format)
⑤Mount and unmount the file system

1. Disk structure

The physical structure of the hard disk
1. Disk: the hard disk has multiple disks, each with 2 sides
2. Magnetic head: one magnetic head on each side

Hard disk data structure
1. Sector: The disk is divided into multiple sector areas, each sector stores 512 bytes of data
2. Track: Concentric circles with different radii on the same disk
3. Cylinder: the same on different disks Cylindrical surface

Hard disk storage capacity = number of heads, the number of tracks (cylinders), the number of sectors per track * the number of bytes per sector.
Cylinders/heads/sectors can be used to uniquely locate each area on the
disk. Disk interface type: IDE (eliminated), SATA (notch), SCSI (basically eliminated, low configuration SAS), SAS (convex port), Fibre Channel (square head, etc.)

2. MBR and disk partition representation

Master Boot Record (MBR: Master Boot Record)
1. MBR is located at the first physical sector of the hard disk 2. MBR
contains the master boot program of the hard disk and the hard disk partition table
3. The partition table has 4 partition recording areas, each partition Recording area occupies 16 bytes
MBR≤4 partitions

In Linux, devices such as hard disks and partitions are all represented as files.
Example: /dev/hda5
/dev: (the directory where the hardware device files are located)
hd: stands for IDE devices, sd stands for SCSI devices
a: the serial number of the hard disk, with letters a, b, c...represent
5: the sequence number of the partition, with numbers 1, 2, 3... representing the
division into primary partition and extended partition (primary partition≥1)

Disk partition structure
1. The number of primary partitions in the hard disk is only 4.
2. The serial numbers of primary and extended partitions are limited to 1~4
3. Extended partitions are then divided into logical partitions
4. The number of logical partitions will always start from 5.

Three, file system type

XFS file system
1. Partition for storing files and directory data
2. High-performance journal file system
3. File system used by default in Centos7 system

SWAP swap file system
to create swap partition for Linux system

Other file system types supported by Linux:
FAT16, FAT32, NTFS, EXT4, JFS, etc.

Fourth, detect and confirm the new hard drive

fdisk command
View or manage disk partition
fdisk -l [disk device] or fdisk [disk device]

Five, create a file system

1. mkfs command
Make Filesystem, create a file system (format)
mkfs -t (mandatory) file system type partition device
or mkfs. file system type partition device

2. mkswap command
make swap, create a swap file system
mkswap partition device

Six, mount and unmount the file system

1. The
mount command mounts the file system and ISO image to the specified folder
mount [-t type] storage device mount point directory
mount -o loop ISO image file mount point directory (mounting with attributes, temporary mounting needs to be After loading, enter mount)
2. umount command to
unmount the mounted file system
umount storage device location
umount mount point directory

Seven, set the automatic mounting of the file system (permanent mounting)

/etc/fstab configuration file
Contains file system records that need to be automatically mounted after booting
vi /etc/fstab
/dev/sdb1 (partition) /mailbox (mount point) xfs (file system) defaults 0 0
or:
/dev/sdb1 (Partition) /mailbox (mount point) xfs (file system) defaults, loop (with attributes) 0 0
Note: After mounting permanently with attributes, you can enter mount -a to make the configuration take effect immediately, otherwise you need to restart

Eight, disk partition (parted)

If the disk is smaller than 2TB, you can use fdisk /dev/sdb to partition, that is,
if the disk is larger than 2TB, you can use parted /dev/sdb to partition. We all know that MBR partition disks cannot be larger than 2TB, so GPT is required for more than 2TB. Partition format

We first use the fdisk -l command in the super user mode to view the mounted hard disk device, assuming the device number is /dev/sdb, then we use the parted command to GPT partition
1.yum install parted -y
parted /dev/sdb
2
.Adjust the MBR disk partition format to GPT (parted) mklabel gpt
3. Divide all the space into a partition
(parted) mkpart primary 0-1
or unit TB (set the unit to TB)
mkpart primary 0 3 (set as a primary partition, The size is 3TB, the start is 0, and the end is 3)
4. Display the set partition size
(parted) print
5. Exit the parted program
(parted) quit
6. After the partition is done with parted, format the operation, and it will be done after completion Can be mounted using
mkfs.ext4 -F /dev/sdb1
7. Finally, add /etc/fstab to automatically mount

Nine, LVM and disk quotas

1. LVM (logical volume manager, logical volume management)
①. Dynamically adjust the disk capacity to improve the flexibility of disk management
② The /boot partition is used to store boot files and cannot be created based on LVM
③ Graphical interface management tool system-config-lvm
The first hard disk does not do lvm, because it needs to be formatted last night, lvm≥100G
2. The basic concept of the LVM mechanism
①PV (physical volume)
-the entire hard disk partition ②VG (volume group)
-physical volume consolidation ③LV ( Logical volume)-further refine the volume group

Main commands
Function physical volume management volume group management logical volume management
Scan scan pvscan vgscan lvscan
Create create pvcreate vgcreate lvcreate
Display display pvdisplay vgdisplay lvdisplay
Remove delete pvremove vgremove lvremove
Extend extension — vgextend lvextend
Reduce — vgreduce lvreduceLV
Recommended steps
PV→ VGuceLV → Format, mount using the file system
pvcreat device name 1 [device name 2]
vgcreate volume group name physical volume name 1 physical volume name 2
lvcreate –L capacity size –n logical volume name volume group name
lvextend –L +size/dev/ Volume group name/logical volume name

X. Overview of implementing disk quotas

Conditions for realizing disk quota ①Need
Linux kernel support
②Install xfsprogs and quota software package
Linux disk quota characteristics.
Scope:
Restrictions for the specified file system (partition) Object: user account, group account
Limit type: disk capacity, number of files
Limitation method: soft limit, hard limit

Experimental examples:
1. Ensure that there is a software function of disk quota
rpm -q quota
If not, you need to install the xfsprogs software at rpm
2. Mount lvm disk with attributes
temporarily mount: mount -o usrquota, grpquota /dev/lvm/cloud /data is
permanently mounted: vi /etc/fstab
/dev/lvm/cloud /data xfs defaults, usrquota, grpquota 0 0
mount -a (load the contents of the configuration file in /etc/fstab)
3. Write to the /data directory Permission
chmod –R 777 /data
4. Limit liming user lvm disk quota, soft limit is 60M, hard limit is 80M, file soft limit is 3, file hard limit is 4
xfs_quota –x –c'limil –u bsoft=60M bhard =80M isoft=3 ihard=4 liming' /data
-x: expert mode -c: command

Test and verify the effect:
su liming
cd /data
dd if=/dev/zero of=./1.txt bs=100M count=1
ls –lh
5. Limit ag group user lvm disk quota
groupadd ag
useradd –g ag lisi
passwd lisi
xfs_quota –x –c'limil –g bsoft=80M bhard=100M isoft=5 ihard=6 ag' /data

Test and verify the effect
su lisi
cd /data
dd if=/dev/zero of=./2.txt bs=120M count=1
ls --lh

6. View the reports of users and groups on their directories.
In super user mode
xfs_quota -x -c'report -ubih' /data
xfs_quota -x -c'report -gbih' /data
b-block disk capacity
i-inode Number of files

Guess you like

Origin blog.csdn.net/yuiLan0/article/details/108252169