Disk and file system management

Disk and file system management

 

1. Plan the partitions in the hard disk

After connecting a new hard disk and device and starting the host, linux will automatically detect and load the hard disk without installing additional drivers.

fdisk command

Syntax: fdisk -l

Purpose: List all hard disk devices and their partition information in the current system

 

 

Note: Whether the boot is a boot partition, if yes, there is * to indicate the size of the blocks partition, in blocks (blocks), the default block size is 1024

Syntax: fdisk [ disk device ] to enter the partition management interface

Common commands in interactive mode

m: View the help information of the operation command

p: list view partition information

n: New partition

d: delete partition

t: change partition type

w: save partition settings and exit

q: Abandon partition settings and exit

After changing the partition of the hard disk, it is best to restart the system once, or execute the "partprode" command to make the operating system re-detect the new partition table to avoid data damage or system crash.

 

2. Create a file system

The process of creating a file system is also the process of formatting a partition. In the Linux system, the mkfs tool (makefilesystem, create a file system) command tool can format different types of partitions such as ext4 and fat, and the mkswap tool can format the swap partition. .

1): Mkfs is actually a front-end tool that can automatically load different programs to create various types of partitions, and the back-end includes multiple tool programs related to the mkfs command. These programs are located in the /sbin/ directory, such as support ext4 partition format mkfs, ext4 program, etc.

 

 

Syntax: mkfs –t filesystem type partition device

2 ): mkswap command

Purpose: make swap, create a swap file system (the role of the swap partition in linux is similar to the "virtual memory" in windows, which can alleviate the situation of insufficient physical memory to a certain extent)

Syntax: mkswap partition device

 

 

3. Mount and unmount the file system

mount command

Purpose: Mount the file system, ISO image to the specified folder

Syntax: mount [-t type  ]  storage device mount point directory

mount -o loop ISO image file mount point directory

When using the mount command without any parameters or options, information about each partition (file system) mounted in the current system will be displayed, and the most recently mounted file system will be displayed at the end.

 

 

umount command

Purpose: To unmount a mounted filesystem

Syntax: umount storage device location

umount mount point directory

CD device mount

 

 

ISO image file mount

root@localhost ~]#mount -o loop rhel-server-6.5-x86_64-dvd.iso /media/mnt

unmount filesystem

 

 

 

4. Set the automatic mount of the file system

The /etc/fstab file in the system can be regarded as the configuration file of the mount command. It stores the static mount data of the file system. When the Linux system is powered on, it will automatically read the contents of this file and automatically mount the specified file system. The default fstab file includes the root partition/boot partition swap partition, and the mount configuration of pseudo file systems such as proc and tmpfs.

By adding the corresponding mount configuration in the /dev/fstab file, you can realize the automatic mount specification after booting; after Reboot, check that it has been automatically mounted

 

5. View Disk Usage

You can use the df command, df command parameters: -h display a more readable capacity unit; -T display the corresponding file system type (two options can be used in combination)

 

6. LVM overview

 

 

Logical Volume Manager , logical volume management

Function: Dynamically adjust the disk capacity, thereby improving the flexibility of disk management

Note: The /boot partition is used to store boot files, and the GUI management tool system-config-lvm cannot be created based on LVM

Basic Concepts of LVM Mechanism

1): PV (Physical Volume, physical volume)

An entire hard disk, or a normal partition created with tools such as fdisk

Includes many PEs (Physical Extent, basic unit) with a default size of 4MB

2): VG (Volume Group, volume group)

A whole composed of one or more physical volumes

3): LV (Logical Volume, logical volume)

A space partitioned from a volume group for establishing a file system

 

 

 

 

7. LVM management commands

Function

Physical Volume Management

Volume group management

Logical volume management

Scan scan

pvscan

vgscan

lvscan

Create

pvcreate

vgcreate

lvcreate

Display

pvdisplay

vgdisplay

lvdisplay

Remove

pvremove

vgremove

lvremove

Extend

 

vgextend

lvextend

Reduce

 

vgreduce

lvreduce

main command

pvcreate device name 1 [ device name 2...]

vgcreate volume group name physical volume name 1     physical volume name 2

vgermove command - used to delete the specified volume group name, specify the volume group name as a parameter

lvcreate -L  capacity size -n  logical volume name volume group name

lvextend -L + size /dev/ VolumeGroupName / LogicalVolumeName

 

8. Case: Description of Requirements

The company plans to build a mail server (RHEL6 system platform) in the Internet to provide e-mail space for employees and some VIP customers all over the country

Due to the large number of users, mail storage requires a lot of space. Considering the need for dynamic expansion, it is planned to add two SCSI hard disks and build an LVM logical volume (mounted to the "/mailbox" directory) for storing mail data.

 

……

 

 

9. Expand the logical volume

Use the lvextend command to expand the capacity of the logical volume mbox

Allocate another 10GB from the volume group mail_store to the logical volume mbox

Use the resize2fs command to update the file system size recognized by the system

 

10. Overview of Disk Quotas

Conditions for achieving disk quotas

Requires Linux kernel support; install the quota package

 Features of Linux Disk Quotas

Scope: For the specified file system (partition)

Restricted objects: user accounts, group accounts

Limit type: disk capacity (default unit is KB); number of files

Limit method: soft limit; hard limit

 

11. Summary

Using the LVM dynamic disk scheme, disk space can be flexibly expanded.

The basic process of creating and using the LVM scheme: creating a physical volume - creating a volume group - creating a logical volume - formatting a file system - mounting and using.

The "usrquota,grpquota" mount parameter enables the file system to support disk quotas for user and group accounts.

Use command tools such as quotacheck. Edquota.Quotaon. Repquota to detect, set, enable and view disk quotas.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325904836&siteId=291194637