Linux VPS下启用未使用的硬盘空间扩充LVM

林继 VPS 知识 3,153 共写了1289个字 (2012-03-16 20:56:04) 没有评论 打印 扫描二维码 百度已收录

SSH登陆后,查看现有分区、挂载及swap情况:
可以看到大概8G的硬盘空间分布情况

  1. df -hal
  2. free -m
  1. [root@XenSystem ~]# df -hal
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/mapper/VolGroup00-LogVol00
  4. 5.7G 1.1G 4.4G 20% /
  5. proc 0 0 0 - /proc
  6. sysfs 0 0 0 - /sys
  7. devpts 0 0 0 - /dev/pts
  8. /dev/xvda1 99M 27M 67M 29% /boot
  9. tmpfs 257M 0 257M 0% /dev/shm
  10. none 0 0 0 - /proc/sys/fs/binfmt_misc
  11. sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs
  1. [root@XenSystem~]# free -m
  2.              total       used       free     shared    buffers     cached
  3. Mem:           512        506          5          0        447          9
  4. -/+ buffers/cache:         49        463
  5. Swap:         2079          0       2079

查看硬盘设备列表:

  1. fdisk -l
  1. Disk /dev/xvdb: 23.6 GB, 23622320128 bytes
  2. 255 heads, 63 sectors/track, 2871 cylinders
  3. Units = cylinders of 16065 * 512 = 8225280 bytes
  4. Disk /dev/xvdb doesn't contain a valid partition table
  5. Disk /dev/xvda: 8589 MB, 8589934592 bytes
  6. 255 heads, 63 sectors/track, 1044 cylinders
  7. Units = cylinders of 16065 * 512 = 8225280 bytes
  8.     Device Boot      Start         End      Blocks   Id  System
  9. /dev/xvda1   *           1          13      104391   83  Linux
  10. /dev/xvda2              14        1044     8281507+  8e  Linux LVM

硬盘/dev/xvdb尚未划分使用,接下来我们为dev/xvdb分区

  1. fdisk /dev/xvdb
  1. [root@XenSystem ~]# fdisk /dev/xvdb
  2. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  3. Building a new DOS disklabel. Changes will remain in memory only,
  4. until you decide to write them. After that, of course, the previous
  5. content won't be recoverable.
  6.  
  7. The number of cylinders for this disk is set to 2871.
  8. There is nothing wrong with that, but this is larger than 1024,
  9. and could in certain setups cause problems with:
  10. 1) software that runs at boot time (e.g., old versions of LILO)
  11. 2) booting and partitioning software from other OSs
  12.    (e.g., DOS FDISK, OS/2 FDISK)
  13. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

#输入n,新建分区

  1. Command (m for help): n

#输入P,主分区

  1. Command action
  2.    e   extended
  3.    p   primary partition (1-4)
  4. p

#目前是xvdb第一个分区输入1

  1. Partition number (1-4): 1

#敲回车,默认就行了

  1. First cylinder (1-2871, default 1):
  2. Using default value 1
  3. Last cylinder or +size or +sizeM or +sizeK (1-2871, default 2871):
  4. Using default value 2871

#这里输入t,指定分区的格式为8e (LVM)

  1. Command (m for help): t
  2. Selected partition 1
  3. Hex code (type L to list codes): 8e
  4. Changed system type of partition 1 to 8e (Linux LVM)

#这里输入w,保存退出

  1. Command (m for help): w
  2. The partition table has been altered!
  3. Calling ioctl() to re-read partition table.
  4. Syncing disks.

重启使其生效

  1. reboot

重启后,再次运行fdisk -l,可看到我们划分的xvdb1已经生效了

  1. [root@XenSystem]# fdisk -l
  2. Disk /dev/xvdb: 23.6 GB, 23622320128 bytes
  3. 255 heads, 63 sectors/track, 2871 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5.  
  6. Device Boot Start End Blocks Id System
  7. /dev/xvdb1 1 2871 23061276 8e Linux LVM
  8.  
  9. Disk /dev/xvda: 8589 MB, 8589934592 bytes
  10. 255 heads, 63 sectors/track, 1044 cylinders
  11. Units = cylinders of 16065 * 512 = 8225280 bytes
  12.  
  13. Device Boot Start End Blocks Id System
  14. /dev/xvda1 * 1 13 104391 83 Linux
  15. /dev/xvda2 14 1044 8281507+ 8e Linux LVM

