1,磁盘分区命令fdisk

[root@localhost ~]# fdisk -l #查看磁盘分区情况

Disk /dev/sda: 10.8 GB, 10837518250 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

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

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

Device Boot      Start       End      Blocks    Id  System

/dev/sda1  *       1         13      104391    83  Linux

/dev/sda2          14        1305     10377990   8e  Linux LVM

(ID和System表示的是分区类型,id看起来不太直观,我们要在fdisk创建一个分区时,可以指定id来确认分区类型;比如7表示的就NTFS分区;这个在fdisk中要通过参数“t”来指定。)

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

其中*表示的是a、b、c ... ...

另外x表示的数字1、2、3 ... ...

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

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

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

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

[root@localhost ~]# fdisk /dev/sda  #对磁盘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)

(输入m可以得到帮助信息)

Command(m for help): m                   ---输出帮助信息

Commandaction

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

b  edit bsd disklabel                 ---编辑分区标签

c  toggle the dos compatibility flag         ---切换dos兼容模式

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      --创建一个新的空白DOS分区表

p  print the partition table                 ---打印分区表

q  quit without saving changes                ---退出不保存设置

s   createa new empty Sun disklabel             ---创建新的sun磁盘标签

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

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

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

w  write table to disk and exit               ---保存分区表

x  extra functionality (experts only)        ---扩展功能

Command (m for help): n (创建一个新分区)

Command action

e   extended

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

p (输入p选择创建主分区)

Partition number (1-4): 1 (创建第一个主分区,也即是后来的sda1) ---主分区最多只能有四个

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

Last cylinder or +size or +sizeM or +sizeK(1-2610, default 2610):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@localhost ~]# 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     (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    Blocks  Id  System   已经没有分区了

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

The partition table has been altered!

Calling ioctl() to re-read partition table.

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

[root@localhost ~]# 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                输入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@localhost ~]# 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@localhost ~]#

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

fdisk 通过t参数来指定

查看分区类型

[root@localhost ~]# fdisk -l /dev/sdb   查看分区信息,类型是Linux,id是83

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      Blocks  Id  System

/dev/sdb1          1        1024    8225248+  83  Linux

/dev/sdb2         1025         2000       7839720   83  Linux

修改分区类型

[root@localhost ~]# 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@localhost ~]# 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      Blocks  Id  System

/dev/sdb1          1             1024    8225248+   6  FAT16

/dev/sdb2         1025             2000    7839720   83  Linux

[root@localhost ~]#

mkfs对分区进行格式化:

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

mkfs.bfs

mkfs.ext3

mkfs.ext4

mkfs.jfs

mkfs.msdos

mkfs.vfat

mkfs.cramfs

mkfs.minix

mkfs.reiserfs

mkfs.xfs

格式化分区:

[root@localhost ~]# 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.

mount挂载磁盘:(临时挂载)

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

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

验证是否成功挂载

