为VMware Linux添加虚拟硬盘
场景:VMware安装linux的时候默认分配的空间是4GB,可能会不够,这个时候可以通过增加一块虚拟硬盘,将/usr或其他内容拷贝过去解决这个问题:
创建虚拟硬盘
1、关闭VM中正在运行的虚拟系统;
2、在虚拟系统名称上点右键->VirtualMachineSettings;
3、在Hardware页点“Add”->Addaharddisk->Createanewvirtualdisk->SCSI(recommended)->分配空间大小->OK;
4、可以看见Hardware中出现了一块新的硬盘HardDisk2。
对虚拟硬盘进行分区和格式化
-------------------------------------------------------------------------------
##查看目前系统上有几块硬盘
[root@zhou-desktop~]#fdisk-l
Disk/dev/hda:10.7GB,10737418240bytes
255heads,63sectors/track,1305cylinders
Units=cylindersof16065*512=8225280bytes
DeviceBootStartEndBlocksIdSystem
/dev/hda1*1321305943015583Linux
/dev/hda21131105222682Linuxswap/Solaris
Partitiontableentriesarenotindiskorder
Disk/dev/hdb:10.7GB,10737418240bytes
15heads,63sectors/track,22192cylinders
Units=cylindersof945*512=483840bytes
Disk/dev/hdbdoesn'tcontainavalidpartitiontable
-------------------------------------------------------------------------------
对/dev/hdb分区进行分区
[root@zhou-desktop~]#fdisk/dev/hdb
DevicecontainsneitheravalidDOSpartitiontable,norSun,SGIorOSFdisklabel
BuildinganewDOSdisklabel.Changeswillremaininmemoryonly,
untilyoudecidetowritethem.Afterthat,ofcourse,theprevious
contentwon'tberecoverable.
Thenumberofcylindersforthisdiskissetto22192.
Thereisnothingwrongwiththat,butthisislargerthan1024,
andcouldincertainsetupscauseproblemswith:
1)softwarethatrunsatboottime(e.g.,oldversionsofLILO)
2)bootingandpartitioningsoftwarefromotherOSs
(e.g.,DOSFDISK,OS/2FDISK)
Warning:invalidflag0x0000ofpartitiontable4willbecorrectedbyw(rite)
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):p##打印出目前该硬盘下的分区列表
Disk/dev/hdb:10.7GB,10737418240bytes
15heads,63sectors/track,22192cylinders
Units=cylindersof945*512=483840bytes
DeviceBootStartEndBlocksIdSystem
Command(mforhelp):n##增加一个分区
Commandaction
eextended
pprimarypartition(1-4)
p##通常选择主分区,所以这里选p
Partitionnumber(1-4):1##第一个分区,选1;第二个分区,选2,依次类推
Firstcylinder(1-22192,default1):##默认值,回车
Usingdefaultvalue1
Lastcylinderor+sizeor+sizeMor+sizeK(1-22192,default22192):
##如果要分区10G,这里可以直接输入:+10240M,因为这里要全部使用硬盘空间,则用默认
Usingdefaultvalue22192
Command(mforhelp):p
Disk/dev/hdb:10.7GB,10737418240bytes
15heads,63sectors/track,22192cylinders
Units=cylindersof945*512=483840bytes
DeviceBootStartEndBlocksIdSystem
/dev/hdb112219210485688+83Linux
##第一个分区已经分好了,接下来把这个分区写入硬盘,用w
Command(mforhelp):w
Thepartitiontablehasbeenaltered!
Callingioctl()tore-readpartitiontable.
Syncingdisks.
##下面的工作就是对该硬盘进行格式,格式化成ext3
[root@zhou-desktop~]#mkfs.ext3/dev/hdb1
mke2fs1.39(29-May-2006)
Filesystemlabel=
OStype:Linux
Blocksize=4096(log=2)
Fragmentsize=4096(log=2)
1310720inodes,2621422blocks
131071blocks(5.00%)reservedforthesuperuser
Firstdatablock=0
Maximumfilesystemblocks=2684354560
80blockgroups
32768blockspergroup,32768fragmentspergroup
16384inodespergroup
Superblockbackupsstoredonblocks:
32768,98304,163840,229376,294912,819200,884736,1605632
Writinginodetables:done
Creatingjournal(32768blocks):done
Writingsuperblocksandfilesystemaccountinginformation:done
Thisfilesystemwillbeautomaticallycheckedevery37mountsor
180days,whichevercomesfirst.Usetune2fs-cor-itooverride.
##检查一下,是否已经格式好
[root@zhou-desktop~]#fdisk-l
Disk/dev/hda:10.7GB,10737418240bytes
255heads,63sectors/track,1305cylinders
Units=cylindersof16065*512=8225280bytes
DeviceBootStartEndBlocksIdSystem
/dev/hda1*1321305943015583Linux
/dev/hda21131105222682Linuxswap/Solaris
Partitiontableentriesarenotindiskorder
Disk/dev/hdb:10.7GB,10737418240bytes
15heads,63sectors/track,22192cylinders
Units=cylindersof945*512=483840bytes
DeviceBootStartEndBlocksIdSystem
/dev/hdb112219210485688+83Linux
[root@zhou-desktop~]#
##挂载虚拟硬盘
把/dev/hdb1挂载到/mnt/ext下
[root@zhou-desktop~]#mount/dev/hdb1/mnt/ext
##重启系统之后,再挂载看是否成功
[root@zhou-desktopmnt]#df-lh
文件系统容量已用可用已用%挂载点
/dev/hda18.8G2.7G5.6G33%/
tmpfs252M0252M0%/dev/shm
/dev/hdb19.9G151M9.2G2%/mnt/ext
##转移数据
1、/usr中的全部数据
2、清空usr目录:
#rm-r/usr
#mkdir/usr
3、卸载刚才挂上的虚拟硬盘,重新将它挂载到usr目录:
#umount/mnt/ext
#mount/dev/hdb1/usr
4、##用vi修改/etc/fstab,使系统启动就可以自动挂载
#vim/etc/fstab
在内容中加上一行:
/dev/sdb1/usrext3defaults12
5、Ok,重新启动之后,可以查看现在的硬盘使用情况了:
[root@zhou-desktopmnt]#df-lh
文件系统容量已用可用已用%挂载点
/dev/hda18.8G2.7G5.6G33%/
tmpfs252M0252M0%/dev/shm
/dev/hdb19.9G151M9.2G2%/usr