linux 下fdisk的使用

以下是一个实际的例子,请各位参考:

 

nx[root@test]# fdisk –l   ( 显示所有的磁盘和分区 )

 

Disk /dev/sda: 300.0 GB, 300000000000 bytes

255 heads, 63 sectors/track, 36472 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1                1           7       56196   12  Compaq diagnostics

/dev/sda2   *           8          20      104422+  83  Linux

 

Disk /dev/sdb: 300.0 GB, 300000000000 bytes

255 heads, 63 sectors/track, 36472 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1   *           1       13054   104856223+  83  Linux

 

Disk /dev/sdc: 300.0 GB, 300000000000 bytes

255 heads, 63 sectors/track, 36472 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

[root@test]# fdisk /dev/sdc ( 对磁盘 /dev/sdc 进行分区等设置 )

 

The number of cylinders for this disk is set to 36472.

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): p ( 打印出当前磁盘的分区表 )

 

Disk /dev/sdc: 300.0 GB, 300000000000 bytes

255 heads, 63 sectors/track, 36472 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

 

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): n ( 添加一个分区,注意:如果 /dev/sdc 是一个没有分区的磁盘的话,必须先创建一个 primary partition 分区 )

Command action

   e   extended

   p   primary partition (1-4)

p ( 创建主分区 )

Partition number (1-4): ( 这里没有输入合法的值 )

Value out of range.

Partition number (1-4): 1 ( 分区的编号是 1)

First cylinder (1-36472, default 1): ( 分区的起始位置,默认值是 1)

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-36472, default 36472): +51200M ( 分区的大小是 50G)

 

Command (m for help): p ( 打印分区表,检查刚才创建的分区是否正确 )

 

Disk /dev/sdc: 300.0 GB, 300000000000 bytes

255 heads, 63 sectors/track, 36472 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        6226    50010313+  83  Linux

 

Command (m for help): w ( 将刚才创建的信息写入磁盘,使之生效 )

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@test]# fdisk -l

 

Disk /dev/sda: 300.0 GB, 300000000000 bytes

255 heads, 63 sectors/track, 36472 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1           7       56196   12  Compaq diagnostics

/dev/sda2   *           8          20      104422+  83  Linux

 

Disk /dev/sdb: 300.0 GB, 300000000000 bytes

255 heads, 63 sectors/track, 36472 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1   *           1       13054   104856223+  83  Linux

 

Disk /dev/sdc: 300.0 GB, 300000000000 bytes

255 heads, 63 sectors/track, 36472 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        6226    50010313+  83  Linux

[root@test]# mkfs.ext3 -b 4096 /dev/sdc1 ( 在刚才创建好的 /dev/sdc1 分区上,建立 ext3 文件系统 )

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

6258688 inodes, 12502578 blocks

625128 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

382 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

10.43.118.16532768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

10.43.118.1654096000, 7962624, 11239424

 

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 23 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@test]# df ( 查看当前文件系统的磁盘使用量 )

Filesystem           1K-blocks      Used Available Use% Mounted on

/dev/sdb1            101572540   3943032  92386700   5% /

/dev/sda2               101105      10452     85432  11% /boot

tmpfs                  8219868         0   8219868   0% /dev/shm

[root@test]# mkdir /base

[root@test]# mount /dev/sdc1 /base   ( /dev/sdc1 挂到 /base )

[root@test]# df

Filesystem           1K-blocks      Used Available Use% Mounted on

/dev/sdb1            101572540   3943032  92386700   5% /

/dev/sda2               101105     10452     85432  11% /boot

tmpfs                  8219868         0   8219868   0% /dev/shm

/dev/sdc1             49224712    184332  46539868   1% /base

 

完成以上工作后,就可以使用文件系统了,但是如果想要在系统启动之后,自动 mount 自己的分区,需要修改 /etc/fstab ,在最后追加一行:

/dev/sdc1               /base                   ext3    defaults        1 2

每列的具体含义可参见:

http://www.ghacks.net/2009/01/03/understanding-linux-etcfstab/

http://en.wikipedia.org/wiki/Fstab

 

以下方法参见:

http://www.cyberciti.biz/faq/linux-disk-format/

http://www.idevelopment.info/data/Unix/Linux/LINUX_PartitioningandFormattingSecondHardDrive_ext3.shtml

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值