Linux learning my way (Section X)

=== === pick IX

(C) LVM Logical Volume Manager

LVM allows users to dynamically adjust resources on the hard disk. LVM technology between the hard disk partition and file system adds a logical layer that provides an abstraction of the volume group can be a combination of multiple disks and by rolling. Users do not have the underlying architecture and layout of the physical machine's hard disk can be achieved dynamically adjust the hard disk partition.

Logical Volume Manager technology structure:

PE basic units consisting of a hard disk: Physical Extent (PE default size 4.00MiB)

Physical volume PV: Physical Volume, may be a physical hard disk partition or RAID set.

Volume group VG: Volume Group

Logical Volume LV: Logical Volume

3.1, the deployment of logical volumes

LVM common deployment command:

Function / Command

Physical Volume Management

Volume Group Management

Logical Volume Management

scanning

pvscan

vgscan

lvscan

set up

pvcreate

vgcreate

lvcreate

display

pvdisplay

vgdisplay

lvdisplay

delete

pvremove

vgremove

lvremove

Spread

--

vgextend

lvextend

Narrow

--

vgreduce

lvreduce

(1) create a physical volume

[Root @ linuxprobe ~] # pvcreate / dev / sdb / dev / sdc // create a hard disk to / dev / sdb, / dev / sdc physical volume

  Physical volume "/dev/sdb" successfully created

  Physical volume "/dev/sdc" successfully created

[Root @ linuxprobe ~] # pvdisplay // check the created physical volume, volume group is empty

   "/dev/sdc" is a new physical volume of "10.00 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sdc

  VG Name

  PV Size               10.00 GiB

  Allocatable           NO

  PE Size               0

  Total PE 0

  Free PE 0

  Allocated PE          0

  PV UUID               3eHCPs-SWDN-Q0xW-H35F-L8Hw-7oWT-FhrS21

 

  "/dev/sdb" is a new physical volume of "10.00 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sdb

  VG Name

  PV Size               10.00 GiB

  Allocatable           NO

  PE Size               0

  Total PE 0

  Free PE 0

  Allocated PE          0

  PV UUID bYTCj6 DSP I1pI will VKw3 B5FW 5vetRr

(2) create a volume group

[Root @ linuxprobe ~] # vgcreate mlgvg / dev / sdb / dev / sdc // physical volumes / dev / sdb, / dev / sdc to create a volume group

  Volume group "mlgvg" successfully created

[Root @ linuxprobe ~] # pvdisplay // check the created physical volumes, volume groups have been shown to

  --- Physical volume ---

  PV Name               /dev/sdb

  VG Name               mlgvg

  PV Size               10.00 GiB / not usable 4.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE 2559

  Free IN 2559

  Allocated PE          0

  PV UUID bYTCj6 DSP I1pI will VKw3 B5FW 5vetRr

 

  --- Physical volume ---

  PV Name               /dev/sdc

  VG Name               mlgvg

  PV Size               10.00 GiB / not usable 4.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE 2559

  Free IN 2559

  Allocated PE          0

  PV UUID               3eHCPs-SWDN-Q0xW-H35F-L8Hw-7oWT-FhrS21

[Root @ linuxprobe ~] # vgdisplay // Check creates a volume group

  --- Volume group ---

  VG Name               mlgvg

  System ID

  format lvm2

  Metadata Areas        2

  Metadata Sequence No  1

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV 0

  Open LV               0

  Max PV                0

  Cur PV                2

  Act PV                2

  VG Size               19.99 GiB

  PE Size               4.00 MiB

  Total PE 5118

  Alloc PE / Size       0 / 0

  Free  PE / Size       5118 / 19.99 GiB

  VG UUID               hxvsyg-U6OO-dK3f-WU4i-3Nrr-TYmP-Qy3yZR

(3) create a logical volume

[Root @ linuxprobe ~] # lvcreate -n mlglv -l 100 mlgvg // In -l parameter (the number of basic units PE) to create a logical volume mlglv, size 100 * 4M = 400M.

  Logical volume "mlglv" created

