重作LVM文件系統之減少PV

命令

縮小PV空間到120G,即PV上的vg00已將縮小到120G
    pvresize --setphysicalvolumesize 120g /dev/sda2

背景

機器上有一塊900G本地的本地磁盤,安裝系統時將900G的空間所有擴到了一個VG卷組中,即vg00,並建立了多個LV邏輯卷,LV邏輯卷佔用了vg00卷組120G的空間,即卷組vg00還剩770G左右的空閒空間;此種文件系統格式不符合應用的規範標準,標準的文件系統規範爲建立一個120G的卷組Vg00,使用Vg00卷組建立系統必要的LV邏輯卷,而剩下的770G空間新建卷組Vg01。爲了知足應用需求,現將900G盤上的vg00空間縮小爲120G,而後新建vg01使用剩下的770G空間。在不影響系統正常的狀況下實現PV/VG的縮小。因爲LV佔用了120G的VG,即將VG空間縮小到120G方可最大化利用vg00卷組,爲了達到縮小Vg00的需求,經過縮小PV來強制縮小Vg空間。

操做流程

現有文件系統linux

[root@sishb00302 ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree  
  vg00   1   6   0 wz--n- 837.84g 721.84g
[root@sishb00302 ~]# lvs
  LV       VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  crashvol vg00 -wi-ao---- 32.00g                                                    
  homevol  vg00 -wi-ao----  2.00g                                                    
  rootvol  vg00 -wi-ao---- 20.00g                                                    
  swapvol  vg00 -wi-ao---- 32.00g                                                    
  tmpvol   vg00 -wi-ao---- 10.00g                                                    
  varvol   vg00 -wi-ao---- 20.00g 

[root@sishb00302 ~]# fdisk /dev/sda 
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.


Command (m for help): p

Disk /dev/sda: 900.2 GB, 900151926784 bytes, 1758109232 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disk label type: dos
Disk identifier: 0x000cd03d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048  1758107647   878540800   8e  Linux LVM

減少PVapp

[root@sishb00302 ~]# pvresize --setphysicalvolumesize 120g /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
[root@sishb00302 ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg00   1   6   0 wz--n- 120.00g 4.00g
[root@sishb00302 ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda2  vg00 lvm2 a--  120.00g 4.00g

刪除原有的900G的/dev/sda2分區,新建/dev/sda2分區爲120G,剩餘空間爲/dev/sda3分區ide

[root@sishb00302 ~]# fdisk /dev/sda
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.


Command (m for help): p

Disk /dev/sda: 900.2 GB, 900151926784 bytes, 1758109232 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disk label type: dos
Disk identifier: 0x000cd03d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048  1758107647   878540800   8e  Linux LVM

Command (m for help): d
Partition number (1,2, default 2): 
Partition 2 is deleted

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): 
Using default response p
Partition number (2-4, default 2): 
First sector (1026048-1758109231, default 1026048): 
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-1758109231, default 1758109231): +120G
Partition 2 of type Linux and of size 120 GiB is set

Command (m for help): t
Partition number (1,2, default 2): 
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): 
Using default response p
Partition number (3,4, default 3): 
First sector (252684288-1758109231, default 252684288): 
Using default value 252684288
Last sector, +sectors or +size{K,M,G} (252684288-1758109231, default 1758109231): 
Using default value 1758109231
Partition 3 of type Linux and of size 717.9 GiB is set

Command (m for help): t
Partition number (1-3, default 3): 
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

移除/dev/vg00/crashvol文件系統ui

[root@sishb00302 ~]# umount /var/crash/
[root@sishb00302 ~]# lvremove /dev/vg00/crashvol
Do you really want to remove active logical volume vg00/crashvol? [y/n]: y
  Logical volume "crashvol" successfully removed
