`
sony-soft
  • 浏览: 1027716 次
文章分类
社区版块
存档分类
最新评论

Linux下分区详解之--Fdisk

 
阅读更多

Linux下分区详解之--Fdisk

作者:吴伟龙

1、通过Fdisk查看系统分区详细信息:

Fdisk –l 详解:

[root@jetsenLin ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

注释:这个硬盘的大小是10.7GB,有255个磁面,63个扇区,1305磁柱(cylinders)

每个cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(约为)=8.225280M(约为);

Device Boot Start End BlocksId System

/dev/sda1* 1 13 10439183 Linux

/dev/sda2 14 130510377990 8e Linux LVM

idSystem 表示的是一个意思,id看起来不太直观,我们要在fdisk 一个分区时,通过指定id来确认分区类型;比如 7表示的就NTFS 分区;这个在fdisk 中要通过t功能来指定。下面的部分会提到;

Disk /dev/sdb: 21.4 GB,21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Disk /dev/sdb doesn't contain a validpartition table

说明:硬盘分区的表示:在Linux 是通过hd*x sd*x 表示的:

其中* 表示的是abc ... ...

另外x 表示的数字 123 ... ...

hd大多是IDE硬盘;sd大多是SCSI或移动存储;引导(Boot):表示引导分区,在上面的例子中sda1 是引导分区;

Start (开始):表示的一个分区从Xcylinder(磁柱)开始;

End (结束):表示一个分区到 Ycylinder(磁柱)结束;

2、学会使用fdisk帮助功能:

[root@jetsenLin~]# fdisk /dev/sda

Thenumber of cylinders for this disk is set to 1305.

There isnothing wrong with that, but this is larger than 1024,

and couldin certain setups cause problems with:

1) softwarethat 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 ---输出帮助信息

Commandaction

atoggle a bootable flag ---设置启动分区

bedit bsd disklabel ---编辑分区标签

ctoggle the dos compatibility flag

ddelete a partition --删除一个分区

llist known partition types --列出分区类型

mprint this menu --帮助

nadd a new partition --建立一个新的分区

ocreate a new empty DOS partition table--创建一个新的空白DOS分区表

pprint the partition table---打印分区表

qquit without saving changes---退出不保存设置

s createa new empty Sun disklabel ---

t changea partition's system id---改变分区的ID

u changedisplay/entry units---改变显示的单位

v verifythe partition table---检查验证分区表

wwrite table to disk and exit---保存分区表

xextra functionality (experts only)

Command (m for help):

3、通过Fdisk对磁盘分区进行操作:

Fdisk 创建分区:

[root@jetsenLin ~]#fdisk /dev/sdb

Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes willremain in memory only,

until you decide to write them. After that,of course, the previous

content won't be recoverable.

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother OSs

(e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w(rite)

Command (m for help): n ---输入m会有帮助信息出来,输入n不打印帮助信息

Command action

e extended

p primary partition (1-4) ---指定分区类型 e为扩展分区 p为主分区

p

Partition number (1-4): 1 ---定义分区数量 --主分区最多只能有四个

First cylinder (1-2610, default 1): 1 ---设定起始分区的位置

Last cylinder or +size or +sizeM or +sizeK(1-2610, default 2610):

Using default value 2610 ---设定结束分区的位置

Command (m for help): w ---保存刚才的配置信息。

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@jetsenLin ~]#

Fdisk 删除分区:

[root@jetsenLin ~]# fdisk /dev/sdb

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): d ---d 是代表删除,并且会列出当前磁盘的分区数。

Selected partition 1

Command (m for help): p ----p 是代表删除后,显示磁盘还有几个剩余的分区。

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Device Boot Start End BlocksId System ----已经没有分区了

Command (m for help): w ----保存刚才的操作并且生效

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the nextreboot.

这里报了一错误,分区表正在使用,删除再下次启动生效

Syncing disks. ---同步新的磁盘信息

[root@jetsenLin ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Device Boot Start End BlocksId System

通过fdisk 命令来创建一指定大小的分区并增加一个分区

Fdisk n

创建分区:

[root@jetsenLin ~]# fdisk /dev/sdb

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n ---创建分区

Command action

e extended

p primary partition (1-4) --指定分区类型为主分区

p

Partition number (1-4): 1 --指定其实分区号

First cylinder (1-2610, default 1): 1 --指定起始柱面号

Last cylinder or +size or +sizeM or +sizeK(1-2610, default 2610): 1024 ---指定终止柱面号

Command (m for help): w ---保存分区配置信息

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the nextreboot.

Syncing disks.

增加分区:

[root@jetsenLin ~]# fdisk /dev/sdb -----增加分区

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n ---分区类型

Command action

e extended

p primary partition (1-4) ---还是指定主分区

p

Partition number (1-4): 1 ---分区号,我指定1

Partition 1is already defined. Delete it beforere-adding it.

提示分区号1已经存在,删除后操作

Command (m for help): n --我们重新创建分区

Command action

e extended

p primary partition (1-4) --指定分区类型

p

Partition number (1-4): 2 ---因为分区1已经存在,所以我们指定分区2,可通过。

First cylinder (1025-2610, default 1025): ---指定起始礠柱号,默认是上一分区后一号。

Using default value 1025

Last cylinder or +size or +sizeM or +sizeK(1025-2610, default 2610): 2000 --指定终止礠柱号。

Command (m for help): w ---保存分区配置

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the nextreboot.

Syncing disks.

[root@jetsenLin ~]#

通过fdisk命令来来修改现有分区类型

Fdisk 通过t参数来指定

查看分区类型

[root@jetsenLin ~]# fdisk -l /dev/sdb 查看分区信息,类型是Linuxid83

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Device Boot Start End BlocksId System

/dev/sdb1 1 10248225248+ 83 Linux

/dev/sdb2 1025 20007839720 83 Linux

修改分区类型

[root@jetsenLin ~]# fdisk /dev/sdb

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): t ---进入修改分区类型

Partition number (1-4): 1 ---指定需要修改的分区号

Hex code (type L tolist codes): 6 ---指定分区号为6,也就是FAT16

注意:查看分区类型的代码,在这里可以输入L查看就可以了

Changed system type of partition 1 to 6(FAT16)

Command (m for help): w ---保存

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the nextreboot.

WARNING: If you have created or modifiedany DOS 6.x

partitions, please see the fdisk manualpage for additional

information.

Syncing disks.

[root@jetsenLin ~]# fdisk -l /dev/sdb ---我们看到已经FAT16,并且ID也改成6了。

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Device Boot Start End BlocksId System

/dev/sdb1 1 10248225248+ 6 FAT16

/dev/sdb2 1025 20007839720 83 Linux

[root@jetsenLin ~]#

4、对分区进行格式化及加载:

对分区进行格式化的命令如下等,mkfs后面所接的代表的是将要格式化成的文件系统类型:

mkfs.bfs

mkfs.ext2

mkfs.ext3

mkfs.jfs

mkfs.msdos

mkfs.vfat

mkfs.cramfs

mkfs.minix

mkfs.reiserfs

mkfs.xfs

格式化分区:

[root@jetsenLin ~]# mkfs.ext4 /dev/sdb1 ---格式化分区类型为ext4

mke4fs 1.41.5(23-Apr-2009)

Filesystem label= ---我们没有指定卷标,就没有

OS type: Linux ---操作系统类型

Block size=4096 (log=2) --单个块的大小

Fragment size=4096 (log=2) --片大小

1310720 inodes, 5241198blocks

262059 blocks (5.00%)reserved for the super user

First data block=0

Maximum filesystem blocks=0

160 block groups

32768 blocks per group, 32768fragments per group

8192 inodes per group

Superblock backups stored on blocks:

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

4096000

Writing inode tables:done

Creating journal (32768blocks): done

Writing superblocks andfilesystem accounting information: done

This filesystem will beautomatically checked every 27 mounts or

180 days, whichever comesfirst. Use tune4fs -c or -i to override.

挂载磁盘:(临时挂载)

[root@jetsenLin ~]# mkdir/data --创建挂载目录点

[root@jetsenLin ~]#mount /dev/sdb1 /data --/dev/sdb1 挂载到/data

验证是否成功挂载

[root@jetsenLin ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

7.7G 3.1G4.2G 43% /

/dev/sda1 99M 12M82M 13% /boot

tmpfs 506M0 506M 0% /dev/shm

/dev/sdb1 20G 16K20G 1% /data --我们看到已经成功挂载了。

[root@jetsenLin ~]#

挂载磁盘:(永久挂载)

通过vi编辑器编辑/etc/fstab文件,内容如下,(红色部分是刚添加上去的):

挂载路径 挂载的分区 文件系统 挂载参数 是否要备份 自检顺序

/dev/VolGroup00/LogVol00/ ext3 defaults 1 1

LABEL=/boot /boot ext3 defaults 1 2

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

/dev/VolGroup00/LogVol01swap swap defaults 0 0

/data /dev/sdb1 ext4 default 0 0

第四列挂载参数:通过查看man mount 来查看

第五列是否要备份:(0为不备份,1为要备份,一般情况下不用做备份)

第六列自检程序 0为不自检,12为要自检,如果是根分区要设置1,其它分区只能是2

分享到:
评论

相关推荐

    Linux中fdisk详解

    实例解说Linux中fdisk分区使用方法

    Linux fdisk命令用法详解

    Linux fdisk是一个创建和维护分区表的程序,它兼容DOS类型的分区表、BSD或者SUN类型的磁盘列表。 语法 fdisk [必要参数][选择参数] 必要参数: -l 列出素所有分区表 -u 与”-l”搭配使用,显示分区数目 选择参数:...

    Linux之 fdisk 命令操作详解

    >>>Linux教程目录<<< 文件系统管理-3.1fdisk 命令分区过程 写在前面:自己写完检查可能会有所纰漏,读者们如若发现哪里有错误,可在下方留言或私信我,我会第一时间改正 1. 添加新硬盘 2. 查看新硬盘 fdisk...

    Linux常用命令大全.zip

    内含Linux常用必会60+个命令实例以及详解。 Linux提供了大量的命令,利用它可以有效地完成大量的工作, 如磁盘操作、文件存取、目录操作、进程管理、文件权限设定等。 所以,在Linux系统上工作离不开使用系统提供的...

    Linux下的fdisk命令用法详解

    Linux下的fdisk功能是极其强大的,用它可以划分出最复杂的分区,下面简要介绍一下它的用法: 对于IDE硬盘,每块盘有一个设备名:对应于主板的四个IDE接口,设备名依次为:/dev/hda,/dev/hdb,/dev/hdc,/dev/hdd等, ...

    Linux之分配 swap 分区详解

    >>>Linux教程目录<<< 文件系统管理-4.1分配swap分区 写在前面:自己写完检查可能会有所纰漏,读者们如若发现哪里有错误,可在下方留言或私信我,我会第一时间改正 1. free 命令 free 查看内存与 swap 分区...

    详解Linux下挂载新硬盘方法

    Linux的硬盘识别: 一般使用”fdisk -l”命令可以列出系统中当前连接的硬盘 设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息. 1.关闭服务器加上新硬盘 2.启动服务器,以root用户登录 3.查看硬盘信息 #...

    Linux 自动分区、格式化、挂载脚本详解

    自动分区、格式化、挂载脚本 功能:自动检测是否有尚未分区的数据盘,格式化新的数据盘并自动挂载 解决了什么问题:一键式检测是否有尚未分区的数据盘,并能对其格式化和自动挂载,省去了复杂的命令和步骤 执行...

    基于Linux系统中查看硬件等信息的方法详解

    本文介绍下,linux下查看硬件信息的命令与方法,包括主板序列号、cpu信息、内存信息、硬盘信息、网卡信息等。1,主板信息.查看主板的序列号 #使用命令dmidecode | grep -i ‘serial number’#查看板卡信息cat /proc/...

    Linux cfdisk命令用法详解

    cfdisk是用来磁盘分区的程序,它十分类似DOS的fdisk,具有互动式操作界面而非传统fdisk的问答式界面,您可以轻易地利用方向键来操控分区操作。 语法 cfdisk [-avz][-c -h -s ][-P ][外围设备代号] 参数说明: -a 在...

    DISKGEN命令详解

    然后按提示输入分区大小,选择分区类型(要建立非DOS分区,还须根据提示设定系统标志,如建立Linux分区,系统标志为“83”)。利用本软件,你最多可以建立四个DOS主分区。存盘前如用户未设置启动分区,则自动激活第一...

    详解CentOS阿里云云服务器硬盘分区及挂载

    硬盘分区及挂载操作步骤: 1. 查看未挂载的硬盘(名称为/dev/xvdb) # fdisk -l Disk /dev/xvdb doesn’t contain a valid partition table 2. 创建分区 # fdisk /dev/xvdb … 输入n Command (m for help):n 输入...

    Linux磁盘设备与LVM管理命令示例详解

    这些文件绝大多数位于 /dev 目录下,用来表示 Linux 主机检测到的某个具体的硬件设备。 比如 /dev/sda 文件通常用来指代系统中的第一块硬盘。 Linux 操作系统及其应用与服务则通过这些设备文件与对应的硬件设备...

    Linux中软RAID的创建及维护

     首先用fdisk命令创建分区,操作如下: fdisk /dev/sdc  查看分区信息  用磁盘的话,每一块磁盘创建一个分区。  2.创建RAID 5  其中“- -spare-device=1”表示当前阵列中备用设备只有一块,即作为备用设备的...

    Ubuntu下如何创建XFS文件系统的LVM详解

    lvm(Logical Volume Manager) 逻辑卷管理, 可以满足linux系统动态调整各分区大小,满足服务器在不同的运行时期的需求。 以前在Linux下面玩LVM,一般都是选择ext3、ext4格式的文件系统,最近在Ubuntu 16.04.5下安装...

    Ghost 8.3 系统备份软件

    Ghost 使用详解 -------------------------------------------------------------------------------- 一、分区备份  使用Ghost进行系统备份,有整个硬盘(Disk)和分区硬盘(Partition)两种方式。在菜单中...

    Ghost 8.3 Enterprise

    Ghost 使用详解  --------------------------------------------------------------------------------  一、分区备份  使用Ghost进行系统备份,有整个硬盘(Disk)和分区硬盘(Partition)两种方式。在菜单中...

Global site tag (gtag.js) - Google Analytics