`
cocos
  • 浏览: 394297 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

fdisk

阅读更多
[root@192_168_9_78 ~]# fdisk -l

Disk /dev/sda: 146.1 GB, 146163105792 bytes
255 heads, 63 sectors/track, 17769 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26        2636    20972857+  83  Linux
/dev/sda3            2637        5247    20972857+  83  Linux
/dev/sda4            5248       17769   100582965    5  Extended
/dev/sda5            5248        5769     4192933+  82  Linux swap / Solaris
/dev/sda6            5770        6291     4192933+  83  Linux
/dev/sda7            6292       17769    92197003+  83  Linux

Disk /dev/sdb: 898.3 GB, 898319253504 bytes
255 heads, 63 sectors/track, 109214 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      109214   877261423+  83  Linux

Disk /dev/sdc: 999.6 GB, 999653638144 bytes
255 heads, 63 sectors/track, 121534 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1      121534   976221823+  83  Linux


[root@192_168_9_78 ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 109214.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help):
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (80001-182401, default 80001):
Using default value 80001
Last cylinder or +size or +sizeM or +sizeK (80001-182401, default 182401):
Using default value 182401
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): l
0  Empty           1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot 
1  FAT12           24  NEC DOS         81  Minix / old Lin bf  Solaris      
2  XENIX root      39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
3  XENIX usr       3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
5  Extended        41  PPC PReP Boot   85  Linux extended  c7  Syrinx       
6  FAT16           42  SFS             86  NTFS volume set da  Non-FS data  
7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility 
9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt       
a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e1  DOS access   
b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O      
c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          e4  SpeedStor    
e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs      
f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  EFI GPT      
10  OPUS            55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor    
14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f4  SpeedStor    
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fd  Linux raid auto
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fe  LANstep      
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid ff  BBT          
1c  Hidden W95 FAT3 75  PC/IX        
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@NAT ~]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/sda2              19G  2.6G   16G  14% /
/dev/sda1             190M   10M  171M   6% /boot
tmpfs                 248M     0  248M   0% /dev/shm
/dev/sda7             132G   16G  110G  13% /home
/dev/sda5             9.5G  3.2G  5.9G  36% /usr
/dev/sda3              19G  4.1G   14G  23% /var
[root@NAT ~]# fdisk -l
Disk /dev/sda: 200.0 GB, 200049647616 bytes
255 heads, 63 sectors/track, 24321 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26        2575    20482875   83  Linux
/dev/sda3            2576        5125    20482875   83  Linux
/dev/sda4            5126       24321   154191870    5  Extended
/dev/sda5            5126        6400    10241406   83  Linux
/dev/sda6            6401        6655     2048256   82  Linux swap / Solaris
/dev/sda7            6656       24321   141902113+  83  Linux
Disk /dev/sdb: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       80000   642599968+  83  Linux
/dev/sdb2           80001      182401   822536032+  83  Linux
[root@NAT
[root@NAT ~]# mkfs -t ext3 -c /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
80330752 inodes, 160649992 blocks
8032499 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
4903 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000

分享到:
评论
1 楼 cocos 2011-05-12  
FDISK进行硬盘分区从实质上说就是对硬盘的一种格式化。当我们创建分区时,就已经设置好了硬盘的各项物理参数,指定了硬盘主引导记录(即MasterBootRecord,MBR)和引导记录备份的存放位置。而对于文件系统以及其他操作系统管理硬盘所需要的信息则是通过之后的高级格式化,即Format命令来实现。用一个形象的比喻,分区就好比在一张白纸上画一个大方框。而格式化好比在方框里打上格子。安装各种软件就好比在格子里写上字。分区和格式化就相当于为安装软件打基础,实际上它们为电脑在硬盘上存储数据起到标记定位的作用。


fdisk是用来磁盘分区的程序,它采用传统的问答式界面,而非类似DOS fdisk的cfdisk互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣。


通过fdisk -l 查看机器情况;

所挂硬盘个数及分区  

[root@localhost beinan]# fdisk -l  

Disk /dev/hda: 80.0 GB, 80026361856 bytes  

255 heads, 63 sectors/track, 9729 cylinders  

Units = cylinders of 16065 * 512 = 8225280 bytes  

Device Boot Start End Blocks Id System  

/dev/hda1 * 1 765 6144831 7 HPFS/NTFS  

/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)  

/dev/hda3 2806 9729 55617030 5 Extended  

/dev/hda5 2806 3825 8193118+ 83 Linux  

/dev/hda6 3826 5100 10241406 83 Linux  

/dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris  

/dev/hda8 5199 6657 11719386 83 Linux  

/dev/hda9 6658 7751 8787523+ 83 Linux  

/dev/hda10 7752 9729 15888253+ 83 Linux  

Disk /dev/sda: 1035 MB, 1035730944 bytes  

256 heads, 63 sectors/track, 125 cylinders  

Units = cylinders of 16128 * 512 = 8257536 bytes  

Device Boot Start End Blocks Id System  

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)  

/dev/sda2 26 125 806400 5 Extended  

/dev/sda5 26 50 201568+ 83 Linux  

/dev/sda6 51 76 200781 83 Linux  

通过上面的信息,我们知道此机器中挂载两个硬盘(或移动硬盘),其中一个是hda 另一个是sda ;如果我们想查看单个硬盘情况,可以通过 fdisk -l /dev/hda1 或者fdisk -l /dev/sda1 来操作;以fdisk -l 输出的硬盘标识为准;其中 hda有三个主分区(包括扩展分区),分别是主分区 hda1 hda2 和hda3(扩展分区) ;逻辑分区是 hda5到hda10;  其中 sda 有两个主分区(包括扩展分区),分别是 hda1 和hda2 (扩展分区);逻辑分区是 sda5 hda6 ;硬盘总容量=主分区(包括扩展分区)总容量



  扩展分区容量=逻辑分区总容量通过上面的例子,我们可以得知 hda=hda1+hda2+hda3,其中hda3=hda5+hda6+hda7+hda8+hda9+hda10 ... ...


四、fdisk 对硬盘及分区的操作

我们可以对硬盘进行分区操作,前提是您把fdisk -l 弄明白了;通过fdisk -l ,我们能找出机器中所有硬盘个数及设备名称;比如上面的例子,我们会看到两个设备一个是/dev/hda ,另一个是/dev/sda ;  fdisk 操作硬盘的命令格式如下:  [root@localhost beinan]# fdisk 设备  比如我们通过 fdisk -l 得知 /dev/hda 或者 /dev/sda设备;我们如果想再添加或者删除一些分区,可以用 [root@localhost beinan]# fdisk /dev/hda  或  [root@localhost beinan]# fdisk /dev/sda



  注 在以后的例子中,我们要以 /dev/sda设备为例,来讲解如何用fdisk 来操作添加、删除分区等动作;


1、fdisk 的说明;

当我们通过 fdisk 设备,进入相应设备的操作时,会发现有如下的提示;以 fdisk /dev/sda 设备为例,以下同; [root@localhost beinan]# fdisk /dev/sda  

Command (m for help): 在这里按m ,就会输出帮助;  

Command action  

a toggle a bootable flag  

b edit bsd disklabel  

c toggle the dos compatibility flag  

d delete a partition 注:这是删除一个分区的动作;  

l list known partition types 注:l是列出分区类型,以供我们设置相应分区的类型;  

m print this menu 注:m 是列出帮助信息;  

n add a new partition 注:添加一个分区;  

o create a new empty DOS partition table  

p print the partition table 注:p列出分区表;  

q quit without saving changes 注:不保存退出;  

s create a new empty Sun disklabel  

t change a partition's system id 注:t 改变分区类型;  

u change display/entry units  

v verify the partition table  

w write table to disk and exit 注:把分区表写入硬盘并退出;  

x extra functionality (experts only) 注:扩展应用,专家功能;  

其实我们常用的只有注有中文的,其它的功能我们不常用(呵,主要是我不会用,否则早会卖弄一下了);x扩展功能,也不是常用的;一般的情况下只要懂得 d l m p q t w 就行了;下面以实例操作来详述,没有例子没有办法就,新手也看不懂;
2、列出当前操作硬盘的分区情况,用p;

Command (m for help): p  

Disk /dev/sda: 1035 MB, 1035730944 bytes  

256 heads, 63 sectors/track, 125 cylinders  

Units = cylinders of 16128 * 512 = 8257536 bytes  

Device Boot Start End Blocks Id System  

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)  

/dev/sda2 26 125 806400 5 Extended  

/dev/sda5 26 50 201568+ 83 Linux  

/dev/sda6 51 76 200781 83 Linux
3、通过fdisk的d指令来删除一个分区;

Command (m for help): p 注:列出分区情况;  

Disk /dev/sda: 1035 MB, 1035730944 bytes  256 heads, 63 sectors/track, 125 cylinders  

Units = cylinders of 16128 * 512 = 8257536 bytes  

Device Boot Start End Blocks Id System  

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)  

/dev/sda2 26 125 806400 5 Extended  

/dev/sda5 26 50 201568+ 83 Linux  

/dev/sda6 51 76 200781 83 Linux  

Command (m for help): d 注:执行删除分区指定;  

Partition number (1-6): 6 注:我想删除 sda6 ,就在这里输入 6 ;  

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

Disk /dev/sda: 1035 MB, 1035730944 bytes  256 heads, 63 sectors/track, 125 cylinders  

Units = cylinders of 16128 * 512 = 8257536 bytes  

Device Boot Start End Blocks Id System  

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)  

/dev/sda2 26 125 806400 5 Extended  

/dev/sda5 26 50 201568+ 83 Linux  

Command (m for help):  

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

Command (m for help): p  

Disk /dev/sda: 1035 MB, 1035730944 bytes  

256 heads, 63 sectors/track, 125 cylinders  

Units = cylinders of 16128 * 512 = 8257536 bytes  

Device Boot Start End Blocks Id System  

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)  

/dev/sda2 26 125 806400 5 Extended  

/dev/sda5 26 50 201568+ 83 Linux  

Command (m for help): n 注:增加一个分区;  

Command action  l logical (5 or over) 注:增加逻辑分区,分区编号要大于5;为什么要大于5,因为已经有sda5了;  

p primary partition (1-4) 注:增加一个主分区;编号从 1-4 ;但sda1 和sda2都被占用,所以只能从3开始;  

p Partition number (1-4): 3  No free sectors available 注:失败中,为什么失败?  注:我试图增加一个主分区,看来是失败了,为什么失败?因为我们看到主分区+扩展分区把整个磁盘都用光了,看扩展分区的End的值,再看一下 p输出信息中有125 cylinders;最好还是看前面部分;那里有提到;所以我们只能增加逻辑分区了;

Command (m for help): n  

Command action  l logical (5 or over)  p primary partition (1-4)  l 注:在这里输入l,就进入划分逻辑分区阶段了;  First cylinder (51-125, default 51): 注:这个就是分区的Start 值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费;  Using default value 51  Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:这个是定义分区大小的,+200M 就是大小为200M ;当然您也可以根据p提示的单位cylinder的大小来算,然后来指定 End的数值。回头看看是怎么算的;还是用+200M这个办法来添加,这样能直观一点。如果您想添加一个10G左右大小的分区,请输入 +10000M ;

相关推荐

Global site tag (gtag.js) - Google Analytics