当我们想在系统里增加一块硬盘的时候,要做以下这四步工作:
fdisk [-l] 设备名称
-l:加上这个参数会输出后面接的这个设备的所有分区的信息;如果后面不写设备名称,那么系统中所有设备的分区信息都会被列出来
PS:fdisk这个命令只是一系列磁盘分区功能的入口命令!例子:给咱电脑的磁盘进行一下分区
//1。找到所有的磁盘设备的名字
[root@iZ28st035lsZ ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/hda1 20307028 2666372 16592468 14% /
//2。对hda进行分区
[root@iZ28st035lsZ ~]# fdisk /dev/hda //这里设备名称不加数字!
The number of cylinders for this disk is set to 3343.
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): //查看帮助
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): p
Disk /dev/hda: 21.4 GB, 21474836480 bytes
224 heads, 56 sectors/track, 3343 cylinders
Units = cylinders of 12544 * 512 = 6422528 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 3343 20963801 83 Linux
Partition 1 does not end on cylinder boundary.
Device:设备文件名字
Boot:是否为开机引导模块,Windows下C盘需要开机引导模块
Start,End:表示这个分区的开始柱面号与终止柱面号
Blocks:这个分区中block的数量,单位是1KB注意:fdisk -l可以列出整个系统中所有磁盘的所有分区,如果有多个磁盘(比如插入了一块U盘),那么执行这个命令后,再选择p,结果是这样的: PS:也就是会显示两块这样的信息,分别代表两块磁盘中的分区情况
Disk /dev/hda: 21.4 GB, 21474836480 bytes
224 heads, 56 sectors/track, 3343 cylinders
Units = cylinders of 12544 * 512 = 6422528 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 3343 20963801 83 Linux
Partition 1 does not end on cylinder boundary.
----------------------------------------
Disk /dev/hda: 21.4 GB, 21474836480 bytes
224 heads, 56 sectors/track, 3343 cylinders
Units = cylinders of 12544 * 512 = 6422528 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 3343 20963801 83 Linux
Partition 1 does not end on cylinder boundary.如果出现柱面号是以下情况:
//hda1的起始和结束柱面号是1-3343,而hda5的起始和结束柱面号是1-2000,那么说明hda5是属于hda1的一个逻辑分区,那么hda1就是扩展分区了。
Device Boot Start End Blocks Id System
/dev/hda1 * 1 3343 20963801 83 Linux
/dev/hda5 * 1 2000 20963801 83 Linuxfdisk /dev/hda //进入fdisk界面
Command (m for help): d //选择“删除分区“
Selected partition 1 //选择要删除的分区号
w (or) q //保存或离开PS:若hda5是由hda4衍生出来的逻辑分区,如果把hda4删除,那么hda5也会随之消失。
//选择n,新建分区
Command (m for help): n
//选择新建主分区or扩展分区
Command action
e extended
p primary partition (1-4)p //选择主分区
Partition number (1-4): 4 //选择分区号
First cylinder (1-834, default 1): //选择起始柱面号,就用默认值,按下回车即可
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-834, default 834): +512M//输入分区大小,+xxxM,+表示让系统自动找一个最接近xxxM大小的柱面综上所述,一共有这几种情况:
关于新建分区的一些注意点:
分区完毕之后就要进行格式化,格式化非常简单,使用mkfs(make file system)即可。
mkfs [-t 文件系统格式] 磁盘设备的文件名
-t后的文件系统格式就是让你指定将文件系统格式化成哪种文件系统。如ext2、ext3、vfat等。PS:通过mkfs tab tab就可以查看本系统支持的所有文件系统了。
当系统运行出现问题导致文件系统发生错乱,此时就需要磁盘的检验。
fsck [-t 文件系统] [-ACay] 设备名称注意:通常只有root用户,而且在文件系统有问题的时候才能进行这个操作,因为在正常情况下使用这个命令会对系统伤害很大。 此外,fsck在扫描的时候,有问题的数据会被放在lost+found这个文件夹中。所以正常情况下这个文件夹中是不应该有数据的。