Centos7 creates LVM and expands

This article was written 109 days ago and was last modified 109 days ago. Some of the information may be out of date.

**Environment is Centos7 system on VMware virtual machine**
  1. List the current system disk information, you can see that /dev/sdb is available
[ root@xls ~]# fdisk -l

Disk /dev/sda:21.5 GB,21474836480 bytes,41943040 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk label type: dos
Disk identifier:0x00000a46

 Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *20482099199104857683  Linux
/dev/sda2         20992004194303919921920   8e  Linux LVM

Disk /dev/mapper/cl-root:18.2 GB,18249416704 bytes,35643392 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk /dev/mapper/cl-swap:2147 MB,2147483648 bytes,4194304 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk /dev/sdb:10.7 GB,10737418240 bytes,20971520 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
  1. Partition using fdisk
[ root@xls ~]# fdisk /dev/sdb

Command(m for help): p #Print the partition and view the current partition status

Disk /dev/sdb:10.7 GB,10737418240 bytes,20971520 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk label type: dos
Disk identifier:0x62cab278

 Device Boot      Start         End      Blocks   Id  System

Command(m for help): n #Start partition
Partition type:
 p   primary(0 primary,0 extended,4 free)
 e   extended
Select(default p): p #Select primary partition
Partition number(1-4,default1):1 #Partition number 1
First sector(2048-20971519,default2048):  #Press Enter to select the default value
Using default value 2048
Last sector,+sectors or +size{K,M,G}(2048-20971519,default20971519):  #Press Enter to select the default partition size
Using default value 20971519
Partition 1of type Linux and of size 10 GiB is set
  1. Modify the partition type, 8e is the LVM partition type
Command(m for help): p #Print the partition and view the current partition status
Disk /dev/sdb:10.7 GB,10737418240 bytes,20971520 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk label type: dos
Disk identifier:0x62cab278

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048209715191048473683  Linux

Command(m for help):Command(m for help): t #Change partition type
Selected partition 1
Hex code(type L to list all codes): 8e #lvm partition type
Changed type of partition 'Linux' to 'Linux LVM'Command(m for help): p #Print the partition, you can see that the type is changed to 8e, linux LVM

Disk /dev/sdb:10.7 GB,10737418240 bytes,20971520 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk label type: dos
Disk identifier:0x62cab278

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            20482097151910484736   8e  Linux LVM
Command(m for help): w #Save partition
  1. Start creating pv
[ root@xls ~]# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created.
  1. View pv information
[ root@xls ~]# pvdisplay 
 - - - Physical volume ---
 PV Name               /dev/sda2
 VG Name               cl
 PV Size               19.00 GiB / not usable 3.00 MiB
 Allocatable           yes(but full)
 PE Size               4.00 MiB
 Total PE              4863
 Free PE               0
 Allocated PE          4863
 PV UUID               yunbOn-2uCl-9Xtr-wWV0-3jkn-fUoz-xpw6Ap

 " /dev/sdb1" is a newphysical volume of"10.00 GiB"--- NEW Physical volume ---
 PV Name               /dev/sdb1
 VG Name               
 PV Size               10.00 GiB
 Allocatable           NO
 PE Size               0   
 Total PE              0
 Free PE               0
 Allocated PE          0
 PV UUID               k8y4on-IAJP-URy6-l3eu-xmUH-D3Ov-OI3yfb
  1. Create VG, xls_vg is the name of vg
[ root@xls ~]# vgcreate xls_vg /dev/sdb1
 Volume group "xls_vg" successfully created
  1. View VG information
[ root@xls ~]# vgdisplay 
 - - - Volume group ---
 VG Name               xls_vg
 System ID             
 Format                lvm2
 Metadata Areas        1
 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                1
 Act PV                1
 VG Size               10.00 GiB
 PE Size               4.00 MiB
 Total PE              2559
 Alloc PE / Size       0/0   
 Free  PE / Size       2559/10.00 GiB
 VG UUID               NczNSi-vCaA-pe9L-Q857-GDig-ME0f-zzxRiB
  1. Create lv, and allocate space, here is all the 10 Gs out, xls_lv is the name of lv
[ root@xls ~]# lvcreate -L 10000M -n xls_lv xls_vg
 Logical volume "xls_lv" created.
  1. View lv information
