当前位置:网站首页>Disk space, logical volume

Disk space, logical volume

2022-06-30 07:30:00 My deep blue

disk

  • MBR-Main Boot Record ( Master boot record ) : Tell the hard disk how to
    Partition , Write it in the... Of the disk - In one sector .

characteristic :

  1. The primary partition has at least 1 individual , most 4 individual ,
  2. The extended partition may not have , most 1 individual . And the main partition + The total number of extended partitions cannot exceed 4 individual .
  3. Logical partitions can have several .
  4. The maximum partition and disk size allowed is 2T

 Insert picture description here

  • View available memory and virtual memory space
free -m
  • Look at the size of a directory or file
du

 Parameters 
-a: Display the disk usage of each sub file . By default, only the disk usage of subdirectories is counted 
-h: Use custom units to display disk usage , Such as KB,MB or GB etc. 
-s: Count the total consumption , The usage of subdirectories and sub files is not listed 
  • View the details of the current normal disk
df 

 Parameters 
-ht: Use custom units to display capacity , Such as KB,MB or GB Etc. to display the file system type 
-a: Show all file system information , Including special file systems , Such as /proc、 /sysfs
-m: With MB Show capacity in units 
-K: With KB Show capacity in units . Default is to KB In units of 

 Insert picture description here
/dev/mapper/cl -root : The root directory is stored , Logic volume
/dev/sda1: yes sda The first partition of the disk , Put the startup file
tmpfs: Disk driver

  • df and du The difference between
  1. df Commands are considered from the file system , It's not just about the space the file takes up , Also count the space occupied by commands or programs ( The most common is that the file has been deleted , But the program doesn't release space )
  2. du The command is file oriented , Only the space occupied by a file or directory is calculated

Swap space swap

Swap space = Virtual memory .

  1. Store inactive information in memory
  2. When memory is full , Use
  3. If the virtual memory is full , that Linux It's going to be very stuck , Even collapse
  • How much virtual space should we divide
Physical memory Swap partition (SWAP)
<=4G At least 4G
4G~16G At least 8G
16G~64G At least 16G
64G~256G At least 32G

Disk partition

Disk partition : Divide the hard disk into logical storage units .

Logical storage unit : Partition

The benefits of partitioning :

1、 Limit the available space for applications or users
2、 Allow the same - The hard disk is installed with different operating systems
3、 You can give virtual memory a separate partition
4、 Improve the performance of hard disk

step 1、 Partition

fdisk  /dev/sdb
// Yes  sdb  Partition the disk ,
// Prompt partition operation 
n: New normal partition 
T: Change partition ,82 yes swap
w: Save the created partition and exit 
d: Delete partition 
p: see 

Partition changes will stay in memory , If you need to write to disk , You need to save the operation

step 2、 Reread the new partition table

partprobe  /dev/sdb

step 3、 Create file system

Create file system = format

linux A lot of support file system ,ext4 and xfs
windows Support ,NTFS、FAT32

  • format Normal partition
mkfs.ext4 /dev/sdb1
// Format partition  sdb1  Not disk sdb
  • format Virtual partition
mkswap  /dev/sdb2

step 4、 mount

Mount the file system 、 Connect to the directory structure
Hook the directory to a disk

  • Create mount point
mkdir /mnt/mkd
//  Create mount point 
  1. Manual mount

The system will fail after restart . Used to detect formatted devices

mount /dev/sdb1 /mnt/mkd/
// take   Catalog   and   file system   mount 
  1. Permanently mount

You are about to add the device to /etc/fstab In the

vim /etc/fstab

 Insert picture description here

First step :

  1. The equipment to be used can be used UUID,
  2. You can also use device files blkid Check the... Of the device UUID Number ,

The second part :

  1. Write the mount point , Direct write already exists , There is no use mkdir To create

The third part

  1. File system type (ext4、xfs)

The fourth part

  1. When mounting , Custom options applied to the device ,defaults yes necessary

The fifth part

  1. Redeposit flag

Redeposit flag : Used to generate a backup of device content ,
0: Indicates that backup is not required
1: Indicates the need for backup

