linux fdisk 分区

关于硬盘分区:主分区(包含扩展分区)、逻辑分区,主分区最多有4个(包含扩展分区)。

因此我们在对硬盘分区时最好划分主分区连续,比如说:主分区一、主分区二、扩展分区。

此文章以fdisk工具为例,对一个硬盘划分。

1、fdisk-l查看系统上的硬盘,找到需要分区的硬盘后比如说:/dev/sdb.

然后,fdisk/dev/sdb

进入该设备。此时出现:

Command(mforhelp):

查看帮助信息:输入m,看到如下信息

Commandactionatoggleabootableflagbeditbsddisklabelctogglethedoscompatibilityflagddeleteapartition注:这是删除一个分区的动作;llistknownpartitiontypes注:l是列出分区类型,以供我们设置相应分区的类型;mprintthismenu注:m是列出帮助信息;naddanewpartition注:添加一个分区;ocreateanewemptyDOSpartitiontablepprintthepartitiontable注:p列出分区表;qquitwithoutsavingchanges注:不保存退出;screateanewemptySundisklabeltchangeapartition’ssystemid注:t改变分区类型;uchangedisplay/entryunitsvverifythepartitiontablewwritetabletodiskandexit注:把分区表写入硬盘并退出;xextrafunctionality(expertsonly)注:扩展应用,专家功能;

具体每个参数的含义,请仔细阅读。常用的就是:dlmpqtw

2、列出当前操作硬盘的分区情况,用p

Command(mforhelp):p

Disk/dev/sda:1035MB,1035730944bytes256heads,63sectors/track,125cylindersUnits=cylindersof16128*512=8257536bytes

DeviceBootStartEndBlocksIdSystem/dev/sda1125201568+cW95FAT32(LBA)/dev/sda2261258064005Extended/dev/sda52650201568+83Linux/dev/sda6517620078183Linux

3、通过fdisk的d指令来删除一个分区

Command(mforhelp):p注:列出分区情况;

Disk/dev/sda:1035MB,1035730944bytes256heads,63sectors/track,125cylindersUnits=cylindersof16128*512=8257536bytes

DeviceBootStartEndBlocksIdSystem/dev/sda1125201568+cW95FAT32(LBA)/dev/sda2261258064005Extended

/dev/sda52650201568+83Linux/dev/sda6517620078183Linux

Command(mforhelp):d注:执行删除分区指定;Partitionnumber(1-6):6注:我想删除sda6,就在这里输入6;

Command(mforhelp):p注:再查看一下硬盘分区情况,看是否删除了?

Disk/dev/sda:1035MB,1035730944bytes256heads,63sectors/track,125cylindersUnits=cylindersof16128*512=8257536bytes

DeviceBootStartEndBlocksIdSystem/dev/sda1125201568+cW95FAT32(LBA)/dev/sda2261258064005Extended/dev/sda52650201568+83Linux

Command(mforhelp):警告:删除分区时要小心,请看好分区的序号,如果您删除了扩展分区,扩展分区之下的逻辑分区都会删除;所以操作时一定要小心;如果知道自己操作错了,请不要惊慌,用q不保存退出;切记切记!!!!在分区操作错了之时,千万不要输入w保存退出!!!

4、通过fdisk的n指令增加一个分区

Command(mforhelp):p

Disk/dev/sda:1035MB,1035730944bytes256heads,63sectors/track,125cylindersUnits=cylindersof16128*512=8257536bytes

DeviceBootStartEndBlocksIdSystem/dev/sda1125201568+cW95FAT32(LBA)/dev/sda2261258064005Extended/dev/sda52650201568+83Linux

Command(mforhelp):n注:增加一个分区;Commandactionllogical(5orover)注:增加逻辑分区,分区编号要大于5;为什么要大于5,因为已经有sda5了;pprimarypartition(1-4)注:增加一个主分区;编号从1-4;但sda1和sda2都被占用,所以只能从3开始;pPartitionnumber(1-4):3Nofreesectorsavailable注:失败中,为什么失败?注:我试图增加一个主分区,看来是失败了,为什么失败?因为我们看到主分区+扩展分区把整个磁盘都用光了,看扩展分区的End的值,再看一下p输出信息中有125cylinders;最好还是看前面部份;那里有提到;所以我们只能增加逻辑分区了;Command(mforhelp):nCommandactionllogical(5orover)pprimarypartition(1-4)l注:在这里输入l,就进入划分逻辑分区阶段了;Firstcylinder(51-125,default51):注:这个就是分区的Start值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费;Usingdefaultvalue51Lastcylinderor+sizeor+sizeMor+sizeK(51-125,default125):+200M注:这个是定义分区大小的,+200M就是大小为200M;当然您也可以根据p提示的单位cylinder的大小来算,然后来指定End的数值。回头看看是怎么算的;还是用+200M这个办法来添加,这样能直观一点。如果您想添加一个10G左右大小的分区,请输入+10000M;

Command(mforhelp):

5、通过fdisk的t指令指定分区类型

Command(mforhelp):t注:通过t来指定分区类型;Partitionnumber(1-6):6注:要改变哪个分区类型呢?我指定了6,其实也就是sda6Hexcode(typeLtolistcodes):L注:在这里输入L,就可以查看分区类型的id了;Hexcode(typeLtolistcodes):b注:如果我想让这个分区是W95FAT32类型的,通过L查看得知b是表示的是,所以输入了b;Changedsystemtypeofpartition6tob(W95FAT32)注:系统信息,改变成功;是否是改变了,请用p查看;