[ root@xls ~]# lvdisplay 
 - - - Logical volume ---
 LV Path                /dev/xls_vg/xls_lv
 LV Name                xls_lv
 VG Name                xls_vg
 LV UUID                fXQxBc-UYQi-4T6y-gkmE-e9FC-ACy3-YfATDN
 LV Write Access        read/write
 LV Creation host, time xls,2020-04-0122:55:12-0400
 LV Status              available
 # open                 0
 LV Size                9.77 GiB
 Current LE             2500
 Segments               1
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     8192
 Block device           253:2
  1. Format the file system
[ root@xls ~]# mkfs.ext4 /dev/xls_vg/xls_lv 
  1. Mount the disk
[ root@xls ~]# mount /dev/xls_vg/xls_lv /data/[root@xls ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/cl-root         17G 1020M   16G   6% /
devtmpfs                   478M     0  478M   0%/dev
tmpfs                      489M     0  489M   0%/dev/shm
tmpfs                      489M  6.7M  482M   2%/run
tmpfs                      489M     0  489M   0%/sys/fs/cgroup
/dev/sda1                 1014M  139M  876M  14%/boot
tmpfs                       98M     0   98M   0%/run/user/0/dev/mapper/xls_vg-xls_lv  9.5G   37M  9.0G   1%/data
  1. Set the mount to not fail after restart
[ root@xls ~]# vi /etc/fstab 
/dev/mapper/xls_vg-xls_lv /data                 ext4    defaults        00
  1. Start to expand lvm, add a 5G hard disk to the virtual machine, and use echo to read the new hard disk
[ root@xls ~]# echo "- - -">/sys/class/scsi_host/host2/scan
[ root@xls ~]# fdisk -l
Disk /dev/sdc:5368 MB,5368709120 bytes,10485760 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
  1. Partition the newly added hard disk, the partition operation is the same as above
