虚拟机增加磁盘空间

1、更改虚拟机磁盘到30G到40G

2、

[root@localhost ~]# fdisk -l


Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0007e02e


   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        2611    20458496   8e  Linux LVM
/dev/sda3            2611        3916    10483750   8e  Linux LVM


Disk /dev/mapper/VolGroup-lv_root: 29.5 GB, 29498540032 bytes
255 heads, 63 sectors/track, 3586 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: 0x00000000




Disk /dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 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: 0x00000000


[root@localhost ~]# df -hT
Filesystem                   Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4    27G  4.2G   22G  17% /
tmpfs                        tmpfs  242M     0  242M   0% /dev/shm
/dev/sda1                    ext4   477M   49M  403M  11% /boot

3、格式化磁盘

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


WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').


Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (3917-5221, default 3917): 
Using default value 3917
Last cylinder, +cylinders or +size{K,M,G} (3917-5221, default 5221): 
Using default value 5221


Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 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.


4、重启系统

5、创建PV(物理卷)

# pvcreate /dev/sda4
  dev_is_mpath: failed to get device for 8:4
  Physical volume "/dev/sda4" successfully created

[root@localhost ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               esAhOX-P7To-Ln3d-vcfL-QPiH-easj-fLzs8m
   
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               VolGroup
  PV Size               10.00 GiB / not usable 2.04 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               24
  Allocated PE          2535
  PV UUID               V4Akix-450a-LAi2-37lA-0cfC-HXiT-PQzcfd
   
  "/dev/sda4" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda4
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               aYBMc5-8Zjm-rend-Q7b2-682Q-KpWq-r0DPjW


6、将PV添加到VG(卷组)

[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               VolGroup
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  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               29.50 GiB
  PE Size               4.00 MiB
  Total PE              7553
  Alloc PE / Size       7529 / 29.41 GiB
  Free  PE / Size       24 / 96.00 MiB
  VG UUID               o5nqr9-x3CZ-tkHt-CXMx-Nr4m-Hy4A-gkjEiu

7、添加到卷组

[root@localhost ~]# vgextend VolGroup /dev/sda4

[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               VolGroup
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               39.50 GiB
  PE Size               4.00 MiB
  Total PE              10111
  Alloc PE / Size       7529 / 29.41 GiB
  Free  PE / Size       2582 / 10.09 GiB
  VG UUID               o5nqr9-x3CZ-tkHt-CXMx-Nr4m-Hy4A-gkjEiu

8、扩展LV(逻辑卷)

[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                HbrFzr-ooNo-oqIv-WKah-HYui-svZ5-cL3wmw
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-10-27 16:01:35 +0800
  LV Status              available
  # open                 1
  LV Size                27.47 GiB
  Current LE             7033
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_swap
  LV Name                lv_swap
  VG Name                VolGroup
  LV UUID                1t05pO-HJ2E-OpyX-Ni0s-QB2f-R7zx-V4cFOF
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-10-27 16:01:38 +0800
  LV Status              available
  # open                 1
  LV Size                1.94 GiB
  Current LE             496
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1


  [root@localhost ~]# lvextend -L+10G /dev/VolGroup/lv_root 
  Extending logical volume lv_root to 37.47 GiB
  Logical volume lv_root successfully resized

[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                HbrFzr-ooNo-oqIv-WKah-HYui-svZ5-cL3wmw
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-10-27 16:01:35 +0800
  LV Status              available
  # open                 1
  LV Size                37.47 GiB
  Current LE             9593
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_swap
  LV Name                lv_swap
  VG Name                VolGroup
  LV UUID                1t05pO-HJ2E-OpyX-Ni0s-QB2f-R7zx-V4cFOF
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-10-27 16:01:38 +0800
  LV Status              available
  # open                 1
  LV Size                1.94 GiB
  Current LE             496
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   

[root@localhost ~]# df -hT
Filesystem                   Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4    27G  4.2G   22G  17% /
tmpfs                        tmpfs  242M     0  242M   0% /dev/shm
/dev/sda1                    ext4   477M   49M  403M  11% /boot

上面看到逻辑卷已经增加,系统未增加

使用resize2fs命令将文件系统扩展到增加的空间上:

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

[root@localhost ~]# df -hT
Filesystem                   Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4    37G  4.2G   31G  12% /
tmpfs                        tmpfs  242M     0  242M   0% /dev/shm
/dev/sda1                    ext4   477M   49M  403M  11% /boot


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值