虛擬機LVM擴容

1.先在Vmware上,把虛擬機硬盤作擴展,若是有快照存在,磁盤多是不可編輯狀態,先刪除快照後再擴展。node

2.如今打開虛擬機發現系統的磁盤空間已經擴了,可是硬盤分區可用空間沒變,仍是原來的30Gcentos

[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擴容作準備app

[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格式,防止重裝系統是不能識別(感受不調整格式也能用)this


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 失敗,可能分區還未識別,重啓下再看。spa

4.創建 pv3d

[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.擴展 vgcode

[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.擴展lvorm

輸入擴展單元,這裏就是上面的Free PE 的大小。blog

[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.調整文件系統ip

[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
相關文章
相關標籤/搜索