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

二.操作:

 初始磁盘情况:  

 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

即可。

CentOS6.5增加挂载点容量的更多相关文章

  1. LVM XFS增加硬盘分区容量(resize2fs: Bad magic number in super-block while)

    LVM XFS增加硬盘分区容量(resize2fs: Bad magic number -- :: 分类: Linux LVM XFS增加硬盘分区容量(resize2fs: Bad magic num ...

  2. CentOS6.5系统挂载NTFS分区的移动硬盘 centos安装repoforge源(yum)

    CentOS6.5系统挂载NTFS分区的移动硬盘 作为IT的工作者,避免不了使用Linux系统,我现在使用的系统是CentOS6.5 X86_64位版本,但是插入NTFS移动硬盘没有办法识别.通过下面 ...

  3. CentOS6.5系统挂载NTFS分区的移动硬盘

    CentOS6.5系统挂载NTFS分区的移动硬盘 作为IT的工作者,避免不了使用Linux系统,我如今使用的系统是CentOS6.5 X86_64位版本号,可是插入NTFS移动硬盘没有办法识别.通过以 ...

  4. VirtualBox虚拟机增加CentOS根目录容量 LVM扩容

    对于目前的网络开发者来说,比较好的搭档就是Win7+VirtualBox+CentOS的组合,既可以发挥Linux强大的网络服务功能,也可以有效的隔离各项服务拖慢系统,影响系统的运行,对于新手来说可以 ...

  5. Virtual Box 增加虚拟硬盘容量

    情景: 我现在用 Win10, 因为项目原因要在虚拟机装一个 Win7. 预先估计不足. Win7 C盘容量不够. 方法1: 增加虚拟硬盘文件. 首先把虚拟机 Win7 删掉 (但不要删虚拟硬盘文件, ...

  6. CentOS6.9中挂载NTFS移动硬盘

    公司需要本地备份,不占用公网带宽,而本地服务器硬盘容量不够,所以需要将本地服务器centos 6.9系统的备份数据拷贝到移动硬盘. 所以需要在centos上挂载NTFS格式的移动硬盘. 方法/步骤: ...

  7. 在向一个ArrayList中添加大量元素前,可以使用ensureCapacity方法来增加ArrayList的容量

    参考http://www.jianshu.com/p/f174d49b391c ensureCapacity(),该方法就是 ArrayList 的扩容方法.在前面就提过 ArrayList 每次新增 ...

  8. 在centos6.5下挂载windows共享文件夹

    1.在windows下建立文件夹f:\linux,共享给win下用户username,该用户密码为passwd.该windows系统在局域网中IP为192.168.18.203 2.在centos6. ...

  9. Linux增加挂载盘

    命令:fdisk /dev/sdb, m 命令:m,n,e,1,p,w 命令:mkfs -t ext4 /dev/sdb,y 挂载命令:mount -t ext4 /dev/sdb /data 获取U ...

随机推荐

  1. np.where()

    numpy.where (condition[, x, y]) numpy.where()两种用法 1. np.where(condition, x, y) 满足条件(condition),输出x,不 ...

  2. Mysqlfunc.c

    int rc;int db_connection;char *server = "192.168.139.207"; // 数据库的ip地址char *user = "c ...

  3. strip使用

    strip作用:去掉空格.以及想要去掉的字符,实例如下: In [42]: import subprocess In [42]: output=subprocess.check_output([&qu ...

  4. [转] Maven 从命令行获取项目的版本号

    [From]https://blog.soebes.de/blog/2018/06/09/help-plugin/ I bet you have been faced with the situati ...

  5. keystone 域-项目-用户-角色

    https://docs.openstack.org/keystone/latest/  官方文档 domain是认证边界,项目.用户属于域,然后通过角色把用户和项目关联起来.  openstack  ...

  6. java base64相关

    文件转Base64: public static String imgToBase64(InputStream inStream) { byte[] data = null; try { //avai ...

  7. StringRedisTemplate与RedisTemplate区别

    StringRedisTemplate与RedisTemplate两者的关系是StringRedisTemplate继承RedisTemplate. 两者的数据是不共通的:也就是说StringRedi ...

  8. Python爬虫学习==>第十一章:分析Ajax请求-抓取今日头条信息

    学习目的: 解决AJAX请求的爬虫,网页解析库的学习,MongoDB的简单应用 正式步骤 Step1:流程分析 抓取单页内容:利用requests请求目标站点,得到单个页面的html代码,返回结果: ...

  9. python pandas dataframe 读取和写入Oracle

    1.代码:主要写入时表要为小写,否则报错 Could not reflect: requested table(s) not available in Engine from sqlalchemy i ...

  10. DataGridView中的ComboboxCell报了System.ArgumentException:DagaGridViewComboBoxCell值无效错误

    原因是初始化的时候给ComboboxCell绑定了一系列的值,但是真正赋值的时候却给了一个不在那一系列值范围中的值,所以就报了这个错 在开发的时候难免会因为数据的问题出现这个问题,为了不让系统崩掉,就 ...