Linux磁盘分区格式化


在进行磁盘分区格式化之前,先介绍一些基础常识,虽说是常识,但隔行如隔山,外行人看了,不一定懂。不扯了,步入正题。

 

磁盘分区格式化是相对于硬盘而言的,硬盘属于随机存储设备,在我们的电脑上有各种硬盘的接口,而接口有可以归纳为两大类,串行接口和并行接口。

串行接口(Serial port)又称“串口”,主要用于串行式逐位数据传输。常见的有一般电脑应用的RS-232(使用 25 针或 9 针连接器)和工业电脑应用的半双工RS-485与全双工RS-422。

并行接口是一种增强了的双向并行传输接口。优点是不需在PC中用其它的卡,无限制连接数目(只要你有足够的端口),设备的安装及使用容易,最高传输速度为1.5Mbps。缺点是当传输距离较远、位数又多时,导致了通信线路复杂且成本提高。

推荐阅读:

Linux更改磁盘分区大小

Linux基础教程:磁盘分区(理论篇)

Ubuntu安装过程之磁盘分区图文教程

Linux fdisk命令参数及用法详解---Linux磁盘分区管理命令fdisk 

Linux, /dev/ 设备文件

IDE, ATA: /dev/hd[a-z]------并口

IDE: Master, Slave

第一个IDE控制接硬盘:

第二个IDE控制接光驱:hdc

SCSI, SAS, SATA, USB: /dev/sd[a-z]------串口

/dev/sda, /dev/sdb

Windows支持的文件系统主要有FAT32NTFS

Linux支持的文件系统主要有 MINIXXIAFSEXTEXT2ISO9660MSDOSUMSDOSVFATNTFSHPFSNFSSYSVSMBFSNCPFS

 

RAW:裸设备

低级格式化:创建磁盘

高级格式化:创建文件系统

MBR: Master Boot Record mbr是硬盘的主引导记录,属于引导区。

含有512bytes:

446bytes: bootloader

中间64: 分区表, 其中每16bytes标示一个分表,最多4主分区;

最后两个字节固定为55AA,(magic number)被称作魔数

 

SCSI接口为例,若是硬盘插在了第一个插槽,它的各个分区就可以这样表示

Sda1sda2sda3sda4.....

若是插在了第二个插槽,则可以这样表示

Sdb1sdb2, sdb3sdb4......

以此类推。

 

分区与格式化

 

先用fdisk分区,分区完成后再用mkfs格式化并创建文件系统,挂载,磁盘就能使用啦。

由于mbr主引导记录里的主分区表只有64bytes,而每个主分区在分区表里只能占16bytes,所以,硬盘上最多只能有四个主分区。

 

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

fdisk -l [DEVICE]

参数

-b<分区大小> 指定每个分区的大小。

-l 列出指定的外围设备的分区表状况。

-s<分区编号> 将指定的分区大小输出到标准输出上,单位为区块。

-u 搭配"-l"参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址。

-v 显示版本信息。

fdisk [DEVICE]

交互式命令:

d: 删除一个分区

n: 新建一个分区

p: 显示当前的分区信息

w: 保存退出

q: 不保存退出

l: 各分区类型所对应的System ID;

83Linux

82Linux Swap,交换分区

8eLVM

fd:Soft Raid

t: 修改指定分区的System ID;

 

fdisk -l [/dev/sda]

fdisk -l /dev/[hs]d[a-z]

[root@station110 ~]# fdisk -l /dev/sda
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006e97b
Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          26      204800  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        7859    62914560  8e  Linux LVM
/dev/sda4            7859      15665    62708728+  5  Extended
/dev/sda5            7859      10470    20979859+  83  Linux
/dev/sda6          10471      15665    41728806  83  Linux


[root@station110 ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help):

删除磁盘分区是,注意系统原先存在的主分区不要误删,否则,系统会直接崩溃
Command (m for help): d
Partition number (1-6): 4
Command (m for help): p
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006e97b
Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          26      204800  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        7859    62914560  8e  Linux LVM

直接创建扩展分区
Command (m for help): n
Command action
e  extended
p  primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (7859-15665, default 7859):
Using default value 7859
Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665):
Using default value 15665
Command (m for help): p
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006e97b
Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          26      204800  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        7859    62914560  8e  Linux LVM
/dev/sda4            7859      15665    62708728+  5  Extended

创建逻辑分区

Command (m for help): n
Command action
l  logical (5 or over)
p  primary partition (1-4)
l
First cylinder (7859-15665, default 7859):
Using default value 7859
Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665): +20G
Command (m for help): P
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006e97b
Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          26      204800  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        7859    62914560  8e  Linux LVM
/dev/sda4            7859      15665    62708728+  5  Extended
/dev/sda5            7859      10470    20979859+  83  Linux

格式化磁盘分区

[root@station110 ~]# mke2fs -b 1024 -m 3 -L music /dev/sda5

创建挂载点,进行挂载
[root@station110 ~]# mkdir /media/music
[root@station110 ~]# mount /dev/sda5 /media/music

取消挂载

[root@station110 ~]# umount /dev/sda5

只读挂载
[root@station110 ~]# mount -o ro /dev/sda6 /media/book
[root@station110 ~]# mount -r /dev/sda6 /media/book

若有其他用户正在访问某个挂载点,则无法卸载该挂载点
[root@station110 ~]# umount /dev/sda6
umount: /media/book: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))

查看是谁正在访问此挂载点

the device is found by lsof(8) or fuser(1))
[root@station110 ~]# fuser /media/book
/media/book:          3100c

fuser -km [MOUNT_POINT]: 强行杀死正在访问此挂载点的进程;
root@station110 ~]# fuser -km /media/book
/media/book:          3100c


查看内核识别的分区信息:
cat /proc/partitions
major minor  #blocks  name
8        0  125829120 sda
8        1    204800 sda1
8        2  62914560 sda2
8        4          1 sda4
8        5  52435129 sda5
8        6  10273536 sda6
8      16  20971520 sdb
253        0  20971520 dm-0
253        1    2097152 dm-1
253        2  10485760 dm-2
253        3  20971520 dm-3 

  • 1
  • 2
  • 下一页

相关内容