[ root@xls ~]# fdisk /dev/sdc
Welcome to fdisk(util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a newDOS disklabel with disk identifier 0x8dd3be7d.Command(m for help): n
Partition type:
 p   primary(0 primary,0 extended,4 free)
 e   extended
Select(default p): p
Partition number(1-4,default1): 
First sector(2048-10485759,default2048): 
Using default value 2048
Last sector,+sectors or +size{K,M,G}(2048-10485759,default10485759): 
Using default value 10485759
Partition 1of type Linux and of size 5 GiB is setCommand(m for help): p

Disk /dev/sdc:5368 MB,5368709120 bytes,10485760 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk label type: dos
Disk identifier:0x8dd3be7d

 Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            204810485759524185683  Linux

Command(m for help): t
Selected partition 1
Hex code(type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'Command(m for help): w
  1. Create the newly added hard disk /dev/sdc1 as pv
[ root@xls ~]# pvcreate /dev/sdc1 
 Physical volume "/dev/sdc1" successfully created.
  1. View pv
[ root@xls ~]# pvscan 
 PV /dev/sdb1   VG xls_vg          lvm2 [10.00 GiB /236.00 MiB free]
 PV /dev/sda2   VG cl              lvm2 [19.00 GiB /0    free]
 PV /dev/sdc1                      lvm2 [5.00 GiB]
 Total:3[33.99 GiB]/in use:2[28.99 GiB]/in no VG:1[5.00 GiB]
  1. Add /dec/sdc1 to vg:xls_vg
[ root@xls ~]# vgextend xls_vg /dev/sdc1
 Volume group "xls_vg" successfully extended
[ root@xls ~]# vgdisplay  #It can be seen that the vg space has increased from the original 10g to 15g
 - - - Volume group ---
 VG Name               xls_vg
 System ID             
 Format                lvm2
 Metadata Areas        2
 Metadata Sequence No  3
 VG Access             read/write
 VG Status             resizable
 MAX LV                0
 Cur LV                1
 Open LV               1
 Max PV                0
 Cur PV                2
 Act PV                2
 VG Size               14.99 GiB
 PE Size               4.00 MiB
 Total PE              3838
 Alloc PE / Size       2500/9.77 GiB
 Free  PE / Size       1338/5.23 GiB
 VG UUID               NczNSi-vCaA-pe9L-Q857-GDig-ME0f-zzxRiB
  1. Expand lv, here all free space in vg is expanded into lv
[ root@xls ~]# lvextend -l +100%FREE /dev/xls_vg/xls_lv 
 Size of logical volume xls_vg/xls_lv changed from9.77GiB(2500 extents) to 14.99GiB(3838 
extents).
 Logical volume xls_vg/xls_lv successfully resized.
  1. Check lv information, the space has been expanded to 15g
[ root@xls ~]# lvdisplay 
 - - - Logical volume ---
 LV Path                /dev/xls_vg/xls_lv
 LV Name                xls_lv
 VG Name                xls_vg
 LV UUID                fXQxBc-UYQi-4T6y-gkmE-e9FC-ACy3-YfATDN
 LV Write Access        read/write
 LV Creation host, time xls,2020-04-0122:55:12-0400
 LV Status              available
 # open                 1
 LV Size                14.99 GiB
 Current LE             3838
 Segments               2
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     8192
 Block device           253:2
  1. Write the expanded space into the file system. If the file system format is xfs, use the xfs_growfs command
[ root@xls ~]# resize2fs /dev/xls_vg/xls_lv 
resize2fs 1.42.9(28-Dec-2013)
Filesystem at /dev/xls_vg/xls_lv is mounted on /data; on-line resizing required
old_desc_blocks =2, new_desc_blocks =2
The filesystem on /dev/xls_vg/xls_lv is now 3930112 blocks long.
  1. View the information after disk expansion
[ root@xls ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/cl-root         17G 1021M   16G   6% /
devtmpfs                   478M     0  478M   0%/dev
tmpfs                      489M     0  489M   0%/dev/shm
tmpfs                      489M  6.8M  482M   2%/run
tmpfs                      489M     0  489M   0%/sys/fs/cgroup
/dev/sda1                 1014M  139M  876M  14%/boot
tmpfs                       98M     0   98M   0%/run/user/0/dev/mapper/xls_vg-xls_lv   15G   41M   14G   1%/data

Recommended Posts

Centos7 creates LVM and expands
Centos7 creates LVM disk management
Install centos7 and connect
Vmware-install and start Centos 8
Vmware-install and start Centos 7
centos7 install python3 and ipython
Centos mysql installation and configuration
Know Linux and install CentOS
CentOs7.3 compile and install Nginx 1.9.9
Centos7 installation and configuration prometheus
CentOS6.5 install Java 8 and Tomcat8
CentOS 7 installation and configuration PPTP
Centos compile and install Git
Centos 6.10 reinstall python and yum
CentOS installation and configuration cmake
Centos7.5 installation and configuration MongoDB4.0.4
CentOS 7 installation and configuration PPTP
Centos6.5 install and configure mongodb
centos7 kvm installation and use
CentOS7 install python3 and pip3
CentOS7 install OracleJDK and JRE
CentOS6.5 install Java 8 and Tomcat8
CentOS common exceptions and solutions
CentOS6 install and crack Jira 7
CentOS6.5 install Java 8 and Tomcat8
CentOS7 postgresql installation and use
Centos7 compile and install ntp-4.2.8p11
CentOS 6.9 compile and install python
CentOS6 install and crack confluence
CentOS 6 compile and install python 3
CentOS6 install and crack Jira 7
The difference between CentOS 7 and CentOS 6
Centos7 elk7.1.1 installation and use
Centos 7 install jdk and package service service
CentOS7 yum install and start mysql
Centos7 installation and configuration of Jenkins
Install and configure keepalived under CentOS 5.9
Ubuntu creates users adduser and useradd
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
CentOS 8 install Git and basic configuration
The difference between CentOS and Ubuntu
Use Nginx and u under CentOS
Centos6.5 installation and deployment of KVM
Centos7 hadoop cluster installation and configuration
CentOS7 installation and maintenance of Gitlab
Upgrade OpenSSL and OpenSSH under CentOS7
CentOS 6.x compile and install Nginx
CentOS7 compile and install L(A|N)MP environment
CentOS7.2 and Nginx configuration virtual host
CentOS7.3 install iptables and detailed use
Deploy and optimize Tomcat under Centos
CentOS 8 - install and configure NFS service
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos7 uninstall openJdk, and install JDK1.8
CentOS 7.X system installation and optimization
Java-JDK installation and configuration under CentOS
Install Python3 and ansible under CentOS8
Install and use docker under CentOS 6.8
CentOS 7 Tomcat service installation and configuration
Centos 7 RAID 5 detailed explanation and configuration