1.先在Vmware上,把虚拟机硬盘做扩展,如果有快照存在,磁盘可能是不可编辑状态,先删除快照后再扩展。

2.现在打开虚拟机发现系统的磁盘空间已经扩了,但是硬盘分区可用空间没变,还是原来的30G

[root@localhost ~]# fdisk -l

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3916    31350847+  8e  Linux LVM

3.使用 fdisk 新建分区,为lvm扩容做准备

[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 6527.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3916    31350847+  8e  Linux LVM

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (3917-6527, default 3917): 
Using default value 3917
Last cylinder or +size or +sizeM or +sizeK (3917-6527, default 6527): 
Using default value 6527

Command (m for help): p

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3916    31350847+  8e  Linux LVM
/dev/sda3            3917        6527    20972857+  83  Linux

调整磁盘分区/dev/sda3为LVM格式,防止重装系统是不能识别(感觉不调整格式也能用)


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

Command (m for help): p

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3916    31350847+  8e  Linux LVM
/dev/sda3            3917        6527    20972857+  8e  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.
Syncing disks.
[root@localhost ~]# reboot

Broadcast message from root (pts/1) (Wed Mar  9 11:00:43 2016):

The system is going down for reboot NOW!

如果Re-reading the partition table 失败,可能分区还未识别,重启下再看。

4.建立 pv

[root@localhost ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@localhost ~]# pvdisplay 
  /dev/cdrom: open failed: No medium found
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               29.90 GB / not usable 24.06 MB
  Allocatable           yes 
  PE Size (KByte)       32768
  Total PE              956
  Free PE               2
  Allocated PE          954
  PV UUID               o9H0fA-136u-HmOM-Ga3O-7R0i-VRAS-F1mNxZ
   
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               20.00 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Qib59l-uCF5-5fo0-6oqH-5Url-yuSA-Y6N0E0

5.扩展 vg

[root@localhost ~]# vgextend VolGroup00 /dev/sda3
  Volume group "VolGroup00" successfully extended
[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               49.88 GB
  PE Size               32.00 MB
  Total PE              1596
  Alloc PE / Size       954 / 29.81 GB
  Free  PE / Size       642 / 20.06 GB
  VG UUID               8D7xnq-UPBK-LW2U-OCmc-Dl23-cpP1-qLLSHn

6.扩展lv

输入扩展单元,这里就是上面的Free PE 的大小。

[root@localhost ~]# lvextend -l +642 /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 47.94 GB
  Logical volume LogVol00 successfully resized
[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                QDtSfz-1SlB-xl3P-mRZp-H3dx-erAx-mAwrt2
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                47.94 GB
  Current LE             1534
  Segments               3
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                6nv9PJ-ho10-LPkA-0GBg-TBZt-z1Tf-F6S2Hu
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:1

 

7.调整文件系统

[root@localhost ~]# resize2fs  /dev/mapper/VolGroup00-LogVol00
resize2fs 1.35 (28-Feb-2004)
/dev/mapper/VolGroup00-LogVol00 is mounted; can't resize a mounted filesystem!

不能调整,使用 ext2online,我这边文件系统估计有点不对,所有会有些inode调整,忽略。

[root@localhost ~]# ext2online -v /dev/mapper/VolGroup00-LogVol00
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
new filesystem size 12550144
group 2 inode table has offset 2, not 1029
group 4 inode table has offset 2, not 1029
...
using 1024 reserved group descriptor blocks
creating group 382 with 32768 blocks (rsvd = 1023, newgd =  3)

cache direct hits: 160, indirect hits: 1, misses: 4

 

注意,对于新的CentOS系统,可能是使用 xfs 格式的分区,需要用别的命令调整

[root@vt-c7 ~]# resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

检查是xfs格式并使用 xfs_growfs 命令来扩展

[root@vt-c7 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Apr 29 21:12:56 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/centos-root /                       xfs     defaults        0 0
UUID=7c27bad9-295a-4323-afc8-b1f721ba5a5d /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
[root@vt-c7 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=436992 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1747968, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 1747968 to 3854336
[root@vt-c7 ~]#

 

8.打完收工

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       48G   27G   19G  59% /
/dev/sda1              99M   13M   81M  14% /boot
none                  772M     0  772M   0% /dev/shm

 

posted on 2016-03-09 11:09  tigertall  阅读(5130)  评论(0编辑  收藏  举报