VMware虚拟机centos7.5扩容lvm卷的home目录

首先查看是否还有未分配的磁盘空间,有则直接热扩容就行。没有的话参照下面:

首先在虚拟机的编辑里面添加一块新的硬盘,选择thin,模式。

然后重启centos

小于2T的扩容使用fdisk就行

fdisk -l
查看新加进去的磁盘
给磁盘分区
[root@localhost ~]# fdisk /dev/sdb 
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 0x95f32263.

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, default 1): 
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L     

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
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.
Syncing disks.


 

mkfs.xfs /dev/sda3 进行格式化


指令:mkfs.xfs /dev/sda3

使用 lvm扩充分区

指令:  lvm

       pvcreate /dev/sda3

使用pvdisplay查看当前卷信息,发现/dev/sda2的VG Name是VolGroup,因此需要将/dev/sda3加入到VolGroup卷里面去。

指令: pvdisplay

将/dev/sda3加入到VolGroup卷里面去

指令: vgextend VolGroup /dev/sda3

      lvextend -L +39.9G /dev/mapper/VolGroup-lv_home

 

最后要调整逻辑分区大小,才能看到新的空间

指令: resize2fs /dev/mapper/VolGroup-lv_home

 我是xfs的。。所以用xfs_growfs /dev/mapper/centos-home

注意这块可能有如下报错:

[root@backup binlog]# resize2fs /dev/mapper/centos-home
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block 当尝试打开 /dev/mapper/centos-home 时
找不到有效的文件系统超级块.

确认文件系统是xfs:
[root@backup binlog]# cat /etc/fstab | grep centos-home
/dev/mapper/centos-home /home                   xfs     defaults        0 0

xfs用以下命令来扩磁盘空间:
[root@backup binlog]# xfs_growfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=256    agcount=6, agsize=118277632 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=709040128, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=231011, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 709040128 to 715331584

11.      最后用df –lh查看空间已经变更了。ok!

 
原文地址:https://www.cnblogs.com/xiongyoutom/p/14851531.html