The sixth part

  1. fsck The order

fsck: When there are multiple file systems to check , The order of inspection .
0 Indicates no need to check , Boot and mount directly
1 Indicates the first mount after the check
2 Indicates the second mount after the check

  1. Common partition mount results
/dev/sdb1 /mnt/mkd ext4 defaults 0 0
  1. Virtual partition mount results
/dev/sdb2 swap swap defaults 0 0

Virtual partition , You don't need a mount point

Save exit written /etc/fstab Use mount -a Command to check whether the writing format is correct .

If the document is incorrectly written ,Linux You will not be able to power on

step 5、 Activate zone space

Normal partitions do not need to be activated
The virtual partition needs to be activated

swapon  View the activated virtual partitions 
swapon /dev/sdb2  Activate virtual partition 

Logic volume

Physical volume (PV) : Used to register basic physical devices , Mapping to physical devices

The volume group (VG): Storage pool , Consists of one or more physical volumes

Logic volume (LV): Allocate the free physical space according to the volume lease

Logical volume and logical partition are not the same concept

The role of logical volumes :

  1. If the normal partition is full , We can import the data to a larger disk , Very heavy workload , And very dangerous .
  2. Logical volume manager (LVM) You can manage disk space more easily , To solve a problem easily .
  • lvm Better than traditional hard disk storage

1、 Flexibility capacity - Allow multiple disks or partitions to be made into a logical volume
2、 Scalable storage pool one - You can modify logical volumes with commands , Without formatting
3、 Online data can be moved online after distribution , Hot swappable disks can be exchanged with
4、 Equipment naming is convenient
5、 The mirrored volume is very convenient for data mirroring
6、 Volume snapshot a snapshot saves all the contents of the logical volume

  • View command
  1. View physical volume information

pvdisplay /dev/sdc1

  1. View volume group information

vgdisplay lewis1

  1. View logical volume information

Ivdisplay /dev/lewis1/lewis2

Create logical volumes

step 1、 Create partitions

fdisk  /dev/sdc
T: Change to logical partition ,8e yes Linux LVM

step 2、 Reread the new partition table

partprobe  /dev/sdc

step 3、 Create a physical volume

pvcreate /dev/sdc1

step 4、 Create a volume group

vgcreate lewis1 /dev/sdb1
// Volume groups are also called storage pools 
// Create the name of the volume group lewis1
// hold  /dev/sdc1  Of capacity into   The volume group lewis1

step 5、 Create logical volumes

lvcreate -n lewis2 -L 1G lewis1
// establish  lewis2  The logical volume   The size is 1G  Size source volume group Lewis1

step 6、 Create file system

mkfs.ext4 /dev/lewis

step 7、 Create permanent mount

  • Create mount point
mkdir /mnt/mkd2
//  Create mount point 
/dev/lewis1/lewis2 /mnt/mkd2 ext4 defaults 0 0
  • Check
mount -a

Delete logical volume

  1. Cancel the mount
    umount /dev/lewis1/lewis2
    At the same time, delete /etc/fstable Contents of the file

  2. Remove logical volumes

lvremove /dev/lewis1/lewis2

  1. Remove volume group

vgremove lewis1

  1. Delete physical volume

pvremove /dev/sdc1
pvremove /dev/sdc2

Logical volume expansion

  • Yes ETX4 File system logical volume expansion
  1. If the volume group still has space , Increase the size of the logical volume directly

increase 20M

lvextend -L +20M /dev/lewis1/lewis2 

Effective operation

resize2fs /dev/lewis1/lewis2
  1. If the volume group does not have enough space , You need to increase the volume group space first ,
fdisk /dev/sdc
partprobe  /dev/sdc
pvcreate /dev/sdc2
vgextend lewis1 /dev/sdc2 // Add capacity to the original volume group 
  • Yes xfs File system logical volume expansion

The operation takes effect differently

xfs_growfs /dev/lewis1/lewis2
原网站

版权声明
本文为[My deep blue]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160541594064.html