[Root @ linuxprobe mlgvg] # lvcreate -n mlglv2 -l 200 mlgvg // In -l parameter (the number of basic units PE) to create a logical volume mlglv2, size 200 * 4M = 800M.

  Logical volume "mlglv2" created

[Root @ linuxprobe ~] # lvdisplay // create logical view

  --- Logical volume ---

  LV Path                /dev/mlgvg/mlglv

  LV Name                mlglv

  VG Name                mlgvg

  LV UUID                52pQW5-Zhv0-WjoF-cMFO-kgjR-qlZR-ZDHkJ7

  LV Write Access        read/write

  LV Creation host, time linuxprobe.com, 2020-03-06 19:36:15 +0800

  LV Status              available

  # open                 0

  LV Size                400.00 MiB

  Current LE             100

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:2

--- Logical volume ---

  LV Path                /dev/mlgvg/mlglv2

  LV Name                mlglv2

  VG Name                mlgvg

  LV UUID                8rn2PC-bQcZ-MErf-ENBC-JC93-ekiF-AFxgbr

  LV Write Access        read/write

  LV Creation host, time linuxprobe.com, 2020-03-06 19:41:37 +0800

  LV Status              available

  # open                 0

  LV Size                800.00 MiB

  Current LE             200

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:3

Note: xfs file system does not support LVM technology, so the LVM expansion and the need to use the ext4 file system to format the partition.

[Root @ linuxprobe ~] # mkfs.ext4 / dev / mlgvg / mlglv // file system is formatted

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

102400 inodes, 409600 blocks

20480 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=34078720

50 block groups

8192 blocks per group, 8192 fragments per group

2048 inodes per group

Superblock backups stored on blocks:

        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

 

Allocating group tables: done

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

[Root @ linuxprobe ~] # mkdir / mlglv1 // create a mount point, mount LVM logical volume created and see if mount successful.

[root@linuxprobe ~]# mount /dev/mlgvg/mlglv /mlglv1/

