lvm空间扩展_虚拟机

在安装虚拟机中,默认硬盘20G,安装完操作系统后发现根目录不够使用,然后添加硬盘40,扩展根目录空间。
[root@localhost ~] df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol01   18G  3.5G   13G  21% /
tmpfs                          491M   72K  491M   1% /dev/shm
/dev/sda1                      485M   35M  426M   8% /boot

添加硬盘

  1. 关闭虚拟机,添加 40G 硬盘
    在这里插入图片描述
  2. 开启虚拟机,查看添加硬盘:
[root@localhost ~] fdisk -l /dev/sdb

Disk /dev/sdb: 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: 0x00000000
  1. 对新硬盘创建分区,指定分区大小
[root@localhost ~] fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xee9b440c.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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
Partition number (1-4): 1
First cylinder (1-5221, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): 
Using default value 5221

Command (m for help): w
[root@localhost ~] fdisk -l /dev/sdb

Disk /dev/sdb: 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: 0xee9b440c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        5221    41937651   83  Linux

  1. 更改硬盘 ID ,默认为83,lvm为 8e 并重启操作系统:
[root@localhost ~] fdisk /dev/sdb

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): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 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: 0xee9b440c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        5221    41937651   8e  Linux LVM

Command (m for help): w
[root@localhost ~] reboot
  1. 扩充新分区
pvcreate /dev/sdb1   //pvcreate指令用于将物理硬盘分区初始化为物理卷,以便被LVM使用。要创建物理卷必须首先对硬盘进行分区,并且将硬盘分区的类型设置为“8e”后,才能使用pvcreat  指令将分区初始化为物理卷。
[root@localhost ~] pvcreate /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created
vgextend VolGroup /dev/sdb1   //(其中是当前需要扩充的lvm组名,可以通过df -h查看,例如我的是: /dev/mapper/VolGroup00-LogVol00) vgextend指令用于动态的扩展卷组,      它通过向卷组中添加物理卷来增加卷组的容量。
[root@localhost ~] vgextend VolGroup /dev/sdb1
  Volume group "VolGroup" successfully extended
vgdisplay //用于显示LNM卷组的元数据信息。
[root@localhost ~] vgdisplay 
  --- Volume group ---
  VG Name               VolGroup
  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               59.50 GiB
  PE Size               4.00 MiB
  Total PE              15232
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       10238 / 39.99 GiB
  VG UUID               PNgbYA-sj6B-apNB-zOku-ax56-031V-RQKitY
lvextend -L +39.99G /dev/mapper/VolGroup-LogVol01 /dev/sdb1 //想指定lvm卷组扩展空间
[root@localhost ~] lvextend -L +39.99G /dev/mapper/VolGroup-LogVol01 /dev/sdb1 
  Rounding size to boundary between physical extents: 39.99 GiB
  Extending logical volume LogVol01 to 57.50 GiB
  Logical volume LogVol01 successfully resized
resize2fs /dev/mapper/VolGroup-LogVol01     //resize2fs指令被用来增大或者收缩未加载的“ext2/ext3”文件系统的大小。
[root@localhost ~] resize2fs /dev/mapper/VolGroup-LogVol01 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-LogVol01 is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/VolGroup-LogVol01 to 15073280 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-LogVol01 is now 15073280 blocks long.
  1. 完成后查看磁盘空间:
[root@localhost ~] df -h
Filesystem                     	Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol01  	 57G  3.5G   51G   7% /
tmpfs                          	491M   72K  491M   1% /dev/shm
/dev/sda1                      	485M   35M  426M   8% /boot
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值