- 金錢
- 1528
- 威望
- 5296
- 貢獻值
- 378
- 推廣值
- 2
- 性別
- 男
- 在線時間
- 401 小時
- 最後登錄
- 2024-11-14
- 主題
- 989
- 精華
- 0
- 閱讀權限
- 90
- 註冊時間
- 2011-12-29
- 帖子
- 0
TA的每日心情 | 怒 2024-11-3 15:50 |
---|
簽到天數: 1258 天 [LV.10]以壇為家III - 推廣值
- 2
- 貢獻值
- 378
- 金錢
- 1528
- 威望
- 5296
- 主題
- 989
|
樓主
發表於 2012-9-15 20:41:22
首先说明一下情况,在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)
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
Device Boot Start End Blocks Id System
/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)
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 (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)
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
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
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.
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
Writing inode tables: 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
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
6.将建立好的PV加入到现有的VG中,输入#vgextend VolGroup00 /dev/sda3 (注意这里第二个参数为VG的名字)
[root@localhost ~]# vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended
7.扩展LV,输入#lvextend -L +20G /dev/VolGroup00/LogVol00
[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
[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查看新的容量
[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 |
|