[root@linuxprobe ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/rhel-root     18G  3.2G   15G  19% /

devtmpfs                 985M     0  985M   0% /dev

tmpfs                    994M   80K  994M   1% /dev/shm

tmpfs                    994M  8.9M  986M   1% /run

tmpfs                    994M     0  994M   0% /sys/fs/cgroup

/dev/sr0                 3.5G  3.5G     0 100% /mnt/cdrom

/dev/sda1                497M  119M  379M  24% /boot

/dev/mapper/mlgvg-mlglv  380M  2.3M  354M   1% /mlglv1

Note: If you need to turn on automatically mount a logical volume, you need to edit / etc / fstab configuration file, add the following content.

[root@linuxprobe ~]# vim /etc/fstab

# /etc/fstab

# Created by anaconda on Sun Feb 16 14:06:24 2020

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/rhel-root   /                       xfs     defaults        1 1

UUID=0026f461-b0a2-4d90-8304-7cb4d0575432 /boot                   xfs     defaults        1 2

/dev/mapper/rhel-swap   swap                    swap    defaults        0 0

/dev/sr0        /mnt/cdrom      iso9660 defaults        0       0

/dev/mlgvg/mlglv        /mlglv  ext4    defaults        0       0

/dev/mlgvg/mlglv2       /mlglv2 ext4    defaults        0       0

/dev/mlgvg/mlglv3       /mlglv3 ext4    defaults        0       0

Note: reboot After rebooting again, the system automatically mount the logical volume has been determined.

[root@linuxprobe ~]# df -h

Filesystem                Size  Used Avail Use% Mounted on

/dev/mapper/rhel-root      18G  3.2G   15G  19% /

devtmpfs                  985M     0  985M   0% /dev

tmpfs                     994M   80K  994M   1% /dev/shm

tmpfs                     994M  8.9M  986M   1% /run

tmpfs                     994M     0  994M   0% /sys/fs/cgroup

/dev/sr0                  3.5G  3.5G     0 100% /mnt/cdrom

/dev/sda1                 497M  119M  379M  24% /boot

/dev/mapper/mlgvg-mlglv2  772M  1.6M  714M   1% /mlglv2

/dev/mapper/mlgvg-mlglv   380M  2.3M  354M   1% /mlglv

/dev/mapper/mlgvg-mlglv3  477M  2.3M  445M   1% /mlglv3

(4) expansion of logical volumes

[Root @ linuxprobe ~] # lvextend -L 800M / dev / mlgvg / mlglv // logical volume / dev / mlgvg / mlglv expansion to 800M

  Extending logical volume mlglv to 800.00 MiB

  Logical volume mlglv successfully resized

[Root @ linuxprobe ~] # e2fsck -f / dev / mlgvg / mlglv // view the file system if there are problems.

e2fsck 1.42.9 (28-Dec-2013)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/mlgvg/mlglv: 11/102400 files (0.0% non-contiguous), 23456/409600 blocks

[root@linuxprobe ~]# resize2fs /dev/mlgvg/mlglv   

// reset the logical volume size, there is Red Hat's bug here, if you need to perform prompt "e2fsck -f / dev / mlgvg / mlglv" command again, you will need to do this several times to restart again or mount command or logic volume and then execute this command.

resize2fs 1.42.9 (28-Dec-2013)

Resizing the filesystem on /dev/mlgvg/mlglv to 819200 (1k) blocks.

The filesystem on /dev/mlgvg/mlglv is now 819200 blocks long.

[root@linuxprobe ~]# mount -a  

[root@linuxprobe ~]# df -h

Filesystem                Size  Used Avail Use% Mounted on

/dev/mapper/rhel-root      18G  3.2G   15G  19% /

devtmpfs                  985M     0  985M   0% /dev

tmpfs                     994M   80K  994M   1% /dev/shm

tmpfs                     994M  8.9M  986M   1% /run

tmpfs                     994M     0  994M   0% /sys/fs/cgroup

/dev/sr0                  3.5G  3.5G     0 100% /mnt/cdrom

/dev/sda1                 497M  119M  379M  24% /boot

/dev/mapper/mlgvg-mlglv2  772M  1.6M  714M   1% /mlglv2

/dev/mapper/mlgvg-mlglv3  477M  2.3M  445M   1% /mlglv3

/dev/mapper/mlgvg-mlglv   767M  2.5M  721M   1% /mlglv    

Note: Make sure that the operation of the logical volume / dev / mapper / mlgvg-mlglv has successfully expanded to 800M.

(5) the logical volume reduction

[root@linuxprobe mlglv]# cp /home/EPEL-linuxprobe.com.tar.bz2 ./

// copy data to a logical volume, narrow verify whether the logical volume will cause data loss.

[root@linuxprobe mlglv]# ll

total 125529

-rw-r - r--. 1 root root 128527996 Mar 6 19:53 EPEL-linuxprobe.com.tar.bz2

drwx------. 2 root root     12288 Mar  6 19:39 lost+found

[root@linuxprobe mlglv]# cd ..

Before [root @ linuxprobe /] # umount / mlglv // shrink logical volumes need to uninstall mount point.

 

[root@linuxprobe /]# e2fsck -f /dev/mlgvg/mlglv  

// first check the file system if there are problems, to ensure that data is not lost if there is no problem can be the next step.

e2fsck 1.42.9 (28-Dec-2013)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/mlgvg/mlglv: 12/204800 files (0.0% non-contiguous), 162135/819200 blocks

[Root @ linuxprobe /] # resize2fs / dev / mlgvg / mlglv 500M // followed by the re-set the logical volume size to 500M

resize2fs 1.42.9 (28-Dec-2013)

Resizing the filesystem on /dev/mlgvg/mlglv to 512000 (1k) blocks.

The filesystem on /dev/mlgvg/mlglv is now 512000 blocks long.

 

[Root @ linuxprobe /] # lvreduce -L 500M / dev / mlgvg / mlglv // Finally reduce the size of the logical volume 500M

  WARNING: Reducing active logical volume to 500.00 MiB

  THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce mlglv? [y/n]: y

  Reducing logical volume mlglv to 500.00 MiB

  Logical volume mlglv successfully resized

[Root @ linuxprobe /] # mount -a // mount, verify whether the logical volume reduced success.

[root@linuxprobe /]# df -h

Filesystem                Size  Used Avail Use% Mounted on

/dev/mapper/rhel-root      18G  3.2G   15G  19% /

devtmpfs                  985M     0  985M   0% /dev

tmpfs                     994M   80K  994M   1% /dev/shm

tmpfs                     994M  8.9M  986M   1% /run

tmpfs                     994M     0  994M   0% /sys/fs/cgroup

/dev/sr0                  3.5G  3.5G     0 100% /mnt/cdrom

/dev/sda1                 497M  119M  379M  24% /boot

/dev/mapper/mlgvg-mlglv2  772M  1.6M  714M   1% /mlglv2

/dev/mapper/mlgvg-mlglv3  477M  2.3M  445M   1% /mlglv3

/dev/mapper/mlgvg-mlglv   477M  125M  323M  28% /mlglv

[root@linuxprobe /]# cd /mlglv

[Root @ linuxprobe mlglv] # ll // verify that the data is lost.

total 125530

-rw-r -. r-- 1 root root 128527996 Mar 6 19:53 EPEL-linuxprobe.com.tar.bz2 // data is not lost

drwx------. 2 root root     12288 Mar  6 19:39 lost+found

Note: xfs file system can not be reduced, only increased.

Description: can be found by the following example, when creating a logical volume space is used up again using another physical volume to satisfy the logical volume space created according to a physical volume space.

[root@linuxprobe mlglv]# pvdisplay

   --- Physical volume ---

  PV Name               /dev/sdb

  VG Name               mlgvg

  PV Size               10.00 GiB / not usable 4.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE 2559

  Free IN 2109

  Allocated PE          450

  PV UUID bYTCj6 DSP I1pI will VKw3 B5FW 5vetRr

 

  --- Physical volume ---

  PV Name               /dev/sdc

  VG Name               mlgvg

  PV Size               10.00 GiB / not usable 4.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE 2559

  Free IN 2559

  Allocated PE          0

  PV UUID               3eHCPs-SWDN-Q0xW-H35F-L8Hw-7oWT-FhrS21

(6) The Logical Volume Snapshot

LVM snapshot volume function has two characteristics:

  • Snapshot volume must have a capacity equal to the capacity of the logical volume;
  • The snapshot volume for one time only, it will be immediately and automatically deleted once the restore operation.

[root@linuxprobe /]# lvcreate -L 500M -s -n mlglvsnap /dev/mlgvg/mlglv

// create a size of 500M, named mlglvsnap snapshot volume. -s create a snapshot volume.

  Logical volume "mlglvsnap" created

[root@linuxprobe /]# lvdisplay

--- Logical volume ---

  LV Path                /dev/mlgvg/mlglvsnap

  LV Name                mlglvsnap

  VG Name                mlgvg

  LV UUID                5C2nN7-klci-hfR2-I92v-Qw7y-sxIa-pFb566

  LV Write Access        read/write

  LV Creation host, time linuxprobe.com, 2020-03-06 20:09:21 +0800

  LV snapshot status     active destination for mlglv

  LV Status              available

  # open                 0

  LV Size                500.00 MiB

  Current LE             125

  COW-table size         500.00 MiB

  COW-table LE           125

  Allocated to snapshot  0.00%

  Snapshot chunk size    4.00 KiB

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:5

[Root @ linuxprobe mlglv] # rm -rf warm-linuxprobe.com.tar.bz2

// delete a file, then restore the snapshot volume, verify whether the recovery was successful.

[root@linuxprobe mlglv]# ll

total 12

drwx------. 2 root root 12288 Mar  6 19:39 lost+found

 

[Root @ linuxprobe /] # umount / mlglv // restore files need to uninstall the mount point by the snapshot volume.

[root@linuxprobe /]# lvconvert --merge /dev/mlgvg/mlglvsnap 

// restore the logical data protection through snapshot volume.

  Merging of volume mlglvsnap started.

  mlglv: Merged: 100.0%

  Merge of snapshot into logical volume mlglv has finished.

  Logical volume "mlglvsnap" successfully removed

[root@linuxprobe /]# mount -a

[root@linuxprobe /]# cd /mlglv

[root@linuxprobe mlglv]# ll

total 125530

-rw-r -. r-- 1 root root 128527996 Mar 6 19:53 EPEL-linuxprobe.com.tar.bz2 // verification confirmation data has been restored.

drwx------. 2 root root     12288 Mar  6 19:39 lost+found

[root@linuxprobe mlglv]#

Note: The snapshot volume, there is no complete recovery, snapshot creation of logical volumes can be restored only be used once.

(7) Removing a Logical Volume

A, uninstall the mount point

[root@linuxprobe /]# umount /mlglv

[root@linuxprobe /]# umount /mlglv2

[root@linuxprobe /]# umount /mlglv3

B, Vim edit delete / etc / fstab to automatically mount configuration.

C, delete the logical volume

[root@linuxprobe /]# lvremove /dev/mlgvg/mlglv

Do you really want to remove active logical volume mlglv? [y/n]: y

  Logical volume "mlglv" successfully removed

[root@linuxprobe /]# lvremove /dev/mlgvg/mlglv2

Do you really want to remove active logical volume mlglv2? [y/n]: y

  Logical volume "mlglv2" successfully removed

[root@linuxprobe /]# lvremove /dev/mlgvg/mlglv3

Do you really want to remove active logical volume mlglv3? [y/n]: y

  Logical volume "mlglv3" successfully removed

D, delete the volume group

[root@linuxprobe /]# vgremove /dev/mlgvg

  Volume group "mlgvg" successfully removed

E, remove the physical volume

[root@linuxprobe /]# pvremove /dev/sdb /dev/sdc

  Labels on physical volume "/dev/sdb" successfully wiped

  Labels on physical volume "/dev/sdc" successfully wiped

After the above operations are completed, then perform lvdisplay, vgdisplay, will not see the LVM information created before the time pvdisplay command to view information regarding LVM.

 

3.2, bug fixes

Note: If for an error to modify the configuration file and cause the system fails to start, you can modify the configuration mode by entering the following command-line operation to recover.

Example 1: The file system and mount point does not exist, but the / etc / fstab to mount configured to start automatically, will lead the host can not start.

reboot to restart the virtual machine operating system to enter the following interface, enter the password for the root user can modify the configuration file recovery.

3.3, modify the network card configuration

Note: After each modify the network card configuration need to restart the service card by the following command

[root@linuxprobe ~]# systemctl restart network

Method 1: by modifying the card configuration parameters to modify the configuration file, the main parameters are marked red.

[root@linuxprobe ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736

HWADDR=00:0C:29:E6:C2:BF

TYPE=Ethernet

BOOTPROTO=static或none

NAME=eno16777736

UUID=9e2ccb08-b59a-4b2f-a3fd-05b58bcc5574

ONBOOT=yes

IPADDR=192.168.10.10

#NETMASK=255.255.255.0

PREFIX=24

GATEWAY=192.168.10.1

DNS1=114.114.114.114

DNS2=8.8.8.8

[Root @ linuxprobe ~] # ifconfig // View card configuration

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.10.10  netmask 255.255.255.0  broadcast 192.168.10.255

        inet6 fe80::20c:29ff:fee6:c2bf  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:e6:c2:bf  txqueuelen 1000  (Ethernet)

        RX packets 6144  bytes 427796 (417.7 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 5284  bytes 659699 (644.2 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

方法2:通过nmtui命令打开图形界面修改网卡配置

[root@linuxprobe ~]# nmtui   //rhel5和rhel6的命令是setup

附:通过nmtui-hostname命令打开图形界面修改主机名

[root@linuxprobe ~]# nmtui-hostname

方法3:通过nm-connection-editor修改网卡配置。

[root@linuxprobe ~]# nm-connection-editor

方法4:图形菜单修改网卡配置

来源:站长平台

Guess you like

Origin www.cnblogs.com/1994july/p/12431428.html