secondid 2012-02-06
第一步:添加磁盘
第二步:使用Linux下的fdisk工具进行分区
用root用户登录:
打印当前的磁盘分区表,这时我们可以看到磁盘的总量的确增加到30GB 了,但是分区只有以前的那几个原有的分区[root@localhost ~]# fdisk -l
键入命令: fdisk /dev/sda “sda 就是经过扩容的硬盘,为 SCSI 硬盘, IDE 类型硬盘对应为 hda ,是对该硬盘进行操作 ”
选择主分区吧,则键入 p
此时, fdisk 会让你选择主分区的编号,如果已经有了主分区 sda1 , sda2 ,那么编号就选3 ,即要创建的该分区为 sda3. 键入: 3
此时, fdisk 又会让你选择该分区的开始值这个就是分区的 Start 值( start cylinder );这里最好直接按回车, 如果您输入了一个非默认的数字,可能会造成空间浪费;
对于分区的 End 值(end cylinder),同样直接按回车。这时候会显示出你新建分区的柱面范围和空间大小。
此时键入: w 表示" 保存所有并退出,分区划分完毕 "
[root@localhost ~]# fdisk /dev/sda
Thenumberofcylindersforthisdiskissetto3916.
Thereisnothingwrongwiththat,butthisislargerthan1024,
andcouldincertainsetupscauseproblemswith:
1)softwarethatrunsatboottime(e.g.,oldversionsofLILO)
2)bootingandpartitioningsoftwarefromotherOSs
(e.g.,DOSFDISK,OS/2FDISK)
Command(mforhelp):n
Commandaction
eextended
pprimarypartition(1-4)
p
Partitionnumber(1-4):3
Firstcylinder(1045-3916,default1045):
Usingdefaultvalue1045
Lastcylinderor+sizeor+sizeMor+sizeK(1045-3916,default3916):
Usingdefaultvalue3916
Command(mforhelp):w
Thepartitiontablehasbeenaltered!
Callingioctl()tore-readpartitiontable.
WARNING:Re-readingthepartitiontablefailedwitherror16:设备或资源忙.
Thekernelstillusestheoldtable.
Thenewtablewillbeusedatthenextreboot.
Syncing disks.我们的新建分区/dev/sda3,却不是LVM的。所以,接下来使用fdisk将其改成LVM的。
[root@CNGI-SIP6-BUPT ~]# fdisk /dev/sda
Command(mforhelp):m
Command(mforhelp):t//改变分区系统id
Partitionnumber(1-4):3//指定分区号
Hexcode(typeLtolistcodes):8e//指定要改成的id号,8e代表LVM。
Command (m for help): w[root@localhost ~]# fdisk /dev/sda
Thenumberofcylindersforthisdiskissetto3916.
Thereisnothingwrongwiththat,butthisislargerthan1024,
andcouldincertainsetupscauseproblemswith:
1)softwarethatrunsatboottime(e.g.,oldversionsofLILO)
2)bootingandpartitioningsoftwarefromotherOSs
(e.g.,DOSFDISK,OS/2FDISK)
Command(mforhelp):m
Commandaction
atoggleabootableflag
beditbsddisklabel
ctogglethedoscompatibilityflag
ddeleteapartition
llistknownpartitiontypes
mprintthismenu
naddanewpartition
ocreateanewemptyDOSpartitiontable
pprintthepartitiontable
qquitwithoutsavingchanges
screateanewemptySundisklabel
tchangeapartition'ssystemid
uchangedisplay/entryunits
vverifythepartitiontable
wwritetabletodiskandexit
xextrafunctionality(expertsonly)
Command(mforhelp):t
Partitionnumber(1-4):3
Hexcode(typeLtolistcodes):8e
Changedsystemtypeofpartition3to8e(LinuxLVM)
Command(mforhelp):w
Thepartitiontablehasbeenaltered!
Callingioctl()tore-readpartitiontable.
WARNING:Re-readingthepartitiontablefailedwitherror16:设备或资源忙.
Thekernelstillusestheoldtable.
Thenewtablewillbeusedatthenextreboot.
Syncing disks.重新登录后:
[root@localhost~]#reboot
Broadcastmessagefromroot(pts/1)(ThuSep2209:54:452011):
ThesystemisgoingdownforrebootNOW!
[root@localhost~]#fdisk-l
Disk/dev/sda:32.2GB,32212254720bytes
255heads,63sectors/track,3916cylinders
Units=cylindersof16065*512=8225280bytes
DeviceBootStartEndBlocksIdSystem
/dev/sda1*11310439183Linux
/dev/sda21410448281507+8eLinuxLVM
/dev/sda310453916230693408eLinuxLVM
Disk/dev/sdb:6442MB,6442450944bytes
255heads,63sectors/track,783cylinders
Units=cylindersof16065*512=8225280bytes
DeviceBootStartEndBlocksIdSystem
/dev/sdb1 1 783 6289416 83 Linux第三步、格式化该新添加的分区
格式化磁盘
[root@localhost~]#mkfs-text3/dev/sda3
mke2fs1.35(28-Feb-2004)
max_blocks4294967295,rsv_groups=0,rsv_gdb=1024
max_blocks4294967295,rsv_groups=0,rsv_gdb=1024
warning:167blocksunused.
Filesystemlabel=
OStype:Linux
Blocksize=4096(log=2)
Fragmentsize=4096(log=2)
2889216inodes,5767168blocks
288366blocks(5.00%)reservedforthesuperuser
Firstdatablock=0
Maximumfilesystemblocks=8388608
176blockgroups
32768blockspergroup,32768fragmentspergroup
16416inodespergroup
Superblockbackupsstoredonblocks:
32768,98304,163840,229376,294912,819200,884736,1605632,2654208,
4096000
Writinginodetables:done
inode.i_blocks=90120,i_size=4243456
Creatingjournal(8192blocks):done
Writingsuperblocksandfilesystemaccountinginformation:done
Thisfilesystemwillbeautomaticallycheckedevery24mountsor
180 days, whichever comes first. Use tune2fs -c or -i to override.第四步、扩充根分区
[root@localhost~]#lvs
LVVGAttrLSizeOriginSnap%MoveCopy%
LogVol00VolGroup00-wi-ao5.91G
LogVol01VolGroup00-wi-ao1.94G
[root@localhost~]#pvcreate/dev/sd
sdasda1sda2sda3sdbsdb1
[root@localhost~]#pvcreate/dev/sda3
Physicalvolume"/dev/sda3"successfullycreated
[root@localhost~]#df-h
Filesystem容量已用可用已用%挂载点
/dev/mapper/VolGroup00-LogVol00
5.9G5.5G120M98%/
/dev/sda199M9.0M85M10%/boot
none506M0506M0%/dev/shm
/dev/sdb16.0G347M5.3G7%/disk2
[root@localhost~]#vgdisplay
---Volumegroup---
VGNameVolGroup00
SystemID
Formatlvm2
MetadataAreas1
MetadataSequenceNo3
VGAccessread/write
VGStatusresizable
MAXLV0
CurLV2
OpenLV2
MaxPV0
CurPV1
ActPV1
VGSize7.88GB
PESize32.00MB
TotalPE252
AllocPE/Size251/7.84GB
FreePE/Size1/32.00MB
VGUUIDHvKxmm-WazL-TjFN-yXNH-ui8U-pcl9-Pk6psB
[root@localhost~]#vgextendVolGroup00/dev/sda3
Volumegroup"VolGroup00"successfullyextended
[root@localhost~]#vgdisplay
---Volumegroup---
VGNameVolGroup00
SystemID
Formatlvm2
MetadataAreas2
MetadataSequenceNo4
VGAccessread/write
VGStatusresizable
MAXLV0
CurLV2
OpenLV2
MaxPV0
CurPV2
ActPV2
VGSize29.88GB
PESize32.00MB
TotalPE956
AllocPE/Size251/7.84GB
FreePE/Size705/22.03GB
VG UUID HvKxmm-WazL-TjFN-yXNH-ui8U-pcl9-Pk6psB#不能把 Free PE / Size 705 / 22.03 GB的空间全部加上,应该下雨22.03
[root@localhost~]#lvextend-L+22.03G/dev/VolGroup00/LogVol00/dev/sda3
Roundingupsizetofullphysicalextent22.03GB
ExtendinglogicalvolumeLogVol00to27.94GB
Insufficient allocatable logical extents (893) for logical volume LogVol00: 894 required[root@localhost~]#lvextend-L+21.03G/dev/VolGroup00/LogVol00/dev/sda3
Roundingupsizetofullphysicalextent21.03GB
ExtendinglogicalvolumeLogVol00to26.94GB
Logical volume LogVol00 successfully resized[root@localhost~]#cat/etc/fstab
#Thisfileiseditedbyfstab-sync-see'manfstab-sync'fordetails
/dev/VolGroup00/LogVol00/ext3defaults11
LABEL=/boot/bootext3defaults12
none/dev/ptsdevptsgid=5,mode=62000
none/dev/shmtmpfsdefaults00
none/procprocdefaults00
none/syssysfsdefaults00
/dev/VolGroup00/LogVol01swapswapdefaults00
/dev/sdb1/disk2ext3defaults11
/dev/hdc/media/cdromautopamconsole,exec,noauto,managed00
/dev/fd0/media/floppyautopamconsole,exec,noauto,managed00
[root@localhost~]#e2fsck-a/dev/VolGroup00/LogVol00
/dev/VolGroup00/LogVol00ismounted.
WARNING!!!Runninge2fsckonamountedfilesystemmaycause
SEVEREfilesystemdamage.
Doyoureallywanttocontinue(y/n)?yes
/dev/VolGroup00/LogVol00:recoveringjournal
/dev/VolGroup00/LogVol00:Clearingorphanedinode596983(uid=501,gid=501,mode=0100660,size=0)
/dev/VolGroup00/LogVol00:clean,144094/774144files,1440278/1548288blocks
#redhat4 没有resize2fs命令
[root@localhost~]#resize2fs
-bash: resize2fs: command not found#redhat4下用ext2online
[root@localhost~]#ext2online/dev/VolGroup00/LogVol00
ext2onlinev1.1.18-2001/03/18forEXT2FS0.5b
[root@localhost~]#df-h
Filesystem容量已用可用已用%挂载点
/dev/mapper/VolGroup00-LogVol00
27G5.5G20G22%/
/dev/sda199M9.0M85M10%/boot
none506M0506M0%/dev/shm
/dev/sdb16.0G347M5.3G7%/disk2