中国稳网用户

云主机中LINUX(CentOS 5.6)系统如何将新分配的空间扩展至根分区下(无须重启)

来源:   作者:   日期:2013-01-06
分享到:
云主机中LINUX(CentOS 5.6)系统默认只有10G空间,如何将其它可用空间加入至"/"根分区下直接使用,不必重新启动系统,也不必重新挂在分区!
前提要求“/”根分区使用LVM。这个感谢旺角的先见之明!话不多说,开始操作:
一、将空闲的10G磁盘(/dev/hdb)做成LVM分区,由于一开始没有想到要做教程,所以没有保存分区的方式,大致说一下
1使用fdisk /dev/hdb命令分区

[root@localhost ~]# fdisk /dev/hdb
The number of cylinders for this disk is set to 20805.
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)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
然后设置分区块的大小,默认就好。两次回车,即完成
然后设置分区的类型,
输入t 设置分区类型
输入3 3号分区
输入8e 设置为LVM

[root@localhost ~]# fdisk -l   --查看分区
Disk /dev/hda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        1305    10377990   8e  Linux LVM
Disk /dev/hdb: 10.7 GB, 10737418240 bytes
16 heads, 63 sectors/track, 20805 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hdb3               1       20805    10485688+  8e  Linux LVM   已经将可用10G空间分成LVM类型了

[root@localhost ~]# df -h           查看容量 现在根分区是7.7G
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                      7.7G  3.4G  4.0G  46% /
/dev/hda1              99M   22M   73M  23% /boot
tmpfs                 506M     0  506M   0% /dev/shm
[root@localhost ~]# pvcreate /dev/hdb3            创建物理卷
  Physical volume "/dev/hdb3" successfully created
[root@localhost ~]# vgextend /dev/VolGroup00 /dev/hdb3  将物理卷加入逻辑卷中
  /dev/hdc: open failed: 找不到介质
  Volume group "VolGroup00" successfully extended
[root@localhost ~]# 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               19.84 GB  //已经20G了,完成第一步工作了。
  PE Size               32.00 MB
  Total PE              635
  Alloc PE / Size       316 / 9.88 GB
  Free  PE / Size       319 / 9.97 GB
  VG UUID               saeQq7-ZDfs-tfMK-WXwc-1Dp4-zp0n-WPOffm
[root@localhost ~]# lvextend -L +10G /dev/VolGroup00/LogVol00       开始扩容了,在原来的LogVol00增加10G
  Extending logical volume LogVol00 to 17.88 GB
  Insufficient free space: 320 extents needed, but only 319 available  //这里执行错误了,原因是实际没有10G,只有9G多一点。
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                KvXRSp-5opU-NpMr-xfat-x9rI-m88t-nSjGTV
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                7.88 GB
  Current LE             252
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                ee8srq-8YwD-DDUk-rQEs-0IoY-B6U5-YWr2oz
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             64
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
[root@localhost ~]# lvextend -L +10737M /dev/VolGroup00/LogVol00
  Rounding up size to full physical extent 10.50 GB
  Extending logical volume LogVol00 to 18.38 GB
  Insufficient free space: 336 extents needed, but only 319 available
[root@localhost ~]# lvextend -L +10537M /dev/VolGroup00/LogVol00
  Rounding up size to full physical extent 10.31 GB
  Extending logical volume LogVol00 to 18.19 GB
  Insufficient free space: 330 extents needed, but only 319 available
[root@localhost ~]# lvextend -L +10037M /dev/VolGroup00/LogVol00    扩容10037M才成功。汗!!!!!!!!!!!!
  Rounding up size to full physical extent 9.81 GB
  Extending logical volume LogVol00 to 17.69 GB
  Logical volume LogVol00 successfully resized
[root@localhost ~]# lvdisplay   查看一下大小,看不是已经扩展出来了
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                KvXRSp-5opU-NpMr-xfat-x9rI-m88t-nSjGTV
  LV Write Access        read/write
  LV Status              available
  # open                 1
LV Size                17.69 GB
  Current LE             566
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                ee8srq-8YwD-DDUk-rQEs-0IoY-B6U5-YWr2oz
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             64
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol00   //使增加的容量生效。
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 4636672 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 4636672 blocks long.
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                KvXRSp-5opU-NpMr-xfat-x9rI-m88t-nSjGTV
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                17.69 GB
  Current LE             566
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                ee8srq-8YwD-DDUk-rQEs-0IoY-B6U5-YWr2oz
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             64
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
[root@localhost ~]# df -h  再查看分区。已经有18G了。是不是很爽。
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                       18G  3.4G   13G  21% /
/dev/hda1              99M   22M   73M  23% /boot
tmpfs                 506M     0  506M   0% /dev/shm
[root@localhost ~]#


推荐 】 【 打印

中国稳网 版权所有 wendns.com