45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:分区大小调整的方法

分区大小调整的方法

2016-08-29 12:46:50 来源:www.45fan.com 【

分区大小调整的方法

摘要
本文以一个例子介绍调整分区大小的完整过程。(2004-03-2516:59:41)

--------------------------------------------------------------------------------
By泛舟


环境

服务器安装有一个60G的硬盘,目前已经划分为/、/home、/chroot和/swap,详细的分区信息如何下所示:


Command(mforhelp):p

Disk/dev/hda:61.4GB,61492838400bytes
255heads,63sectors/track,7476cylinders
Units=cylindersof16065*512=8225280bytes

DeviceBootStartEndBlocksIdSystem
/dev/hda1*1915734970683Linux
/dev/hda291614144008217+83Linux
/dev/hda314157476486930155Extended
/dev/hda51415147750601682Linuxswap
/dev/hda6147874764818693683Linux



然后现在希望从/home分区里面分出大约4GB的空间用于安装FreeBSD。

过程

首先,我们需要调整文件系统的大小(注意是文件系统,而不是分区的大小),然后对调整完毕的文件系统进行检查,然后再进一步调整分区的大校

文章以我自己用的系统为例子,实际操作时根据情况调整即可。

用惯了传统调整硬盘工具的人可能会认为文件系统和硬盘的分区之间是统一的,实际上他们之间并不是完整的整体(这也就是为什么BSD可以在一个硬盘分区里面制作多个文件系统分区)。想像一下带有移动式书架的书橱。你可以通过移动式书架调整书橱里面书籍的位置。把书当成文件系统,你可以在书橱里面放满书籍,也可以通过移动式书架调整书橱的空间。当然也可以通过书架调整书橱里面书籍存放的位置。如下图所示:


|<--hda1------>|<--hda2------>|
+---------------+---------------+
|XXXXXXXXXXXXXXX|XXXXXXXXXX||
|XXXXXXXXXXXXXXX|XXXXXXXXXX||
+---------------+---------------+



硬盘分区/dev/hda1中的文件系统占满了整个分区,而/dev/hda2中的文件系统只占用了2/3左右的分区。

基本的原理就是这样,现在让我们开始调整/dev/hda6中文件系统的大小:


[root@ringmailroot]#umount/home
[root@ringmailroot]#resize_reiserfs-s43000M/dev/hda6

<-------------resize_reiserfs,2002------------->
reiserfsprogs3.6.4

YouarerunningBETAversionofreiserfsshrinker.
ThisversionisonlyfortestingorVERYCAREFULuse.
Backupofyoudataisrecommended.

Doyouwanttocontinue?[y/N]:y
Processingthetree:0%
....20%....40%....60%....80%....100%left0,301020/sec

nodesprocessed(moved):
int56(0),
leaves8124(0),
unfm6313240(0),
total6321420(0).

checkforusedblocksintruncatedregion

ReiserFSreport:
blocksize4096
blockcount11008000(12046734)
freeblocks4678034(5716736)
bitmapblockcount336(368)

Syncing..done



由于/home原来的大小是47057,而我们希望在/home里面划分4G的空间出来,取整数/home的目标大小就是43000。所以在resize_reiserfs时为-s提供大小为43000M。

这样我们就已经完成了文件系统大小调整的工作,下面让我们计算一下目标分区的大小,这个大小需要根据你的fdisk里面的Units值来计算,因为硬盘分区都是按照柱面来划分的,基本的计算方法为:43000*1024*1024/8225280=5481.7304699657640834111422346716,然后我们取最接近的值5482+1478=6960来作为分区结束的柱号,这里面的1478是/home分区开始的柱面号,在前面的fdisk里面可以看到。

调整完文件系统的大小以后,再使用以下命令以文件系统进行全面的检查:


[root@ringmailroot]#reiserfsck--check--fix-fixable/dev/hda6



现在我们已经完成文件系统的大小调整工作,但是硬盘分区的大小仍然没有调整,还是跟先前一样大(可以想像我们从书橱里面拿走了几本书,而书架的大小并没有调整,依然占用着原来的空间)。

现在我们要开始进行整个操作里面最危险的操作:如果没有必要的话,最好不要进行下去:-D,不过不必过于担心,按照以下操作进行即可。

启动fdisk,并按照以下步骤进行:


[root@ringmailroot]#fdisk/dev/hda

Thenumberofcylindersforthisdiskissetto7476.
Thereisnothingwrongwiththat,butthisislargerthan1024,
andcouldincertainsetupscauseproblemswith:
1)softwarethatrunsatboottime(e.g.,oldversionsofLILO)
2)bootingandpartitioningsoftwarefromotherOSs
(e.g.,DOSFDISK,OS/2FDISK)

Command(mforhelp):p

Disk/dev/hda:61.4GB,61492838400bytes
255heads,63sectors/track,7476cylinders
Units=cylindersof16065*512=8225280bytes

