用户名:
密 码:
为何选择我们
  • 7年优质服务经验
  • 10万用户的共同选择
  • 更低的价格更好的服务
  • CNNIC四星级认证服务商
  • 拥有正规经营许可证(ICP)
  • 先进的解析技术10分钟生效
  • 6组DNS负载均衡更快更稳定
  虚拟主机域名注册-常见问题主机租用问题 → 主机租用问题


[分享]Linux系统下的VPS主机启用未使用的硬盘空间扩充LVM
作者:

前面我们的教程已经有具体方法介绍如何挂载分区并保证在重装系统后数据不丢失,大家可以参考Linux VPS新硬盘分区与挂载教程进行操作。

此教程是教大家启用未使用的硬盘空间扩充LVM,简单说,EXT3格式是独立的分区,LVM格式是把存储附加(扩充)到分区,因此在重装系统后会导致数据丢失。

一般在没有重要数据的情况下,可采用此方法。

用SSH登陆,查看目前磁盘分区状况:

# df -hal

# free -m

[root@Myvps ~]# df -hal
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
5.7G 1.1G 4.4G 20% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
/dev/xvda1 99M 27M 67M 29% /boot
tmpfs 257M 0 257M 0% /dev/shm
none 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs

[root@Myvps~]# free -m
total used free shared buffers cached
Mem: 512 506 5 0 447 9
-/+ buffers/cache: 49 463
Swap: 2079 0 2079

可以看出目前已经分配有大概8G的硬盘虚拟空间

查看硬盘设备列表:

# fdisk -l

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

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

# fdisk /dev/xvdb

[root@Myvps ~]# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 2871.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

#输入n,新建分区
Command (m for help): n

#输入P,主分区
Command action
e extended
p primary partition (1-4)
p

#目前是xvdb第一个分区输入1
Partition number (1-4): 1

#敲回车,默认就行了
First cylinder (1-2871, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2871, default 2871):
Using default value 2871

#这里输入t,指定分区的格式为8e (LVM)
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)

#这里输入w,保存退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

到此已经创建了 /dev/xvdb1 这个LVM分区,重启使设置生效

# reboot

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

# vgs

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

可以看出目前已划分 VolGroup00 这个卷组,接下来将分区 /dev/xvdb1 创建物理卷,并将物理卷加入到组VolGroup00(此名称因系统而异)

# pvcreate /dev/xvdb1

# vgextend VolGroup00 /dev/xvdb1

[root@Myvps~]# pvcreate /dev/xvdb1
Physical volume "/dev/xvdb1" successfully created
[root@Myvps~]# vgextend VolGroup00 /dev/xvdb1
Volume group "VolGroup00" successfully extended

执行vgdisplay查看卷组空间情况


# vgdisplay

[root@Myvps~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 29.84 GB
PE Size 32.00 MB
Total PE 955
Alloc PE / Size 252 / 7.88 GB
Free PE / Size 703 / 21.97 GB
VG UUID jWlke0-R01B-RqBP-Qp1X-xxi0-ltOI-FompAt

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

# lvresize -L +21.96G /dev/VolGroup00/LogVol00

# resize2fs /dev/VolGroup00/LogVol00

[root@Myvps~]# lvresize -L +21.96G /dev/VolGroup00/LogVol00
Rounding up size to full physical extent 21.97 GB
Extending logical volume LogVol00 to 27.81 GB
Logical volume LogVol00 successfully resized


[root@Myvps~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing require d
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 7290880 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 7290880 blocks long.

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

[root@Myvps~]# df -hal
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
27G 1.1G 25G 5% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
/dev/xvda1 99M 27M 67M 29% /boot
tmpfs 257M 0 257M 0% /dev/shm
none 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs



来源: http://idcmz.com/
阅读:1503
日期:2012/11/1

【 双击滚屏 】 【 推荐朋友 】 【 收藏 】 【 打印 】 【 关闭 】 【 字体: 】 
上一篇:[分享]百度站长平台高端SEO网站优化俱乐部第一期沙龙活动整理
下一篇:[分享]解决使用PHPMyAdmin时会提示 PHPMyAdmin 无法载入mcrypt 扩展
  >> 相关文章
  没有相关文章。