标签:
一.背景:因为公司虚拟机 (/) 目录容量过小,导致一些任务不能正常执行,需要给虚拟机扩容
二.操作:
初始磁盘情况:
1.使用 df 命令查看磁盘与目录的容量:
[root@shaonian ~]# df -h Filesystem 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% /home cm_processes 3.8G 808K 3.8G 1% /var/run/cloudera-scm-agent/process
2.使用 fdisk -l 命令查看磁盘分区:
[root@shaonian ~]# fdisk -l Disk /dev/xvdb: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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 Disk /dev/xvda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 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: 0x000e9377 Device Boot Start End Blocks Id System /dev/xvda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/xvda2 64 7833 62401536 8e Linux LVM Disk /dev/xvdd: 119 MB, 119891968 bytes 255 heads, 63 sectors/track, 14 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 Disk /dev/mapper/VolGroup-lv_root: 52.3 GB, 52344913920 bytes 255 heads, 63 sectors/track, 6363 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 Disk /dev/mapper/VolGroup-lv_swap: 6442 MB, 6442450944 bytes 255 heads, 63 sectors/track, 783 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 Disk /dev/mapper/VolGroup-lv_home: 5108 MB, 5108662272 bytes 255 heads, 63 sectors/track, 621 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
发现执行 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 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): p Disk /dev/xvdb: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0xd259beb1 Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-10443, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): Using default value 10443 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): 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 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% /home cm_processes 3.8G 792K 3.8G 1% /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 / 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
即可。
标签:
原文地址:http://www.cnblogs.com/dreamtecher/p/5840054.html