虛擬機LVM擴容

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

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

複製代碼

[root@localhost ~]# fdisk -l

Disk /dev/sda: 53.6 GB, 53687091200 bytes255 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 bytes255 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): 3First cylinder (3917-6527, default 3917): 
Using default value 3917Last cylinder or +size or +sizeM or +sizeK (3917-6527, default 6527): 
Using default value 6527Command (m for help): p

Disk /dev/sda: 53.6 GB, 53687091200 bytes255 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): 3Hex 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 bytes255 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): wThe 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 ~]# xfs_growfs /dev/VolGroup00/LogVol00
meta-data=/dev/mapper/VolGroup00-LogVol00 isize=256    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 21232640

完成更改

複製代碼

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

轉載至:http://www.cnblogs.com/tigertall/p/5257324.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章