首先说明一下情况,在VmWare上建立了一个Linux 虚拟机,当时硬盘只分配了20G用着用着发现硬盘不够了需要扩展。
1.在VMware中将硬盘扩展到40G(这个鼠标点点就好了) 2.输入fdisk /dev/sda看看硬盘有没有变大
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 5221.
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)
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): p
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
这里我们发现一共有5221cylinders,可是结束却在2610cylinders,这说明硬盘有空余,说明硬盘扩展成功。
3.新建分区
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 5221.
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)
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 //问你是主分区还是扩展分区,我们输入p代表主分区
e extended
p primary partition (1-4)
p
Partition number (1-4): 3 //问你是第几个分区,我这里前面有两个分区了,输入3表示建立第三个分区
First cylinder (2611-5221, default 2611): //问你分区从哪个cylinder开始,保持默认
Using default value 2611
Last cylinder or +size or +sizeM or +sizeK (2611-5221, default 5221):
Using default value 5221 //问你分区在哪个cylinder结束,我们输入回车,表示硬盘的最后一个cylinder
Command action //问你是主分区还是扩展分区,我们输入p代表主分区
e extended
p primary partition (1-4)
p
Partition number (1-4): 3 //问你是第几个分区,我这里前面有两个分区了,输入3表示建立第三个分区
First cylinder (2611-5221, default 2611): //问你分区从哪个cylinder开始,保持默认
Using default value 2611
Last cylinder or +size or +sizeM or +sizeK (2611-5221, default 5221):
Using default value 5221 //问你分区在哪个cylinder结束,我们输入回车,表示硬盘的最后一个cylinder
Command (m for help): t //输入t我们修改刚刚建立的分区格式
Partition number (1-4): 3 //问我们改哪个分区,输入3改第三个
Hex code (type L to list codes): 8e //改成什么格式的,输入8e,表示Linux LVM格式
Changed system type of partition 3 to 8e (Linux LVM)
Partition number (1-4): 3 //问我们改哪个分区,输入3改第三个
Hex code (type L to list codes): 8e //改成什么格式的,输入8e,表示Linux LVM格式
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): p //输入p查看修改以后的状态
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
/dev/sda3 2611 5221 20972857+ 8e Linux LVM
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
/dev/sda3 2611 5221 20972857+ 8e Linux LVM
Command (m for help): w //输入w保存,这里可能要求重启
4.对新建的分区格式化,输入#mkfs.ext3 /dev/sda3
[root@localhost ~]# mkfs.ext3 /dev/sda3
mke2fs 1.39 (29-May-2006)
warning: 334 blocks unused.
mke2fs 1.39 (29-May-2006)
warning: 334 blocks unused.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2626560 inodes, 5242880 blocks
262160 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16416 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2626560 inodes, 5242880 blocks
262160 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16416 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
5.创建一个PV,输入#pvcreate /dev/sda3
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
6.将建立好的PV加入到现有的VG中,输入#vgextend VolGroup00 /dev/sda3 (注意这里第二个参数为VG的名字)
Physical volume "/dev/sda3" successfully created
[root@localhost ~]# vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended
7.扩展LV,输入#lvextend -L +20G /dev/VolGroup00/LogVol00
Volume group "VolGroup00" successfully extended
[root@localhost ~]# lvextend -L +20G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 35.94 GB
Logical volume LogVol00 successfully resized
8.从新识别一下LV的容量,输入#resize2fs /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 35.94 GB
Logical volume LogVol00 successfully resized
[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 9420800 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 9420800 blocks long.
9.至此扩展就已经成功了,你可以输入df -l查看新的容量
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 9420800 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 9420800 blocks long.
[root@localhost ~]# df -l
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
36505664 15045120 19579916 44% /
/dev/sda1 101086 12097 83770 13% /boot
tmpfs 1037748 0 1037748 0% /dev/shm
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
36505664 15045120 19579916 44% /
/dev/sda1 101086 12097 83770 13% /boot
tmpfs 1037748 0 1037748 0% /dev/shm