ESXI 5.0 linux虛擬機LVM磁盤擴容

 一、增加分區:
1、VC登錄控制檯修改虛擬機磁盤大小。
2、現在系統中還看不到加入的容量,reboot,對新增加的磁盤創建分區
fdisk /dev/sda
#用n命令建個P類型的磁盤,然後用t命令更改ID爲8e(LVM類別)。

Command (m for help): n

Command action

     e     extended

     p     primary partition (1-4)

p

Partition number (1-4): 3

First cylinder (5222-6527, default 5222):

Using default value 5222

Last cylinder, +cylinders or +size{K,M,G} (5222-6527, default 6527):

Using default value 6527



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)

#    p


Command (m for help): p



Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000ef931



     Device Boot            Start                 End            Blocks     Id    System

/dev/sda1     *                     1                    64            512000     83    Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2                            64                5222        41430016     8e    Linux LVM

/dev/sda3                        5222                6527        10485087+    8e    Linux LVM
最後W保存
ps:這裏要重啓一下服務器,不然掛載不上新建的sda3
#不用reboot的做法
我的系統是centos6.2,partprobe無效,要用partx命令重新讀取分區。
新增分區時:partx -a /dev/sda
刪除分區時:partx -d --nr N /dev/sda
二.LVM擴容:
1.先格式化/dev/sda3
[root@nginx ~]# mkfs.ext4 /dev/sda3

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

655360 inodes, 2621271 blocks

131063 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2684354560

80 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632



Writing inode tables: done                                                        

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done



This filesystem will be automatically checked every 38 mounts or

180 days, whichever comes first.    Use tune2fs -c or -i to override.
2.創建pv
[root@nginx ~]# pvcreate /dev/sda3

    Writing physical volume data to disk "/dev/sda3"

    Physical volume "/dev/sda3" successfully created

#查看已創建的pv

[root@nginx ~]# pvdisplay

    --- Physical volume ---

    PV Name                             /dev/sda2

    VG Name                             vg_nginx

    PV Size                             39.51 GiB / not usable 3.00 MiB

    Allocatable                     yes (but full)

    PE Size                             4.00 MiB

    Total PE                            10114

    Free PE                             0

    Allocated PE                    10114

    PV UUID                             Z7S451-CiWS-l66s-6hiU-j5YY-35Wq-KcijFH

    

    --- Physical volume ---

    PV Name                             /dev/sda3

    VG Name                             vg_nginx

    PV Size                             10.00 GiB / not usable 3.34 MiB

    Allocatable                     yes (but full)

    PE Size                             4.00 MiB

    Total PE                            2559

    Free PE                             0

    Allocated PE                    2559

    PV UUID                             aQivcj-noPv-Mpy8-Dlmw-1fBT-DqhL-W1eyOe

#查看vg

[root@nginx ~]# vgdisplay

    --- Volume group ---

    VG Name                             vg_nginx

    System ID                        

    Format                                lvm2

    Metadata Areas                1

    Metadata Sequence No    3

    VG Access                         read/write

    VG Status                         resizable

    MAX LV                                0

    Cur LV                                2

    Open LV                             2

    Max PV                                0

    Cur PV                                1

    Act PV                                1

    VG Size                             39.51 GiB

    PE Size                             4.00 MiB

    Total PE                            10114

    Alloc PE / Size             10114 / 39.51 GiB

    Free    PE / Size             0 / 0    

    VG UUID                             Yah1Wu-pdas-Lag1-ygDT-x9ck-XkZf-4EbwHb
3.將剛創建的pv加入到相應的vg
[root@nginx ~]# vgextend vg_nginx /dev/sda3

    Volume group "vg_nginx" successfully extended

#查看vg是否添加成功

