机器原来有一块硬盘容量不够了,现需要增加一块硬盘,系统使用了LVM,系统为:Redhat Enterprise Linux 5

操作步骤

注意:请在操作时小心细心,并且操作前备份系统数据,以防万一。有血的教训呀!!!

  • 添加物理磁盘:将物理磁盘添加到机器,加入物理磁盘后需要先重新启动一下机器,才可以看到新加的磁盘(使用fdisk -l查看);
  • 创建物理卷;
  • 将新的物理卷加入到卷组;
  • 扩展逻辑卷;
  • 在线resize逻辑卷,使空间生效

准备磁盘

一般可能有2种情况:1)物理机或者虚拟机新添加磁盘;2)虚拟机扩展磁盘尺寸或者物理机克隆硬盘置换大硬盘;这两种操作后都需要在新的磁盘或者剩余空间中建立分区。

如果磁盘是虚拟机方式在原有磁盘扩展来的(热扩展),则再添加新的分区后需要执行分区加载操作,否则在/dev目录中将不存在,不能使用。

# partprobe /dev/vda3

查看新加的磁盘设备名称

[root@ora11g ~]# fdisk -l

我新加的磁盘为/dev/sdb,如果是虚拟机有可能是/dev/vdb或者其它。

添加一个新的分区

[root@ora11g ~]# fdisk /dev/sdb
...
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-17834, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-17834, default 17834): 
Using default value 17834
...

显示已经创建的分区

Command (m for help): p

Disk /dev/sdb: 146.6 GB, 146695782400 bytes
255 heads, 63 sectors/track, 17834 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 17834 143251573+ 83 Linux

列出已知的分区类型

Command (m for help): l

0 Empty 1c Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid
1 FAT12 1e Hidden W95 FAT1 75 PC/IX be Solaris boot 
2 XENIX root 24 NEC DOS 80 Old Minix c1 DRDOS/sec (FAT-
3 XENIX usr 39 Plan 9 81 Minix / old Lin c4 DRDOS/sec (FAT-
...

修改分区类型为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)

查看分区信息

Command (m for help): p

Disk /dev/sdb: 146.6 GB, 146695782400 bytes
255 heads, 63 sectors/track, 17834 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 17834 143251573+ 8e Linux LVM

写入分区表

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

添加磁盘到LVM卷

查看当前分区状态

[root@ora11g ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
68249152 59970328 4811972 93% /
/dev/sda1 101086 12386 83481 13% /boot
none 1037404 0 1037404 0% /dev/shm

查看当前卷配置,这里我们需要扩展逻辑卷/dev/VolGroup00/LogVol00的空间

[root@ora11g ~]# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID X4wkrd-f2WD-Tatu-jZFC-O4c3-y0kI-5bg1aC
LV Write Access read/write
LV Status available
# open 1
LV Size 66.12 GB
Current LE 2116
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID wKKpwV-aiaO-qAGe-gNs3-lUas-b4Y0-hWWAfl
LV Write Access read/write
LV Status available
# open 1
LV Size 1.94 GB
Current LE 62
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1

结果显示所属的卷组为:VolGroup00请显示结果,接下啦我们要建立物理卷并加入卷组。

创建新的物理卷

[root@ora11g ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

查看物理卷状态

[root@ora11g ~]# pvdisplay /dev/sdb1
--- Physical volume ---
PV Name /dev/sdb1
VG Name VolGroup00
PV Size 136.59 GB / not usable 0 
Allocatable yes 
PE Size (KByte) 32768
Total PE 4371
Free PE 4371
Allocated PE 0
PV UUID Mo7mk5-Y0tS-vYnQ-s3N5-db1t-jh8v-MFI5YR

扩展卷组到新加的物理卷

[root@ora11g ~]# vgextend VolGroup00 /dev/sdb1
  Volume group "VolGroup00" successfully extended

查看卷组

[root@ora11g ~]# vgdisplay

查看当前分区容量,还未发生变化。

[root@ora11g ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
68249152 59970504 4811796 93% /
/dev/sda1 101086 12386 83481 13% /boot
none 1037404 0 1037404 0% /dev/shm

扩展卷空间

[root@ora11g ~]# lvextend -L +49G /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 84.94 GB
  Logical volume LogVol00 successfully resized

[root@ora11g ~]# ext2online /dev/VolGroup00/LogVol00

注:在debian 5.0和redhat 5.0中执行的是下面这个命令,它里面没有 ext2online请使用以下命令

# resize2fs /dev/VolGroup00/LogVol00

如果你的系统是xfs,请使用以下命令,可通过cat /etc/fstab查看:

# xfs_growfs /dev/centos/root

查看扩容结果

[root@ora11g ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
208618032 59944412 138078192 31% /
/dev/sda1 101086 12386 83481 13% /boot
none 1037404 0 1037404 0% /dev/shm

[ 编辑 | 历史 ]
最近由“jilili”在“2021-09-21 10:23:23”修改