执行vgs查看卷组情况,可以看到只有一个卷组VolGroup00(此名称因系统而异)

  1. vgs
  1. [root@XenSystem ~]# vgs
  2. VG #PV #LV #SN Attr VSize VFree
  3. VolGroup00 2 2 0 wz--n- 49.84G 0

创建物理卷,并将物理卷加入到组VolGroup00(此名称因系统而异)

  1. pvcreate /dev/xvdb1
  2. vgextend VolGroup00 /dev/xvdb1
  1. [root@XenSystem~]# pvcreate /dev/xvdb1
  2.   Physical volume "/dev/xvdb1" successfully created
  3. [root@XenSystem~]# vgextend VolGroup00 /dev/xvdb1
  4.   Volume group "VolGroup00" successfully extended

执行vgdisplay查看卷组空间情况

  1. vgdisplay
  1. [root@XenSystem~]# vgdisplay
  2.   --- Volume group ---
  3.   VG Name               VolGroup00
  4.   System ID
  5.   Format                lvm2
  6.   Metadata Areas        2
  7.   Metadata Sequence No  4
  8.   VG Access             read/write
  9.   VG Status             resizable
  10.   MAX LV                0
  11.   Cur LV                2
  12.   Open LV               2
  13.   Max PV                0
  14.   Cur PV                2
  15.   Act PV                2
  16.   VG Size               29.84 GB
  17.   PE Size               32.00 MB
  18.   Total PE              955
  19.   Alloc PE / Size       252 / 7.88 GB
  20.   Free  PE / Size       703 / 21.97 GB
  21.   VG UUID               jWlke0-R01B-RqBP-Qp1X-xxi0-ltOI-FompAt

可以看到大概有21.97G的空间可以扩充使用,我们将卷组下的卷LogVol00扩容21.96G

  1. lvresize -L +21.96G /dev/VolGroup00/LogVol00
  2. resize2fs /dev/VolGroup00/LogVol00
  1. [root@XenSystem~]# lvresize -L +21.96G /dev/VolGroup00/LogVol00
  2. Rounding up size to full physical extent 21.97 GB
  3. Extending logical volume LogVol00 to 27.81 GB
  4. Logical volume LogVol00 successfully resized
  5. [root@XenSystem~]# resize2fs /dev/VolGroup00/LogVol00
  6. resize2fs 1.39 (29-May-2006)
  7. Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing require d
  8. Performing an on-line resize of /dev/VolGroup00/LogVol00 to 7290880 (4k) blocks.
  9. The filesystem on /dev/VolGroup00/LogVol00 is now 7290880 blocks long.

运行完成后,我们可以持到相应的空间已经扩展出来可以使用了

  1. [root@XenSystem~]# df -hal
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/mapper/VolGroup00-LogVol00
  4. 27G 1.1G 25G 5% /
  5. proc 0 0 0 - /proc
  6. sysfs 0 0 0 - /sys
  7. devpts 0 0 0 - /dev/pts
  8. /dev/xvda1 99M 27M 67M 29% /boot
  9. tmpfs 257M 0 257M 0% /dev/shm
  10. none 0 0 0 - /proc/sys/fs/binfmt_misc
  11. sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs

系统重装后的重装扩展处理!

重装后,直接执行resize2fs进去动态扩容即可。

  1. resize2fs /dev/VolGroup00/LogVol00

PVs missing导致LVM无法重新扩容的解决办法!

运行vgextend、vgdisplay返回错误:

  1. Couldn't find device with uuid ************************
  2. Cannot change VG VolGroup00 while PVs are missing.

此时可以运行

  1. vgreduce VolGroup00  --removemissing

然后重新扩容LVM即可

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

< >