转载自http://blogold.chinaunix.net/u3/93765/showart_2082034.html
注意:此种扩容/的根目录的前提是分区必须采用LVM格式完成,此次实验系统为redhat 4
分区规划:boot 150MB
/ 5000MB rootlv
home 500MB homelv
swap 500MB swaplv
二、通过系统自带的逻辑卷管理器进行查看LVM的详细信息
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv
4.8G 3.0G 1.6G 66% /
/dev/sda1 145M 14M 124M 10% /boot
none 125M 0 125M 0% /dev/shm
/dev/mapper/rootvg-homelv
465M 11M 431M 3% /home
[root@localhost ~]# fdisk -l
Disk /dev/sda: 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/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 401 3068415 8e Linux LVM
/dev/sda3 402 720 2562367+ 8e Linux LVM
/dev/sda4 721 1044 2602530 5 Extended
/dev/sda5 721 975 2048256 8e Linux LVM
[root@localhost /]# lvextend -L +500M /dev/mapper/rootvg-rootlv
Rounding up size to full physical extent 512.00 MB
Extending logical volume rootlv to 5.38 GB
Logical volume rootlv successfully resized
[root@localhost /]# ext2online /dev/mapper/rootvg-rootlv
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv
5.3G 3.0G 2.1G 60% /
/dev/sda1 145M 14M 124M 10% /boot
none 125M 0 125M 0% /dev/shm
/dev/mapper/rootvg-homelv
465M 11M 431M 3% /home
Disk /dev/sda: 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/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 401 3068415 8e Linux LVM
/dev/sda3 402 720 2562367+ 8e Linux LVM
/dev/sda4 721 1044 2602530 5 Extended
/dev/sda5 721 975 2048256 8e Linux LVM
四、通过图形界面来对/根目录进行扩容500MB测试
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv
5.3G 3.0G 2.1G 60% /
/dev/sda1 145M 14M 124M 10% /boot
none 125M 0 125M 0% /dev/shm
/dev/mapper/rootvg-homelv
465M 11M 431M 3% /home
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv
5.8G 3.0G 2.5G 55% /
/dev/sda1 145M 14M 124M 10% /boot
none 125M 0 125M 0% /dev/shm
/dev/mapper/rootvg-homelv
465M 11M 431M 3% /home
五、通过命令方式建立新LVM的文件系统/jiajia和卷组jiajiavg,大小为200MB,主要步骤见下面红色字体
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 1044.
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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
First cylinder (976-1044, default 976):
Using default value 976
Last cylinder or +size or +sizeM or +sizeK (976-1044, default 1044): +200M
Command (m for help): p
Disk /dev/sda: 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/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 401 3068415 8e Linux LVM
/dev/sda3 402 720 2562367+ 8e Linux LVM
/dev/sda4 721 1044 2602530 5 Extended
/dev/sda5 721 975 2048256 8e Linux LVM
/dev/sda6 976 1000 200781 83 Linux
Partition number (1-6): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 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/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 401 3068415 8e Linux LVM
/dev/sda3 402 720 2562367+ 8e Linux LVM
/dev/sda4 721 1044 2602530 5 Extended
/dev/sda5 721 975 2048256 8e Linux LVM
/dev/sda6 976 1000 200781 8e Linux LVM
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]# partprobe ---使得上面的设置生效,而无需要重启系统
[root@localhost ~]# pvcreate /dev/sda6 ---将/dev/sda6转换成PV
Physical volume "/dev/sda6" successfully created
[root@localhost ~]# pvdisplay /dev/sda6 ---检查新PV的详细信息
"/dev/sda6" is a new physical volume of "196.08 MB"
--- NEW Physical volume ---
PV Name /dev/sda6
VG Name
PV Size 196.08 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID lICdJx-KJAP-SO33-unmJ-ox4x-eR1Z-GJvn0z
[root@localhost ~]# vgcreate jiajiavg /dev/sda6 ---创建卷组,并将逻辑卷/dev/sda6加入到该卷组jiajiavg中
Volume group "jiajiavg" successfully created
[root@localhost ~]# vgdisplay jiajiavg
--- Volume group ---
VG Name jiajiavg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 192.00 MB
PE Size 4.00 MB
Total PE 48
Alloc PE / Size 0 / 0
Free PE / Size 48 / 192.00 MB
VG UUID is2u3L-G9F1-Bnrc-9rPM-1DFm-WDSD-wLog9u
[root@localhost ~]# lvcreate -L 150M -n lvjiajia jiajiavg ---从卷组jiajiavg中分出150M出来给LV,名为lvjiajia
Rounding up size to full physical extent 152.00 MB
Logical volume "lvjiajia" created
[root@localhost ~]# lvdisplay /dev/jiajiavg/lvjiajia
--- Logical volume ---
LV Name /dev/jiajiavg/lvjiajia
VG Name jiajiavg
LV UUID ECAEFu-Pyr3-wkEI-27AE-lYXp-xIWk-1WVI5x
LV Write Access read/write
LV Status available
# open 0
LV Size 152.00 MB
Current LE 38
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
[root@localhost ~]# mke2fs -j /dev/jiajiavg/lvjiajia ---将lvjiajia格式化掉
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
38912 inodes, 155648 blocks
7782 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
19 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/jiajiavg/lvjiajia /jiajia/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv
5.8G 3.1G 2.4G 57% /
/dev/sda1 145M 14M 124M 10% /boot
none 125M 0 125M 0% /dev/shm
/dev/mapper/rootvg-homelv
465M 11M 431M 3% /home
/dev/mapper/jiajiavg-lvjiajia
148M 5.6M 135M 4% /jiajia
六、动态加大VG的大小200M,主要步骤见下面红色字体
[root@localhost ~]# fdisk -l
Disk /dev/sda: 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/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 401 3068415 8e Linux LVM
/dev/sda3 402 720 2562367+ 8e Linux LVM
/dev/sda4 721 1044 2602530 5 Extended
/dev/sda5 721 975 2048256 8e Linux LVM
/dev/sda6 976 1000 200781 8e Linux LVM
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 1044.
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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
First cylinder (1001-1044, default 1001):
Using default value 1001
Last cylinder or +size or +sizeM or +sizeK (1001-1044, default 1044): +200M
Command (m for help): p
Disk /dev/sda: 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/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 401 3068415 8e Linux LVM
/dev/sda3 402 720 2562367+ 8e Linux LVM
/dev/sda4 721 1044 2602530 5 Extended
/dev/sda5 721 975 2048256 8e Linux LVM
/dev/sda6 976 1000 200781 8e Linux LVM
/dev/sda7 1001 1025 200781 83 Linux
Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): 8e
Changed system type of partition 7 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 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/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 401 3068415 8e Linux LVM
/dev/sda3 402 720 2562367+ 8e Linux LVM
/dev/sda4 721 1044 2602530 5 Extended
/dev/sda5 721 975 2048256 8e Linux LVM
/dev/sda6 976 1000 200781 8e Linux LVM
/dev/sda7 1001 1025 200781 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]# vgdisplay rootvg ---先检查未扩容VG钱的大小为7.28G
--- Volume group ---
VG Name rootvg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 3
Act PV 3
VG Size 7.28 GB
PE Size 32.00 MB
Total PE 233
Alloc PE / Size 217 / 6.78 GB
Free PE / Size 16 / 512.00 MB
VG UUID C50uYl-cDF5-03Ie-0Bwh-ucbi-oOpo-Odlmq9
[root@localhost ~]# partprobe ---使得上面的分区生效
[root@localhost ~]# pvcreate /dev/sda7 ---将/dev/sda7转换成PV
Physical volume "/dev/sda7" successfully created
[root@localhost ~]# vgextend rootvg /dev/sda7 ---将PV /dev/sda7加入到VG rootvg中
Volume group "rootvg" successfully extended
[root@localhost ~]# vgdisplay rootvg ---检查扩容后的VG大小为7.47G
--- Volume group ---
VG Name rootvg
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 4
Act PV 4
VG Size 7.47 GB
PE Size 32.00 MB
Total PE 239
Alloc PE / Size 217 / 6.78 GB
Free PE / Size 22 / 704.00 MB
VG UUID C50uYl-cDF5-03Ie-0Bwh-ucbi-oOpo-Odlmq9
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv
5.8G 3.1G 2.4G 57% /
/dev/sda1 145M 14M 124M 10% /boot
none 125M 0 125M 0% /dev/shm
/dev/mapper/rootvg-homelv
465M 11M 431M 3% /home
/dev/mapper/jiajiavg-lvjiajia
148M 5.6M 135M 4% /jiajia
[root@localhost ~]# vgdisplay jiajiavg
--- Volume group ---
VG Name jiajiavg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 192.00 MB
PE Size 4.00 MB
Total PE 48
Alloc PE / Size 38 / 152.00 MB
Free PE / Size 10 / 40.00 MB
VG UUID is2u3L-G9F1-Bnrc-9rPM-1DFm-WDSD-wLog9u
[root@localhost ~]# lvdisplay /dev/mapper/jiajiavg-lvjiajia
--- Logical volume ---
LV Name /dev/jiajiavg/lvjiajia
VG Name jiajiavg
LV UUID ECAEFu-Pyr3-wkEI-27AE-lYXp-xIWk-1WVI5x
LV Write Access read/write
LV Status available
# open 1
LV Size 152.00 MB
Current LE 38
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
[root@localhost ~]# umount /jiajia/ ---先卸载LV所对应的挂在目录
[root@localhost ~]# lvremove /dev/mapper/jiajiavg-lvjiajia ---删除LV
Do you really want to remove active logical volume "lvjiajia"? [y/n]: y
Logical volume "lvjiajia" successfully removed
[root@localhost ~]# vgchange -a n jiajiavg ---将VG停止作用
0 logical volume(s) in volume group "jiajiavg" now active
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv
5.8G 3.1G 2.4G 57% /
/dev/sda1 145M 14M 124M 10% /boot
none 125M 0 125M 0% /dev/shm
/dev/mapper/rootvg-homelv
465M 11M 431M 3% /home
[root@localhost ~]# vgremove jiajiavg
Volume group "jiajiavg" successfully removed
[root@localhost ~]# vgdisplay jiajiavg ---检查该VG是否还存在
Volume group "jiajiavg" not found
选择在第七步骤删除VG jiajiavg后遗留下的物理卷sda6
检查卷组rootvg明显增大了,还剩下896MB
[root@localhost ~]# vgdisplay rootvg
--- Volume group ---
VG Name rootvg
System ID
Format lvm2
Metadata Areas 5
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 5
Act PV 5
VG Size 7.66 GB
PE Size 32.00 MB
Total PE 245
Alloc PE / Size 217 / 6.78 GB
Free PE / Size 28 / 896.00 MB
VG UUID C50uYl-cDF5-03Ie-0Bwh-ucbi-oOpo-Odlmq9
2、若系统是REDHAT 3,则扩容的时候需要先卸载挂在目录,举例如下
umount /jiajia
e2fsadm -L +200M /dev/jiajiavg/jiajiavg-lvjiajia
mount /dev/jiajiavg/jiajiavg-lvjiajia /jiajia
3、若系统是REDHAT 3,则在完成fdisk /dev/sda物理分区后需要reboot系统
[root@localhost ~]# umount /jiajia/
[root@localhost ~]# lvremove /dev/mapper/jiajiavg-lvjiajia
[root@localhost ~]# vgchange -a n jiajiavg
[root@localhost ~]# vgdisplay jiajiavg
[root@localhost ~]# fdisk /dev/sda
。。。
Last cylinder or +size or +sizeM or +sizeK (1001-1044, default 1044): +200M
。。。
Hex code (type L to list codes): 8e
[root@localhost ~]# vgdisplay rootvg
[root@localhost ~]# partprobe
[root@localhost ~]# pvcreate /dev/sda7
[root@localhost ~]# vgextend rootvg /dev/sda7
[root@localhost ~]# vgdisplay rootvg
[root@localhost ~]# fdisk /dev/sda
。。。
Last cylinder or +size or +sizeM or +sizeK (976-1044, default 1044): +200M
。。。
Hex code (type L to list codes): 8e
[root@localhost ~]# partprobe
[root@localhost ~]# pvcreate /dev/sda6
[root@localhost ~]# vgcreate jiajiavg /dev/sda6
[root@localhost ~]# lvcreate -L 150M -n lvjiajia jiajiavg 从卷组的200M中挖出150M给LV
[root@localhost ~]# mke2fs -j /dev/jiajiavg/lvjiajia
[root@localhost ~]# mkdir /jiajia
[root@localhost ~]# mount /dev/jiajiavg/lvjiajia /jiajia/
[root@localhost ~]# df -h
[root@localhost /]# lvextend -L +500M /dev/mapper/rootvg-rootlv
[root@localhost /]# ext2online /dev/mapper/rootvg-rootlv