[root@localhost ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

7.7G  3.1G 4.2G  43% /

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

tmpfs           506M   0    506M   0%  dev/shm

/dev/sdb1         20G   16K  20G   1%  /data     --已经成功挂载了。

[root@localhost ~]#

修改fstab表挂载磁盘(永久挂载)

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

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

/dev/VolGroup00/LogVol00/        ext3    defaults        1 1

LABEL=/boot     /boo          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     defaults           0 0

保存后执行命令 mount -a 加载最新配置

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

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

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

本文转自super李导51CTO博客,原文链接: http://blog.51cto.com/superleedo/1886547,如需转载请自行联系原作者

Linux磁盘管理----分区格式化挂载fdisk、mkfs、mount相关推荐

  1. mount查看linux分区大小,Linux磁盘管理----分区格式化挂载fdisk、mkfs、mount

    1,磁盘分区命令fdisk [root@localhost ~]# fdisk -l #查看磁盘分区情况 Disk /dev/sda: 10.8 GB, 10837518250 bytes 255 h ...

  2. Linux磁盘管理——分区+挂载(fdisk+gdisk+mount+lsblk+df)

    文章目录 一.硬盘基础知识 1. 硬盘命名方式 2. 磁盘设备的命名 3. 硬盘的分区方式 二.基本分区管理 1. 磁盘划分思路 2.lsblk命令 3. df 命令 4. fdisk 1)进入分区 ...

  3. 20. 磁盘的分区,格式化,挂载——fdisk,mkfs,mount

    1.        VM虚拟机添加磁盘,识别磁盘将其添加到分区 注意:reboot之后系统才能识别新加硬盘. 2.        fdisk命令:fdisk -l 查看系统的分区详细信息 [root@ ...

  4. 1. Linux 磁盘管理(分区、格式化、挂载)

    目录 1.  Linux 内核版与发行版 2.  Linux中磁盘的管理(分区.格式化.挂载) 2.1 磁盘定义.分类和命名 2.2 分区的定义和划分 2.3 磁盘格式化(高级/逻辑格式化) 2.4 ...

  5. 学习OpenStack之 (4): Linux 磁盘、分区、挂载、逻辑卷管理 (Logical Volume Manager)

    0. 背景: inux用户安装Linux操作系统时遇到的一个常见的难以决定的问题就是如何正确地评估各分区大小,以分配合适的硬盘空间.普通的磁盘分区管理方式在逻辑分区划分好之后就无法改变其大小,当一个逻 ...

  6. linux磁盘管理、格式化、分区

    磁盘管理 名词:DISK 磁盘.硬盘 磁盘作用:存储数据 种类:机械硬盘.固态硬盘 命名:SATA(串口)1./dev/sda 2./dev/sdb 分区方式1,MBR:主引导记录(Master Bo ...

  7. linux实验------对磁盘进行分区格式化挂载

    文章目录 step1 step2 step3 step4 step5 step1 为虚拟机添加1块大小为20G的硬盘sdb,将该硬盘划分1个主分区和两个逻辑分区. 打开虚拟机设置进行如下操作: **f ...

  8. 【AWSL】之Linux磁盘管理与文件系统(fdisk、df、mount、umount、lsblk)

    序言 这里我主要介绍以下Linux的磁盘管理与文件系统的一些操作与概述 磁盘和文件 序言 一.磁盘分区结构 二.文件系统类型 三. 检测并确认新硬盘 1.fdisk命令 2.fdisk -l 3.规划 ...

  9. Linux 磁盘管理-分区管理-磁盘分区【gdisk】gpt分区工具使用介绍

    gdisk -l [设备] gdisk又叫GPT fdisk,算是fdisk的延伸吧,主要使用的是GPT分区类型,用来划分容量大于2T的硬盘. 扩展1:分区类型GPT和MBR.GPT最大支持18EB( ...

最新文章

  1. java json.pasent_来自CSV的带有id parent(Python)的JSON树
  2. Swift之深入解析协议Protocol的底层原理
  3. Python二级笔记(18,19合集知识点篇)
  4. 【Siddhi】Siddhi 如何表示布尔 Syntax error in SiddhiQL, mismatched input ‘boolean
  5. keil 在多字节的目标代码页中 没有此unicode_Go语言之父带你重新认识字符串、字节、rune和字符
  6. Netty网络编程聊天项目
  7. WPF MVVM模式 发送DataGird表格的数据到另一个页面显示
  8. 使用jdk1.8 新特性stream实现多级分类
  9. python下载问题_初学者下载使用Python遇到的问题看它就行了
  10. 工作总结之因为笛卡尔积问题写SQL搞了半天[害](附笛卡尔积总结)
  11. java的class文件在哪里_传统上,你在哪里存储Java .class文件?
  12. C语言之一个有趣的关机程序
  13. 使用ODAC将SqlServer数据库同步到oracle数据库
  14. 【牛刀小试4】斐波那契数
  15. 总结揭露黑客入侵网站的手法
  16. 在CityEngine中制作绘制路网
  17. 游弋于太平洋,摆脱甜蜜的烦恼
  18. C++基础——IO库基础
  19. OpenJudge 4124 海贼王之伟大航路 深搜剪枝
  20. 二次解析源码全kyuan

热门文章

  1. Java异常信息处理
  2. Binary Tree Postorder Traversal
  3. 《C++ Primer Plus 6th》读书笔记 - 第8章 函数探幽
  4. CallContext和多线程
  5. 对B样条的理解和整理
  6. 敏捷 - #9 原则:持续关注卓越的技术和良好的设计 ( #9 Agile - Principle)
  7. 前端每日实战:164# 视频演示如何用原生 JS 创作一个数独训练小游戏(内含 4 个视频)...
  8. snpeff注释变异(variants)
  9. java回调机制及其实现(转)
  10. 基于jQuery 2.0的源代码分析