服务器之家

专注于服务器技术!
当前位置:首页 > 服务器系统 > Linux

Linux VMware虚拟机系统扩容LVM硬盘

发布时间:2014-03-06 来源:服务器之家

为虚拟机下linux6.3的根目录扩容,根目录使用了linxu LVM。

目前的大小,状态:

[root@node1 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_oel63-lv_root
     13G  6.5G  5.4G  55% /
下面的过程是增加1个linux LVM的分区,并分成成1个PV,再添加到现有的VG中,最后扩容到LV 中。 1.创建磁盘类型为 Linux LVM(8e)的分区:

Command (m for help): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000cd5a1

   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        1959    15215616   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 (1959-2610, default 1959): 
Using default value 1959
Last cylinder, +cylinders or +size{K,M,G} (1959-2610, default 2610): 
Using default value 2610

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: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000cd5a1

   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        1959    15215616   8e  Linux LVM
/dev/sda3            1959        2610     5236185   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 or after you run partprobe(8) or kpartx(8)
Syncing disks.

2.增加PV:

[root@node2 ~]# pvcreate /dev/sda3
查看PV
[root@node1 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_oel63
  PV Size               14.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3714
  Free PE               0
  Allocated PE          3714
  PV UUID               qE4s6S-TMVh-xcEx-5p7i-d217-gWxO-g73RMb
  "/dev/sda3" is a new physical volume of "4.99 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               PV Size               4.99 GiB
  Allocatable           NO
  PE Size               0   Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               nfi7TH-7nbI-UxL4-SJT2-snrk-fRAQ-KcCAI2

3.扩容VG
查看已经有的VG
[root@node1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_oel63
  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               14.51 GiB
  PE Size               4.00 MiB
  Total PE              3714
  Alloc PE / Size       3714 / 14.51 GiB
  Free  PE / Size       0 / 0   VG UUID               CwNr30-smZm-kc85-3CJP-p4Vi-6h3w-X85P9W

进行扩展:
[root@node1 ~]# vgextend vg_oel63 /dev/sda3
  Volume group "vg_oel63" successfully extended
再次查看
[root@node1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_oel63
  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               19.50 GiB
  PE Size               4.00 MiB
  Total PE              4992
  Alloc PE / Size       3714 / 14.51 GiB
  Free  PE / Size       1278 / 4.99 GiB
  VG UUID               CwNr30-smZm-kc85-3CJP-p4Vi-6h3w-X85P9W

4.扩容LV

[root@node1 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_oel63/lv_root
  LV Name                lv_root
  VG Name                vg_oel63
  LV UUID                tsxrdP-KKJc-kD1m-EVl3-VZX0-qprk-1mRHhs
  LV Write Access        read/write
  LV Creation host, time OEL63, 2013-08-20 00:50:06 +0800
  LV Status              available
  # open                 1
  LV Size                12.57 GiB
  Current LE             3218
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
  --- Logical volume ---
  LV Path                /dev/vg_oel63/lv_swap
  LV Name                lv_swap
  VG Name                vg_oel63
  LV UUID                9hSLAQ-PCxn-hz9K-HdXZ-updx-CyjW-tXTcN1
  LV Write Access        read/write
  LV Creation host, time OEL63, 2013-08-20 00:50:09 +0800
  LV Status              available
  # open                 2
  LV Size                1.94 GiB
  Current LE             496
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

扩展lv_root的大小:

[root@node1 ~]# lvextend /dev/vg_oel63/lv_root /dev/sda3
  Extending logical volume lv_root to 17.56 GiB
  Logical volume lv_root successfully resized

[root@node1 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_oel63/lv_root
  LV Name                lv_root
  VG Name                vg_oel63
  LV UUID                tsxrdP-KKJc-kD1m-EVl3-VZX0-qprk-1mRHhs
  LV Write Access        read/write
  LV Creation host, time OEL63, 2013-08-20 00:50:06 +0800
  LV Status              available
  # open                 1
  LV Size                17.56 GiB
  Current LE             4496
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
  --- Logical volume ---
  LV Path                /dev/vg_oel63/lv_swap
  LV Name                lv_swap
  VG Name                vg_oel63
  LV UUID                9hSLAQ-PCxn-hz9K-HdXZ-updx-CyjW-tXTcN1
  LV Write Access        read/write
  LV Creation host, time OEL63, 2013-08-20 00:50:09 +0800
  LV Status              available
  # open                 2
  LV Size                1.94 GiB
  Current LE             496
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256

  Block device           252:1

5.执行重设命令

[root@node1 ~]# resize2fs /dev/mapper/vg_oel63-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_oel63-lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/mapper/vg_oel63-lv_root to 4603904 (4k) blocks.
The filesystem on /dev/mapper/vg_oel63-lv_root is now 4603904 blocks long.

最后结果:
[root@node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_oel63-lv_root
     18G  6.5G   10G  40% /