在原先的基础上添加了一块20G的硬盘,给lvm分区扩容
#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda5 7.1G 2.1G 4.7G 31% /
/dev/mapper/VolGroup00-LogVol00
12G 159M 11G 2% /home
/dev/hda1 92M 12M 76M 13% /boot
tmpfs 125M 0 125M 0% /dev/shm
#fdisk -l
Disk /dev/hda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 12 96358+ 83 Linux
/dev/hda2 13 1598 12739545 8e Linux LVM
/dev/hda3 1599 1663 522112+ 82 Linux swap / Solaris
/dev/hda4 1664 2610 7606777+ 5 Extended
/dev/hda5 1664 2610 7606746 83 Linux
Disk /dev/hdb: 21.4 GB, 21474836480 bytes
15 heads, 63 sectors/track, 44384 cylinders
Units = cylinders of 945 * 512 = 483840 bytes
Disk /dev/hdb doesn't contain a valid partition table
很明显/home目录是我们所要扩容的lvm分区,而新添加20G硬盘还未被格式化成LVM格式,现在我们就将他格式化成LVM
#fdisk /dev/hdb
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 44384.
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)
Command (m for help):n //创建一个新分区
Command action
e extended
p primary partition (1-4)
p //分区编号
Partition number (1-4): 1
First cylinder (1-44384, default 1): //起始块,默认为1
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-44384, default 44384): //结束块,默认最大
Using default value 44384
Command (m for help):t //更变分区格式
Selected partition 1
Hex code (type L to list codes):8e //分区格式代码,L可查看所有编码
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p //打印分区情况
Disk /dev/hdb: 21.4 GB, 21474836480 bytes
15 heads, 63 sectors/track, 44384 cylinders
Units = cylinders of 945 * 512 = 483840 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 44384 20971408+ 8e Linux LVM
Command (m for help): w //保存并退出分区
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
打下面指令可以不用重开机
# partprobe
这样一来格式化分区就做完了,就剩下的任务就是扩容:
首先查看下当前有哪些PV
#pvscan or pvdisplay
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
PV /dev/hda2 VG VolGroup00 lvm2 [12.12 GB / 0 free]
Total: 1 [12.12 GB] / in use: 1 [12.12 GB] / in no VG: 0 [0 ]
然后将新划分的/dev/hdb1做成PV
#pvcreate /dev/hdb1
Physical volume "/dev/hdb1" successfully created
再看下,PV的情况
#pvscan or pvdisplay
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
PV /dev/hda2 VG VolGroup00 lvm2 [12.12 GB / 0 free]
PV /dev/hdb1 VG VolGroup00 lvm2 [19.97 GB / 19.97 GB free]
Total: 2 [32.09 GB] / in use: 2 [32.09 GB] / in no VG: 0 [0 ]
可以发现新创建的PV还有19.97G空闲,然后给VolGroup00卷组添加剩余的空闲空间
#lvextend -L +19G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 31.12 GB
Logical volume LogVol00 successfully resized
最后,resize卷组
#resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /home; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 8159232 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 8159232 blocks long.
见证奇迹吧
#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda5 7.1G 2.1G 4.7G 31% /
/dev/mapper/VolGroup00-LogVol00
31G 165M 29G 1% /home
/dev/hda1 92M 12M 76M 13% /boot
tmpfs 125M 0 125M 0% /dev/shm