Command(mforhelp):p

Disk/dev/sda:1035MB,1035730944bytes256heads,63sectors/track,125cylindersUnits=cylindersof16128*512=8257536bytes

DeviceBootStartEndBlocksIdSystem/dev/sda1125201568+cW95FAT32(LBA)/dev/sda2261258064005Extended/dev/sda52650201568+83Linux/dev/sda65175201568+bW95FAT32

6、fdisk的退出,用q或者w

其中q是不保存退出,w是保存退出

7、一个添加分区的例子

本例中我们会添加两个200M的主分区,其它为扩展分区,在扩展分区中我们添加两个200M大小的逻辑分区;Command(mforhelp):p注:列出分区表;

Disk/dev/sda:1035MB,1035730944bytes256heads,63sectors/track,125cylindersUnits=cylindersof16128*512=8257536bytes

DeviceBootStartEndBlocksIdSystem

Command(mforhelp):n注:添加分区;Commandactioneextendedpprimarypartition(1-4)p注:添加主分区;Partitionnumber(1-4):1注:添加主分区1;Firstcylinder(1-125,default1):注:直接回车,主分区1的起始位置;默认为1,默认就好;Usingdefaultvalue1Lastcylinderor+sizeor+sizeMor+sizeK(1-125,default125):+200M注:指定分区大小,用+200M来指定大小为200M

Command(mforhelp):n注:添加新分区;Commandactioneextendedpprimarypartition(1-4)p注:添加主分区Partitionnumber(1-4):2注:添加主分区2;Firstcylinder(26-125,default26):Usingdefaultvalue26Lastcylinderor+sizeor+sizeMor+sizeK(26-125,default125):+200M注:指定分区大小,用+200M来指定大小为200M

Command(mforhelp):nCommandactioneextendedpprimarypartition(1-4)e注:添加扩展分区;Partitionnumber(1-4):3注:指定为3,因为主分区已经分了两个了,这个也算主分区,从3开始;Firstcylinder(51-125,default51):注:直接回车;Usingdefaultvalue51Lastcylinderor+sizeor+sizeMor+sizeK(51-125,default125):注:直接回车,把其余的所有空间都给扩展分区;Usingdefaultvalue125

Command(mforhelp):p

Disk/dev/sda:1035MB,1035730944bytes256heads,63sectors/track,125cylindersUnits=cylindersof16128*512=8257536bytes

DeviceBootStartEndBlocksIdSystem/dev/sda1125201568+83Linux/dev/sda2265020160083Linux/dev/sda3511256048005Extended

Command(mforhelp):nCommandactionllogical(5orover)pprimarypartition(1-4)l注:添加逻辑分区;Firstcylinder(51-125,default51):Usingdefaultvalue51Lastcylinderor+sizeor+sizeMor+sizeK(51-125,default125):+200M注:添加一个大小为200M大小的分区;

Command(mforhelp):nCommandactionllogical(5orover)pprimarypartition(1-4)l注:添加一个逻辑分区;Firstcylinder(76-125,default76):Usingdefaultvalue76Lastcylinderor+sizeor+sizeMor+sizeK(76-125,default125):+200M注:添加一个大小为200M大小的分区;

Command(mforhelp):p列出分区表;

Disk/dev/sda:1035MB,1035730944bytes256heads,63sectors/track,125cylindersUnits=cylindersof16128*512=8257536bytes

DeviceBootStartEndBlocksIdSystem/dev/sda1125201568+83Linux/dev/sda2265020160083Linux/dev/sda3511256048005Extended/dev/sda55175201568+83Linux/dev/sda676100201568+83Linux然后我们根据前面所说通过t指令来改变分区类型;最后不要忘记w保存退出;

如果是系统所在盘会提示重启,重启就OK了。接下来进行第5步

五、对分区进行格式化,以及加载;先提示一下;用mkfs.bfsmkfs.ext2mkfs.jfsmkfs.msdosmkfs.vfatmkfs.cramfsmkfs.ext3mkfs.minixmkfs.reiserfsmkfs.xfs等命令来格式化分区,比如我想格式化sda6为ext3文件系统,则输入;[root@localhostbeinan]#mkfs-text3-c/dev/sda6具体参数含义,请manmkfs。

如果我想加载sda6到目前系统来存取文件,应该有mount命令,但首先您得建一个挂载目录;比如/mnt/sda6;[root@localhostbeinan]#mkdir/mnt/sda6[root@localhostbeinan]#mount/dev/sda6/mnt/sda6[root@localhostbeinan]#df-lhFilesystem容量已用可用已用%挂载点/dev/hda811G8.4G2.0G81%//dev/shm236M0236M0%/dev/shm/dev/hda1016G6.9G8.3G46%/mnt/hda10/dev/sda6191M5.6M176M4%/mnt/sda6

  8,自动挂载分区

当在系统里创建了一个新的分区后,因为mount挂载在重启服务后会失效,所以需要将分区信息写到/etc/fstab文件中让其永久挂载,编辑/etc/fstab里加入:输入红色内容/dev/sdb1(磁盘分区)/home(mount目录)ext3(文件格式)defaults00保存退出,重启后/dev/sdb1就会自动挂载到/mnt/abc目录下

选择逃避,选择被动的去面对生活

linux fdisk 分区

相关文章:

你感兴趣的文章:

标签云: