lvm Expansion measures

Test data

cd / && dd if=/dev/zero of=file bs=1M count=10000
 Test command to make the disk larger .  Don't use in production environment .  This is just to test the effect of the expansion 

LVM Basic commands :

pvdisplay  Check out pv
pvremove /dev/sdb    # Clear one pv
vgremove [vg name ]      # Clear one vg
lvremove [lv name ]      # Clear one lv

fdisk -l   Check the disk 
df -h      Check all disk sizes 
df -Th     Check disk size and partition format type 
pvdisplay  Check pv
vgdisplay  Check vg
lvdisplay  Check lv

0.   After adding the disk, it needs to be scanned for recognition

echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan

1. Check the current disk

[root@localhost /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   40G  9.6G   31G  24% /
devtmpfs                 982M     0  982M   0% /dev
tmpfs                    993M     0  993M   0% /dev/shm
tmpfs                    993M  8.7M  984M   1% /run
tmpfs                    993M     0  993M   0% /sys/fs/cgroup
/dev/sda1                197M  103M   95M  53% /boot
tmpfs                    199M     0  199M   0% /run/user/0

Be careful : /dev/mapper/centos-root It's the path of the logical volume .

2. Check pv   [ pvdisplay ]

[root@localhost /]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               19.80 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5069
  Free PE               0
  Allocated PE          5069
  PV UUID               4YLVja-jT6q-FphK-3E60-5Qde-Z3gw-zLpcYT
   
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               centos
  PV Size               <20.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               0
  Allocated PE          5119
  PV UUID               SBfuCJ-tli0-Mi2U-wO3w-eQub-0v36-0XkQBw

3. Check vg

[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.80 GiB
  PE Size               4.00 MiB
  Total PE              5069
  Alloc PE / Size       5069 / 19.80 GiB
  Free  PE / Size       0 / 0   
  VG UUID               lkJhAi-7Df5-0K69-LYV4-exS2-ZqE1-FYMyIG

4. Check lv

[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                tUUfhM-dDfU-Aw6K-tiAj-wyqf-cvbl-FcLOxj
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2019-11-22 04:12:42 +0800
  LV Status              available
  # open                 1
  LV Size                19.80 GiB
  Current LE             5069
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

Expansion ideas

1.  Add disks 
2.  Check the disk id  Change to the disk that needs to be expanded ID Agreement , adopt fdisk -l  You can see ID
[root@localhost ~]# fdisk -l /dev/sda
.....
 Device   Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648    41943039    20765696   8e  Linux LVM

 You can see ID yes  8e LVM, So the newly added disk also needs to be changed to  8e

3.  Create a physical volume  pv 
4. pv Join in vg The volume group 
5.  Expansion disk 
6.  Format disk 
7.  end 

Expansion disk

1. Add disks

xxx I mean to have sex with myself

2. Scan for new disks

  scanning :
 echo "- - -" > /sys/class/scsi_host/host0/scan
 echo "- - -" > /sys/class/scsi_host/host1/scan
 echo "- - -" > /sys/class/scsi_host/host2/scan

3. Partition change disk format to LVM:

##  Create a partition and change the disk format to  [8e]:
fdisk /dev/sdc [ Operate the new disk ]
 
[root@localhost /]# 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 new DOS disklabel with disk identifier 0xc7dec5f2.
	
	Command (m for help): n    #####----- Create partitions 
	Partition type:
	p   primary (0 primary, 0 extended, 4 free)
	e   extended
	Select (default p): 
	Using default response p   #####----- Create default primary partition [ The main partition can only be divided into 4 More than 4 Need to create extended partition ]
	Partition number (1-4, default 1): 
	First sector (2048-62914559, default 2048): 
	Using default value 2048
	Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
	Using default value 62914559
	Partition 1 of type Linux and of size 30 GiB is set
	
	Command (m for help): t       #####----- Change disk format  
	Selected partition 1
	Hex code (type L to list all codes): 8e        #####----- Change to 8e
	Changed type of partition 'Linux' to 'Linux LVM'
	
	
	Command (m for help): p     ###  Check to see if  8e

	Disk /dev/sdc: 32.2 GB, 32212254720 bytes, 62914560 sectors
	Units = sectors of 1 * 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: 0xc7dec5f2
	
	Device Boot      Start         End        Blocks    Id  System
	/dev/sdc1            2048    62914559    31456256   8e  Linux LVM    # It is 8e 了 

	
	Command (m for help): w     #####----- preservation 
	The partition table has been altered!
	
	Calling ioctl() to re-read partition table.
	Syncing disks.
	
	## Partition and disk format changed 

4. Create a physical volume group :

#  Create a physical volume  pvcreate /dev/sdc1
[root@localhost /]# pvcreate /dev/sdc1
    Physical volume "/dev/sdc1" successfully created.
    
#  The physical volume is added to the knife  centos  This  vg  in 
[root@localhost /]# vgextend centos  /dev/sdc1
  Volume group "centos" successfully extended

5. Check PE Number

 vgdisplay 
 
 [root@localhost /]# vgdisplay 
	--- Volume group ---
	VG Name               centos
	System ID             
	Format                lvm2
	Metadata Areas        3
	Metadata Sequence No  5
	VG Access             read/write
	VG Status             resizable
	MAX LV                0
	Cur LV                1
	Open LV               1
	Max PV                0
	Cur PV                3
	Act PV                3
	VG Size               69.79 GiB
	PE Size               4.00 MiB
	Total PE              17867
	Alloc PE / Size       10188 / <39.80 GiB
	Free  PE / Size       7679 / <30.00 GiB         ### This is the surplus PE Number , 7679, It's also new 30G disk ,7679 individual PE
	VG UUID               lkJhAi-7Df5-0K69-LYV4-exS2-ZqE1-FYMyIG

6. Expansion disk :

 # First look at the current disk situation :
 [root@localhost /]# df -h
 Filesystem               Size  Used Avail Use% Mounted on
 /dev/mapper/centos-root   40G  9.6G   31G  24% /          ## 31G.
 devtmpfs                 982M     0  982M   0% /dev
 tmpfs                    993M     0  993M   0% /dev/shm
 tmpfs                    993M  8.7M  984M   1% /run
 tmpfs                    993M     0  993M   0% /sys/fs/cgroup
 /dev/sda1                197M  103M   95M  53% /boot
 tmpfs                    199M     0  199M   0% /run/user/0


#  Expand and format the disk :
lvresize -r -l +7679  /dev/centos/root
 
# result : 
[root@localhost /]# lvresize -r -l +7679  /dev/centos/root
      Size of logical volume centos/root changed from <39.80 GiB (10188 extents) to 69.79 GiB (17867 extents).
      Logical volume centos/root successfully resized.
  meta-data=/dev/mapper/centos-root isize=512    agcount=9, agsize=1297664 blks
           =                       sectsz=512   attr=2, projid32bit=1
           =                       crc=1        finobt=0 spinodes=0
  data     =                       bsize=4096   blocks=10432512, imaxpct=25
           =                       sunit=0      swidth=0 blks
  naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
  log      =internal               bsize=4096   blocks=2560, version=2
           =                       sectsz=512   sunit=0 blks, lazy-count=1
  realtime =none                   extsz=4096   blocks=0, rtextents=0
  data blocks changed from 10432512 to 18295808
  
 # It's going to be all PE It's all divided into  /dev/centos/root ,  among  -r  Is to format this new disk while partitioning , To join the   In this partition .
 # That is to say, first format and then expand to /dev/centos/root  disk  . 
 # This method is based on PE A number to divide the disk ,  The total disk size is     Total disk size  = PE Number  * PE size

7. Check the existing condition of the disk :

#  View the existing disk size :
  [root@localhost /]# df -h
  Filesystem               Size  Used Avail Use% Mounted on
  /dev/mapper/centos-root   70G  9.6G   61G  14% /        ##----- Expansion successful , Disk from  32% Down to 14 , The size has become  61G
  devtmpfs                 982M     0  982M   0% /dev
  tmpfs                    993M     0  993M   0% /dev/shm
  tmpfs                    993M  8.7M  984M   1% /run
  tmpfs                    993M     0  993M   0% /sys/fs/cgroup
  /dev/sda1                197M  103M   95M  53% /boot
  tmpfs                    199M     0  199M   0% /run/user/0
  
  ## 31G+ Expansion to  30G Is the total  61G  It's all right .

Check the disk UUID:

[root@localhost ~]# blkid 
/dev/sda1: UUID="cb322c86-f37a-49e8-86a0-924d9b0c719e" TYPE="xfs" 
/dev/sda2: UUID="4YLVja-jT6q-FphK-3E60-5Qde-Z3gw-zLpcYT" TYPE="LVM2_member" 
/dev/sdb1: UUID="SBfuCJ-tli0-Mi2U-wO3w-eQub-0v36-0XkQBw" TYPE="LVM2_member" 
/dev/sdc1: UUID="Z7K8RO-denr-cyn8-sCjb-9HMa-Pu3I-ciK3kt" TYPE="LVM2_member" 
/dev/sr0: UUID="2017-09-06-10-51-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos-root: UUID="e3508edd-30c0-4e7d-9d8f-622c8dbd174e" TYPE="xfs"

Expansion completed .

PDF file :

lvm01.pdf