DeviceBootStartEndBlocksIdSystem
/dev/hda1*1915734970683Linux
/dev/hda291614144008217+83Linux
/dev/hda314157476486930155Extended
/dev/hda51415147750601682Linuxswap
/dev/hda6147874764818693683Linux

Command(mforhelp):d
Partitionnumber(1-6):6

Command(mforhelp):n
Commandaction
llogical(5orover)
pprimarypartition(1-4)
l
Firstcylinder(1478-7476,default1478):1478
Lastcylinderor+sizeor+sizeMor+sizeK(1478-7476,default7476):6960

Command(mforhelp):p

Disk/dev/hda:61.4GB,61492838400bytes
255heads,63sectors/track,7476cylinders
Units=cylindersof16065*512=8225280bytes

DeviceBootStartEndBlocksIdSystem
/dev/hda1*1915734970683Linux
/dev/hda291614144008217+83Linux
/dev/hda314157476486930155Extended
/dev/hda51415147750601682Linuxswap
/dev/hda6147869604404216683Linux

Command(mforhelp):w
Thepartitiontablehasbeenaltered!

Callingioctl()tore-readpartitiontable.

WARNING:Re-readingthepartitiontablefailedwitherror16:Deviceorresource
busy.
Thekernelstillusestheoldtable.
Thenewtablewillbeusedatthenextreboot.
Syncingdisks.



这里需要说明的是,由于内核仍然使用旧的分区表,我需要通过重新启动才可以刷新刚制作的分区信息,所以在进行完重划分区操作以后,我对系统进行了重新启操作。系统重启后再继续后续的操作过程。

通过以上步骤,我们已经完成了硬盘分区大小调整的操作,接下来回到重新调整文件系统大小的问题上来。由于硬盘分区是按照柱面来计划的,我们要在resize_reiserfs步骤上就一步到位调整文件系统大小与硬盘分区大小正好相等是比较困难的事情。所以一般是调硬盘分区比文件系统要大一点点,然后再通过以下命令进行同步(当然如果你不在意硬盘分区里面存在部分空间的话也可以忽略以下步骤):


[root@ringmailroot]#umount/home/
[root@ringmailroot]#resize_reiserfs/dev/hda6

<-------------resize_reiserfs,2002------------->
reiserfsprogs3.6.4

ReiserFSreport:
blocksize4096
blockcount11010541(11008000)
freeblocks4680574(4678034)
bitmapblockcount337(336)

Syncing..done



完成以后原有分区的大小调整操作已经结束,接下来需要创建新分区:


[root@ringmailroot]#fdisk/dev/hda

Thenumberofcylindersforthisdiskissetto7476.
Thereisnothingwrongwiththat,butthisislargerthan1024,
andcouldincertainsetupscauseproblemswith:
1)softwarethatrunsatboottime(e.g.,oldversionsofLILO)
2)bootingandpartitioningsoftwarefromotherOSs
(e.g.,DOSFDISK,OS/2FDISK)

Command(mforhelp):p

Disk/dev/hda:61.4GB,61492838400bytes
255heads,63sectors/track,7476cylinders
Units=cylindersof16065*512=8225280bytes

DeviceBootStartEndBlocksIdSystem
/dev/hda1*1915734970683Linux
/dev/hda291614144008217+83Linux
/dev/hda314157476486930155Extended
/dev/hda51415147750601682Linuxswap
/dev/hda6147869604404216683Linux

Command(mforhelp):n
Commandaction
llogical(5orover)
pprimarypartition(1-4)
l
Firstcylinder(6961-7476,default6961):
Usingdefaultvalue6961
Lastcylinderor+sizeor+sizeMor+sizeK(6961-7476,default7476):
Usingdefaultvalue7476

Command(mforhelp):t
Partitionnumber(1-7):7
Hexcode(typeLtolistcodes):a5
Changedsystemtypeofpartition7toa5(FreeBSD)

Command(mforhelp):p

Disk/dev/hda:61.4GB,61492838400bytes
255heads,63sectors/track,7476cylinders
Units=cylindersof16065*512=8225280bytes

DeviceBootStartEndBlocksIdSystem
/dev/hda1*1915734970683Linux
/dev/hda291614144008217+83Linux
/dev/hda314157476486930155Extended
/dev/hda51415147750601682Linuxswap
/dev/hda6147869604404216683Linux
/dev/hda7696174764144738+a5FreeBSD

Command(mforhelp):w
Thepartitiontablehasbeenaltered!

Callingioctl()tore-readpartitiontable.

WARNING:Re-readingthepartitiontablefailedwitherror16:Deviceorresource
busy.
Thekernelstillusestheoldtable.
Thenewtablewillbeusedatthenextreboot.
Syncingdisks.



至此,整个调整分区大小及创建新分区的操作全部完成
 

本文地址:http://www.45fan.com/a/question/69270.html
Tags: 完全 调整 大小
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部