Linux Storage Management (Part 1)

Linux pipes and redirection

Linux storage management

Basic partition

Introduction to Disk

Disk/hard disk/disk is the same thing, different from memory is the larger capacity

  • Principle distinction
    Mechanical hard disk: it is a traditional ordinary hard disk, mainly composed of: platters, magnetic heads, platters shaft and control motor, head controller, data converter, interface, cache and other parts.
    Solid-state drive: referred to as solid-state drive, solid-state drive is a hard drive made of solid-state electronic storage chip arrays.
    Illustration:
    Insert picture description here
    Disk related terms
  • Disk naming The
    kernel naming methods for hard disks with different interfaces:
    RHEL7/centos7:
    IDE (parallel port):
    /dev/hda
    /dev/hdb
    SATA (serial port):
    /dev/sda(/dev device file directory, s represents sata is the serial port , D stands for disk, a is the first block, sda is a file)
    /dev/sdb
  • Disk partition method
    MBR: The maximum disk capacity supported by MBR is <2TB, and 4 partitions are allocated during design. If you want to have more than 4 partitions, you need to abandon the primary partition and change to an extended partition and a logical partition.
    GPT: Globally Unique Identifier Partition Table (GPT) is a standard for the structure and layout of the partition table of a physical hard disk. GPT supports hard disks larger than 2T and supports 128 partitions.
Disk management
  • Adding a disk
    How to add a hard disk to our virtual machine?
    Insert picture description here
    Open the edit virtual machine settings,
    Insert picture description here
    click Add,
    Insert picture description here
    select the hard disk, and then all the way to the next step.
  • The trilogy of disk management process
    Partition (MBR or GPT) -> Format/Filesystem--> Mount
  • View disk information
    Method one:
ls -l /dev/sd*

Insert picture description here
/dev/sdb in /dev/sdb1, /dev/sdb2, /dev/sdb5 represents a disk, and 1, 2, and 5 represent the partitions of this disk.
Method Two:

lsblk

View block devices
Insert picture description here

  • Create partitions
    Step 1: MBR (in layman's terms, divide the house into bedrooms and living rooms)
    Step 2: Start the partition tool
fdisk /dev/磁盘名称
fdisk /dev/sdc

Step 3: Enter the conversation mode.
Insert picture description here
Press the n key,
Insert picture description here
press the p key,
press 1, press the enter key, and
enter +1G (note: the input range should not exceed the capacity of the disk, otherwise it will be prompted to exceed the range)
Insert picture description here
press w and Hit enter to save all operation results.
Insert picture description here

Step 4: Refresh the partition table

partprobe /dev/磁盘名称

Refresh preparation

partprobe /dev/sbc

Step 5: View the partition results

fdisk -l /dev/sdc

Insert picture description here
Or enter to lsdlkview the results
Insert picture description here

  • Create a file system
mkfs.ext4 /dev/sdc1

mk–>make creates
f–> files–
>system system
ext4–>extend4 The fourth generation of extended file system is a type of file system.
/dev/sdc1 The first partition of the second serial hard disk, ready to format.
Insert picture description here
Formatting is complete.

  • Mount
mkdir /mnt/disk1
mount -t ext4 /dev/sdc1 /mnt/disk1

Press down

df -hT
  • View mount information
    Insert picture description here
    Insert picture description here

Logical Volume LVM

purpose

A way to manage disks is no different from basic disks in nature.

Features

You can expand the size at will.
Insert picture description here
Unlike the basic partition, if the space of the created logical volume is full, no more data can be written, so we can allocate some space from the volume group to give the logical volume LVM and refresh the logical volume again. It becomes larger, and then you can continue to write data.

the term

PV: physical volume
VG: volume group
LV: logical volume

Create LVM
  • Prepare physical disk
lsblk
  • Convert physical disk to physical volume pv
pvcreate /dev/sdc
  • Create volume group
vgcreate 卷组名称 /dev/sdc
vgcreate vg1 /dev/sdc
  • Create logical volume
lvcreate -L 大小 -n 逻辑卷名称 卷组名称
lvcreate -L 200M -n lv2 vg1
  • format
mkfs.ext4 /dev/vg1/lv1
  • Prepare a folder
mkdir mnt /lv1
  • Mount
mount /dev/vg1/lv1 /mnt/lv1
  • verification
df -hT
  • data input
dd if=/dev/zero of=/mnt/lv1/1.txt bs=1M count=4000

At this time, the logical volume is full of data, can I directly extend LVM? The answer is yes, but only if there is space in the volume group, it can be called.

VG management

What if there is no space in the volume group? So we need to expand the volume group

  • Create PV and add it to the group
pvcreate /dev/sdg

Check the physical volume

pvs
  • Expand VG
vgextend vg1 /dev/sdg

Check out the volume group

vgs
LV expansion
  • View VG space
vgs
  • Expansion LV
lvextend -L +4G /dev/vg1/lv1
FS expansion
  • Observe the current capacity of the file system
df -Th
  • File system expansion
resize2fs /dev/vg1/lv2

Exchange partition management swap

Introduction
  • Function:'improve' the memory capacity to prevent OOM (out of memory)
  • Icon:
    Insert picture description here
  • swap size It is
    recommended to set the swap partition size to twice the size of the memory.
    In a production environment:

A system with more than 4GB but less than 16GB memory requires a minimum of 4GB swap space. A system with
more than 16GB but less than 64GB memory requires a minimum of 8GB swap space.
A system with more than 64GB but less than 256GB memory requires a minimum of 16GB swap space.

View the current swap partition
free -m

Insert picture description here

Increase swap partition
  • Prepare partition

Prepare to divide the /dev/sde disk into 1G partition as an example. After
dividing the partition, set the type to 82 (press t)
fdisk /dev/sde
partprobe /dev/sde
ls -l /dev/sd*

  • format

mkswap /dev/sde1

  • Mount

swapon /dev/sde1

  • verification

free -m

How to delete the created swap partition?

swapoff /dev/sdc1
  • Command to restart the computer
init 6

or it could be

reboot
  • How to fill a disk quickly? If there is a disk partition with a size of 1G
dd if=/dev/zero of=/mnt/disk4/1.txt bs=1M count=1000

Open another terminal

watch -n0.5 'df -hT'

Observe the partition written to the disk and
Insert picture description here
verify again

cp -rf /etc/ /mnt/disk4/

Insert picture description here
Since the computer's disk partition is full, an error will be reported when the file is copied again.
What happens when a disk is full?
Compared to cloud computing engineers, it is a suggestive error, but for the front end, it can't be written completely.
Insert picture description here
Therefore, the space of the physical disk is limited, which is not convenient for management, copying, deletion, and authorization.
Relying on physical disks alone cannot solve the problem of space growth.
Linux storage management (part 2)

Guess you like

Origin blog.csdn.net/qq_45671732/article/details/109586438