首页 > 代码库 > CentOS6.5增加挂载点容量

CentOS6.5增加挂载点容量

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

二.操作:

 初始磁盘情况:  

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

[root@shaonian ~]# df -hFilesystem                    Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root   48G   22G   25G  47% /tmpfs                         3.8G     0  3.8G   0% /dev/shm/dev/xvda1                    485M   33M  427M   8% /boot/dev/mapper/VolGroup-lv_home  4.7G  138M  4.4G   4% /homecm_processes                  3.8G  808K  3.8G   1% /var/run/cloudera-scm-agent/process

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

[root@shaonian ~]# fdisk -lDisk /dev/xvdb: 85.9 GB, 85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/xvda: 64.4 GB, 64424509440 bytes255 heads, 63 sectors/track, 7832 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000e9377    Device Boot      Start         End      Blocks   Id  System/dev/xvda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/xvda2              64        7833    62401536   8e  Linux LVMDisk /dev/xvdd: 119 MB, 119891968 bytes255 heads, 63 sectors/track, 14 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_root: 52.3 GB, 52344913920 bytes255 heads, 63 sectors/track, 6363 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_swap: 6442 MB, 6442450944 bytes255 heads, 63 sectors/track, 783 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_home: 5108 MB, 5108662272 bytes255 heads, 63 sectors/track, 621 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

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

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

[root@shaonian ~]# fdisk /dev/xvdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding 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 wont be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. Its strongly recommended to         switch off the mode (command c) and change display units to         sectors (command u).Command (m for help): pDisk /dev/xvdb: 85.9 GB, 85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xd259beb1    Device Boot      Start         End      Blocks   Id  SystemCommand (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-10443, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): Using default value 10443Command (m for help): tSelected partition 1Hex code (type L to list codes): 8eChanged system type of partition 1 to 8e (Linux LVM)Command (m for help): wThe 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 -hFilesystem                    Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root  127G   22G   99G  18% /tmpfs                         3.8G     0  3.8G   0% /dev/shm/dev/xvda1                    485M   33M  427M   8% /boot/dev/mapper/VolGroup-lv_home  4.7G  138M  4.4G   4% /homecm_processes                  3.8G  792K  3.8G   1% /var/run/cloudera-scm-agent/process

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

 

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

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

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

Couldnt find device with uuid cRdLUx-1ttO-JUKw-K2Bu-FOw2-EIrk-87Xdl3.

运行 pvscan 查看 pv:

lvm> pvscan  Couldnt find device with uuid cRdLUx-1ttO-JUKw-K2Bu-FOw2-EIrk-87Xdl3.  Couldnt find device with uuid 7Ef30A-6qRY-bBP0-CTH9-f6ut-kE8x-ch4c2j.  PV /dev/xvda2       VG VolGroup   lvm2 [59.51 GiB / 0    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: 4 [299.50 GiB] / in use: 4 [299.50 GiB] / in no VG: 0 [0   ]

发现 有两行 出现了 unknown device 

执行

lvm> vgreduce --removemissing  VolGroup

即可。

CentOS6.5增加挂载点容量