一.背景:因为公司虚拟机 (/) 目录容量过小,导致一些任务不能正常执行,需要给虚拟机扩容

二.操作:

 初始磁盘情况:  

 1.使用 df 命令查看磁盘与目录的容量:

[root@shaonian ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 48G 22G 25G % /
tmpfs .8G .8G % /dev/shm
/dev/xvda1 485M 33M 427M % /boot
/dev/mapper/VolGroup-lv_home .7G 138M .4G % /home
cm_processes .8G 808K .8G % /var/run/cloudera-scm-agent/process

 2.使用 fdisk -l 命令查看磁盘分区:

[root@shaonian ~]# fdisk -l

Disk /dev/xvdb: 85.9 GB,  bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 Disk /dev/xvda: 64.4 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x000e9377 Device Boot Start End Blocks Id System
/dev/xvda1 * Linux
Partition does not end on cylinder boundary.
/dev/xvda2 8e Linux LVM Disk /dev/xvdd: MB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_root: 52.3 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_swap: MB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_home: MB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000

发现执行 fdisk -l 显示的第一行,显示出的 /dev/xvdb 分区,并没有被使用。这就是是管理人员分出给磁盘扩容用的磁盘空间,我们接下来要用这个分区为(/)目录扩容

3.接着执行 fdisk /dev/xvdb ,进入 fdisk 命令行给磁盘分区

[root@shaonian ~]# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd259beb1.
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 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): p Disk /dev/xvdb: 85.9 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xd259beb1 Device Boot Start End Blocks Id System Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ):
Using default value Command (m for help): t
Selected partition
Hex code (type L to list codes): 8e
Changed system type of partition to 8e (Linux LVM) Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

可以看出,输入fdisk /dev/xvdb  命令后,提示我们输入命令,我们依次输入以下命令:

p 查看已有分区,由于这个分区是新的,所以为空

n 新建分区:

  p 新建主分区

1 输入分区号,因为之前没有分区,所以这是第一个分区,分区号为1

接下来 First cylinder 和 Last cylinder 我们直接点击回车,默认使用全部空间

t 改变分区类型

8e 改变分区类型为 LVM

w 写入改变

此时系统将改变分区,然后退出 fdisk 命令行。如果没有自动退出,输入 q 退出。

4. 用 mkfs 命令对分区进行格式化

mkfs -t ext3 /dev/xvdb1

此时将进入漫长的等待......

5.添加 LVM到原来的 LVM组

lvm  进入lvm管理

lvm> pvcreate /dev/xvdb1  创建虚拟分区

lvm> vgextend VolGroup  /dev/xvdb1  把刚刚创建的分区添加到虚拟分区组

lvm>lvextend -L +79.5 /dev/mapper/VolGroup-lv_root  扩展容量(可以看到 /dev/mapper/VolGroup-lv_root)就是我们执行 df -h 时 (/)目录的文件系统)

lvm> quit  退出

6. 文件系统扩容

resize2fs /dev/mapper/VolGroup-lv_root

至此,扩容全部完成,此时再次执行 df -h :

[root@shaonian ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 127G 22G 99G % /
tmpfs .8G .8G % /dev/shm
/dev/xvda1 485M 33M 427M % /boot
/dev/mapper/VolGroup-lv_home .7G 138M .4G % /home
cm_processes .8G 792K .8G % /var/run/cloudera-scm-agent/process

可以看到 (/)目录的容量大大增加了

PS:顺便一提,一共扩容了三台虚拟机,其中两台都是很顺利的,有一台不知道什么原因(可能是其中某一步操作错误),在执行

lvm> vgextend VolGroup /dev/mapper/Group-lv_root

操作时,出现了如下错误:

Couldn't find device with uuid cRdLUx-1ttO-JUKw-K2Bu-FOw2-EIrk-87Xdl3.

运行 pvscan 查看 pv:

lvm> pvscan
Couldn't find device with uuid cRdLUx-1ttO-JUKw-K2Bu-FOw2-EIrk-87Xdl3.
Couldn't find device with uuid 7Ef30A-6qRY-bBP0-CTH9-f6ut-kE8x-ch4c2j.
PV /dev/xvda2 VG VolGroup lvm2 [59.51 GiB / free]
PV unknown device VG VolGroup lvm2 [80.00 GiB / 80.00 GiB free]
PV unknown device VG VolGroup lvm2 [80.00 GiB / 80.00 GiB free]
PV /dev/xvdb4 VG VolGroup lvm2 [80.00 GiB / 80.00 GiB free]
Total: [299.50 GiB] / in use: [299.50 GiB] / in no VG: [ ]

发现 有两行 出现了 unknown device

执行

lvm> vgreduce --removemissing  VolGroup

即可。

最新文章

  1. [Web API] Web API 2 深入系列(6) Model绑定(上)
  2. CoreJava学习笔记1-基本概念、对象和类
  3. Guava学习笔记:Google Guava 类库简介
  4. 在Salesforce中处理Email的发送
  5. Unity协程(Coroutine)管理类——TaskManager工具分享
  6. jquery给元素添加样式表的方法
  7. 浅谈CSS样式png、gif、jpg图片优化的方法
  8. SecureCRT for Linux突破30天使用限制
  9. [转]LINQ操作数据库
  10. c#的异或运算符
  11. Android Studio 快捷键整理分享
  12. Android图表库MPAndroidChart(九)——神神秘秘的散点图
  13. 1.ActionBar
  14. chm开源文档制作
  15. 【转载】在MySQL登录时出现Access denied for user 'root'@'localhost' (using password: YES) 拒绝访问,并可修改MySQL密码
  16. VBScript进阶篇一
  17. 浅谈移动应用的跨平台开发工具(Xamarin和React Native)
  18. 【Web前端开发最佳实践系列】前端代码推荐和建议
  19. Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
  20. #if 1...#endif

热门文章

  1. GitHub-Microsoft:sql-server-samples
  2. vue路由在keep-alive下的刷新问题 对watch的影响
  3. OGG-01877 Missing explicit accessrule for server collector
  4. dom4j工具对XML写入修改删除操作实现
  5. 简单配置 docker swarm
  6. XSS攻击总结
  7. Python:Base2(List和Tuple类型, 条件判断和循环,Dict和Set类型)
  8. Java ——类型转换 向args传递参数
  9. VM Centos 连不上网或者ping不通问题汇总
  10. solr设置分片和副本