[root@sishb00302 ~]# lvs
  LV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  homevol vg00 -wi-ao----  2.00g                                                    
  rootvol vg00 -wi-ao---- 20.00g                                                    
  swapvol vg00 -wi-ao---- 32.00g                                                    
  tmpvol  vg00 -wi-ao---- 10.00g                                                    
  varvol  vg00 -wi-ao---- 20.00g                                                    
[root@sishb00302 ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree 
  vg00   1   5   0 wz--n- 120.00g 36.00g

/dev/vg00/varvol邏輯卷在線擴容3d

[root@sishb00302 ~]# lvextend -L +30g /dev/vg00/varvol -r
  Size of logical volume vg00/varvol changed from 20.00 GiB (5120 extents) to 50.00 GiB (12800 extents).
  Logical volume vg00/varvol successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg00-varvol is mounted on /var; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 7
The filesystem on /dev/mapper/vg00-varvol is now 13107200 blocks long.

[root@sishb00302 ~]# lvs
  LV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  homevol vg00 -wi-ao----  2.00g                                                    
  rootvol vg00 -wi-ao---- 20.00g                                                    
  swapvol vg00 -wi-ao---- 32.00g                                                    
  tmpvol  vg00 -wi-ao---- 10.00g                                                    
  varvol  vg00 -wi-ao---- 50.00g

修改fatab文件code

修改前
[root@sishb00302 ~]# cat /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Tue Mar  6 11:44:46 2018
#
# 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/vg00-rootvol /                       ext4    defaults        1 1
UUID=c04bb69b-1380-4c31-b4f4-9bfacb5d9063 /boot                   ext4    defaults        1 2
/dev/mapper/vg00-homevol /home                   ext4    defaults        1 2
/dev/mapper/vg00-tmpvol /tmp                    ext4    defaults        1 2
/dev/mapper/vg00-varvol /var                    ext4    defaults        1 2
/dev/mapper/vg00-crashvol /var/crash              ext4    defaults        1 2
/dev/mapper/vg00-swapvol swap                    swap    defaults        0 0

 修改後
[root@sishb00302 ~]# cat /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Tue Mar  6 11:44:46 2018
#
# 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/vg00-rootvol /                       ext4    defaults        1 1
UUID=c04bb69b-1380-4c31-b4f4-9bfacb5d9063 /boot                   ext4    defaults        1 2
/dev/mapper/vg00-homevol /home                   ext4    defaults        1 2
/dev/mapper/vg00-tmpvol /tmp                    ext4    defaults        1 2
/dev/mapper/vg00-varvol /var                    ext4    defaults        1 2
/dev/mapper/vg00-swapvol swap                    swap    defaults        0 0

關機重啓系統,從而釋放/Idev/sda3分區的空間ci

空間釋放後,再次建立vg01卷組rem

[root@sishb00302 ~]# lvs
  LV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  homevol vg00 -wi-ao----  2.00g                                                    
  rootvol vg00 -wi-ao---- 20.00g                                                    
  swapvol vg00 -wi-ao---- 32.00g                                                    
  tmpvol  vg00 -wi-ao---- 10.00g                                                    
  varvol  vg00 -wi-ao---- 50.00g                                                    

[root@sishb00302 ~]# vgcreate /dev/vg01 /dev/sda3
  Physical volume "/dev/sda3" successfully created.
  Volume group "vg01" successfully created
[root@sishb00302 ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree  
  vg00   1   5   0 wz--n- 120.00g   6.00g
  vg01   1   0   0 wz--n- 717.84g 717.84g

[root@sishb00302 ~]# lvs
  LV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  homevol vg00 -wi-ao----  2.00g                                                    
  rootvol vg00 -wi-ao---- 20.00g                                                    
  swapvol vg00 -wi-ao---- 32.00g                                                    
  tmpvol  vg00 -wi-ao---- 10.00g                                                    
  varvol  vg00 -wi-ao---- 50.00g

最終實現了vg00文件系統從900G減少到了120G,並新建了vg01卷組it

相關文章
相關標籤/搜索