fdisk -l
先分区
[root@test ~]# fdisk /dev/sdb[田兴1]
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9dbb2440.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p[田兴2]
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9dbb2440
Device Boot Start End Blocks Id System
Command (m for help): n[田兴3]
Command action
e extended
p primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-1305, default 1): 1[田兴5]
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): [田兴6]
Using default value 1305
Command (m for help): t[田兴7]
Selected partition 1[田兴8]
Hex code (type L to list codes): 8e[田兴9]
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w[田兴10]
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@MSJTVL-FHJF-A10 sm01]# partx -a /dev/sdb[田兴11]
[root@test ~]# mkfs.ext3 /dev/sdb1[田兴12] [田兴13]
[root@test ~]# lvm[田兴14]
lvm> pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created[田兴15]
lvm> pvs[田兴16]
PV VG Fmt Attr PSize PFree
/dev/sda5 vgsystem lvm2 a-- 21.88g 6.88g
/dev/sdb1 lvm2 --- 10.00g 10.00g
lvm> vgcreate vghadoop /dev/sdb1
Volume group "vghadoop" successfully created[田兴17]
lvm> lvcreate -n lv_hadoop -L 9.9G vghadoop
Rounding up size to full physical extent 9.90 GiB
Logical volume "lv_hadoop" created.[田兴18]
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name vghadoop
PV Size 10.00 GiB / not usable 4.70 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2558
Free PE 23
Allocated PE 2535
PV UUID l7d6Tb-7EaU-aLY3-ykvu-k0HK-pUeE-rHbH5r
--- Physical volume ---
PV Name /dev/sda5
VG Name vgsystem
PV Size 21.88 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 5601
Free PE 1761
Allocated PE 3840
PV UUID xFXJd2-clwW-lH7C-Axs9-UHGu-OkHP-J0hn7d
[root@test ~]# mkfs.ext3 /dev/vghadoop/lv_hadoop [田兴19]
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
648960 inodes, 2595840 blocks
129792 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2659188736
80 block groups
32768 blocks per group, 32768 fragments per group
8112 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@test ~]# mount /dev/vghadoop/lv_hadoop /hadoop[田兴20]
[root@test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.9G 2.1G 7.4G 22% /
tmpfs 935M 0 935M 0% /dev/shm
/dev/sda1 117M 44M 67M 40% /boot
/dev/mapper/vgsystem-lv_opt
9.9G 151M 9.2G 2% /opt
/dev/mapper/vgsystem-lv_tmp
5.0G 139M 4.6G 3% /tmp
/dev/mapper/vghadoop-lv_hadoop
9.8G 151M 9.2G 2% /Hadoop
解决CentOS重启后就挂载就没有了
在/etc/fstab文件中增加:
/dev/mapper/vghadoop-lv_hadoop /hadoop ext3 defaults 1 0
#查看挂载点:
df -h
#显示:
文件系统
容量 已用 可用 已用%% 挂载点
/dev/mapper/vg_dc01-lv_root
47G 12G 34G 25% /
tmpfs 504M 88K 504M 1% /dev/shm
/dev/sda1 485M 31M 429M 7% /boot
一、扩展VMWare硬盘空间
关闭Vmware 的 Linux系统,这样,才能在VMWare菜单中设置:
VM -> Settings... -> Hardware -> Hard Disk -> Utilities -> Expand
输入你想要扩展到多少G。本文假设你新增加了 30G
二、对新增加的硬盘进行分区、格式化
这里进行一个极简化的介绍,非常简化,但很全面,上面已经知道增加了空间的硬盘是 /dev/sda。
分区:
fdisk /dev/sda 操作 /dev/sda 的分区表
p 查看已分区数量(我看到有两个 /dev/sda1 /dev/sda2)
n 新增加一个分区
p 分区类型我们选择为主分区
3 分区号选3(因为1,2已经用过了,见上)
回车 默认(起始扇区)
回车 默认(结束扇区)
t 修改分区类型
3 选分区3
8e 修改为LVM(8e就是LVM)
w 写分区表
q 完成,退出fdisk命令
系统提示你重启,重启吧。
开机后,格式化:
mkfs.ext3 /dev/sda3
三、添加新LVM到已有的LVM组,实现扩容
lvm 进入lvm管理
lvm> pvcreate /dev/sda3 这是初始化刚才的分区,必须的
lvm> vgextend vg_dc01 /dev/sda3 将初始化过的分区加入到虚拟卷组vg_dc01
lvm>lvextend -L +29.9G /dev/vg_dc01/lv_root 扩展已有卷的容量(29.9G这个数字在后面解释)
lvm>pvdisplay 查看卷容量,这时你会看到一个很大的卷了
lvm>quit 退出
上面那个 29.9G 怎么来的呢?因为你在VMWare新增加了30G,但这些空间不能全被LVM用了,你可以在上面的lvextend操作中一个一个的试探,比如 29.9G, 29.8G ... 直到不报错为止,这样你就可以充分使用新增加的硬盘空间了,当然这是因为我不懂才用的笨办法,高手笑笑就过了吧。(我更不懂啊,原作者,我直接上了29.9G,结果就OK了)
以上只是卷扩容了,下面是文件系统的真正扩容,输入以下命令:
resize2fs /dev/vghadoop/lv_hadoop
resize2fs /dev/mapper/vghadoop-lv_hadoop
resize2fs /dev/vg_dc01/lv_root
resize2fs /dev/mapper/vgsystem-lv_opt
现在,再运行下:df -h
Superblock超级块,对ext3数据进行相应的回复
[田兴1]分区
[田兴2]查看已分区的情况
[田兴3]新增加一个分区
[田兴4]分区选择为主分区
[田兴5]起始盘区
[田兴6]结束盘区,默认为最后一个,回车就是默认
[田兴7]修改分区类型
[田兴8]选择分区
[田兴9]修改为8e(LVM)类型的
[田兴10]写分区
[田兴11]通知内核重新分区
[田兴12]格式化
[田兴13]应该可以不格式化因为后面还需要格式化,需要确认下?
[田兴15]创建PV:将物理硬盘格式化成PV(物理券)
[田兴16]创建完PV以后,我们可以使用pvdisplay(显示详细信息)、pvs命令来查看当前pv的信息
[田兴17]创建卷组(VG),并将PV加入到卷组中。通过vgcreate命令
[田兴18]基于卷组(VG)创建逻辑卷(LV)命令lvcreate
[田兴19]格式化
[田兴20]用mount命令进行相应的挂载