LVM

在虚拟机vm上为centos新增了8G硬盘容量,(之前只有8G)编辑该虚拟机

 

###成功进入系统后,查看硬盘信息

 

###分区信息如下

我的目标是把新增的磁盘空间全部加入到/dev/mapper/VolGroup00--LogVol00

 

###先格式化硬盘

硬盘容量会增加到修改之后的大小,用fdisk来在新增的那部分磁盘空间建立新的分区,请根据自己的实际情况来执行这一步,操作有风险,模仿需谨慎!

fdisk /dev/sda

 

The number of cylinders for this disk is set to 2610.

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): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 3

First cylinder (1306-2610, default 1306): 

Using default value 1306

Last cylinder or +size or +sizeM or +sizeK (1306-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)

----以上是把该分区转化为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.

Syncing disks.

再查看分区情况:

 

 

可以看到,一个/dev/sda3分区已经建立

 

#####初始化物理卷

用pvcreate初始化/dev/sda3,以便被LVM使用:

pvcreate /dev/sda3

  Device /dev/sda3 not found (or ignored by filtering).

 

如果出现上面这种情况,重启CentOS下运行上面命令:

pvcreate /dev/sda3

  Physical volume "/dev/sda3" successfully created

 

###扩展原有卷组

初始化/dev/sda3之后,把它加入一个卷组里。

用下面命令来扫描已经存在的卷组:

vgscan 

  Reading all physical volumes.  This may take a while...

  Found volume group "VolGroup" using metadata type lvm2

扫描到一个名为"VolGroup"的卷组,这是要被扩展的卷组。

 

###扩展命令:

 

######卷组扩展成功,查看卷组信息:

注意上面"Alloc PE / Size""Free PE / Size",两者分别是已已分配PE/大小未分配PE/大小。可见新增的空间已经被加入卷组VolGroup00了。

 

#####扩展原有逻辑卷

现在把未分配空间加入到逻辑卷里去,扫描一下逻辑卷:

/dev/VolGroup/lv_root就是要扩展的逻辑卷,使用下面的命令来扩展

lvextend -L +9.97G /dev/VolGroup00/LogVol00

  Rounding up size to full physical extent 9.97 GB

  Extending logical volume LogVol00 to 19.34 GB

  Logical volume LogVol00 successfully resized

---上面是公司文档的做法,以下是自己的

 

df查看,发现并没有增加

 

###调整大小

用resize2fs来在线调整文件系统的大小:

 

最后查看大小,如下:

 

 

你可能感兴趣的:(lvm)