[root@nginx ~]# vgdisplay

    --- Volume group ---

    VG Name                             vg_nginx

    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.50 GiB

    PE Size                             4.00 MiB

    Total PE                            12673

    Alloc PE / Size             10114 / 39.51 GiB

    Free    PE / Size             2559 / 10.00 GiB

    VG UUID                             Yah1Wu-pdas-Lag1-ygDT-x9ck-XkZf-4EbwHb

#查看lv狀態

[root@nginx ~]# lvdisplay

    --- Logical volume ---

    LV Name                                /dev/vg_nginx/lv_root

    VG Name                                vg_nginx

    LV UUID                                3EG5sY-NPMC-CKIy-MDWE-0ln7-GgtZ-TYNJWk

    LV Write Access                read/write

    LV Status                            available

    # open                                 1

    LV Size                                37.54 GiB

    Current LE                         9610

    Segments                             1

    Allocation                         inherit

    Read ahead sectors         auto

    - currently set to         256

    Block device                     253:0

    

    --- Logical volume ---

    LV Name                                /dev/vg_nginx/lv_swap

    VG Name                                vg_nginx

    LV UUID                                J50VXw-rWdY-ZBw7-lRnh-xB8s-NBdv-wGnr0B

    LV Write Access                read/write

    LV Status                            available

    # open                                 1

    LV Size                                1.97 GiB

    Current LE                         504

    Segments                             1

    Allocation                         inherit

    Read ahead sectors         auto

    - currently set to         256

    Block device                     253:1
4.爲/dev/vg_nginx/lv_root增加容量
[root@nginx ~]# lvextend -l +2559 /dev/vg_nginx/lv_root

    Extending logical volume lv_root to 47.54 GiB

    Logical volume lv_root successfully resized

#或者用lvextend -L +10G /dev/vg_nginx/lv_root

#查看已掛載分區的容量

[root@nginx ~]# df -hl

Filesystem                        Size    Used Avail Use% Mounted on

/dev/mapper/vg_nginx-lv_root

                                             37G    2.0G     34G     6% /

tmpfs                                 499M         0    499M     0% /dev/shm

/dev/sda1                         485M     51M    409M    12% /boot
5.看到了吧,這裏容量還沒增加需要執行resize2fs
[root@nginx ~]# resize2fs /dev/mapper/vg_nginx-lv_root

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/mapper/vg_nginx-lv_root is mounted on /; on-line resizing required

old desc_blocks = 3, new_desc_blocks = 3

Performing an on-line resize of /dev/mapper/vg_nginx-lv_root to 12461056 (4k) blocks.

The filesystem on /dev/mapper/vg_nginx-lv_root is now 12461056 blocks long.

#現在查看一下,ok
[root@nginx ~]# df -hl
Filesystem                        Size    Used Avail Use% Mounted on
/dev/mapper/vg_nginx-lv_root
                                             47G    2.0G     43G     5% /
tmpfs                                 499M         0    499M     0% /dev/shm
/dev/sda1                         485M     51M    409M    12% /boot









#查看一下lv的最終結果:
[root@nginx ~]# lvdisplay

    --- Logical volume ---

    LV Name                                /dev/vg_nginx/lv_root

    VG Name                                vg_nginx

    LV UUID                                3EG5sY-NPMC-CKIy-MDWE-0ln7-GgtZ-TYNJWk

    LV Write Access                read/write

    LV Status                            available

    # open                                 1

    LV Size                                47.54 GiB

    Current LE                         12169

    Segments                             2

    Allocation                         inherit

    Read ahead sectors         auto

    - currently set to         256

    Block device                     253:0

    

    --- Logical volume ---

    LV Name                                /dev/vg_nginx/lv_swap

    VG Name                                vg_nginx

    LV UUID                                J50VXw-rWdY-ZBw7-lRnh-xB8s-NBdv-wGnr0B

    LV Write Access                read/write

    LV Status                            available

    # open                                 1

    LV Size                                1.97 GiB

    Current LE                         504

    Segments                             1

    Allocation                         inherit

    Read ahead sectors         auto

    - currently set to         256

    Block device                     253:1




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