Fdisk 分区详解
Fdisk 分区详解
来源 http://blog.itpub.net/20674423/viewspace-722812/
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 = 8225280 bytes
注释:这个硬盘的大小是10.7GB,有255个磁面,63个扇区,1305磁柱(cylinders)
每个 cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(约为)=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功能来指定。下面的部分会提到;
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
说明: 硬盘分区的表示:在Linux 是通过hd*x 或 sd*x 表示的:
其中 * 表示的是a、b、c ... ...
另外 x 表示的数字 1、2、3 ... ...
hd大多是IDE硬盘;sd大多是SCSI或移动存储; 引导(Boot):表示引导分区,在上面的例子中 sda1 是引导分区;
Start (开始):表示的一个分区从X cylinder(磁柱)开始;
End (结束):表示一个分区到 Y cylinder(磁柱)结束;
2、 学会使用fdisk帮助功能:
[root@jetsenLin ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 1305.
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): 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 --创建一个新的空白DOS分区表
p print the partition table ---打印分区表
q quit without saving changes ---退出不保存设置
s create a new empty Sun disklabel ---
t change a partition's system id ---改变分区的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):
3、 通过Fdisk对磁盘分区进行操作:
Fdisk 创建分区:
[root@jetsenLin ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain 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 is set to 2610.
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)
Warning: invalid flag 0x0000 of partition table 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 is set to 2610.
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): 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 = 8225280 bytes
Device Boot Start End Blocks Id System ----已经没有分区了
Command (m for help): w ----保存刚才的操作并且生效
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
这里报了一错误,分区表正在使用,删除再下次启动生效
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 = 8225280 bytes
Device Boot Start End Blocks Id System
通过fdisk 命令来创建一指定大小的分区并增加一个分区
Fdisk n
创建分区:
[root@jetsenLin ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 2610.
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): 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 table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
增加分区:
[root@jetsenLin ~]# fdisk /dev/sdb -----增加分区
The number of cylinders for this disk is set to 2610.
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): n ---分区类型
Command action
e extended
p primary partition (1-4) ---还是指定主分区
p
Partition number (1-4): 1 ---分区号,我指定1。
Partition 1 is already defined. Delete it before re-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 table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@jetsenLin ~]#
通过fdisk 命令来来修改现有分区类型
Fdisk 通过t参数来指定
查看分区类型
[root@jetsenLin ~]# 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 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1024 8225248+ 83 Linux
/dev/sdb2 1025 2000 7839720 83 Linux
修改分区类型
[root@jetsenLin ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 2610.
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): t ---进入修改分区类型
Partition number (1-4): 1 ---指定需要修改的分区号
Hex code (type L to list 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 table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page 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 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1024 8225248+ 6 FAT16
/dev/sdb2 1025 2000 7839720 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, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments 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 (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. 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.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@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/LogVol01 swap swap defaults 0 0
/data /dev/sdb1 ext4 default 0 0
第四列挂载参数:通过查看man mount 来查看
第五列是否要备份:(0为不备份,1为要备份, 一般情况下不用做备份)
第六列自检程序 (0为不自检,1或2为要自检,如果是根分区要设置1,其它分区只能是2)
============ End
Fdisk 分区详解的更多相关文章
- linux下磁盘分区详解 图文(fdisk;mkfs)
linux分区不同于windows,linux下硬盘设备名为(IDE硬盘为hdx(x为从a-d)因为IDE硬盘最多四个,SCSI,SATA,USB硬盘为sdx(x为a-z)),硬盘主分区最多为4个,不 ...
- linux磁盘及分区详解
1.Linux 分区简介 1.1 主分区 vs 扩展分区 硬盘分区表中最多能存储四个分区,但我们实际使用时一般只分为两个分区,一个是主分区(Primary Partion)一个是扩展分区(extend ...
- linux分区详解
点评:如果你想了解linux分区,请务必认真阅读本文.对于初学者来说,linux分区不像windows下那么一目了解. Linux 分区的规定 1. 设备管理 在 Linux 中,每一 ...
- linux磁盘分区详解【转】
本文装载自:http://blog.csdn.net/aaronychen/article/details/2270048#comments 在学习 Linux 的过程中,安装 Linux 是每一个初 ...
- linux下磁盘分区详解
Centos下磁盘管理 1.磁盘分区格式说明 linux分区不同于windows,linux下硬盘设备名为(IDE硬盘为hdx(x为从a—d)因为IDE硬盘最多四个,SCSI,SATA,USB ...
- Linux培训教程 linux磁盘分区详解
在学习 Linux 的过程中,安装 Linux 是每一个初学者的第一个门槛.在这个过程中间,最大的困惑莫过于给硬盘进行分区.虽然,现在各种发行版本的 Linux 已经提供了友好的图形交互界面,但是很多 ...
- oracle表分区详解
原文来自:http://www.cnblogs.com/leiOOlei/archive/2012/06/08/2541306.html oracle表分区详解 从以下几个方面来整理关于分区表的概念及 ...
- 基于集合成工控机Ubuntu系统安装分区详解
基于集合成工控机Ubuntu系统安装分区详解 硬件描述:双核的CPU,128G的固态硬盘 软件描述:使用Ubuntu12.04系统,内核3.8.0-29版本,QT4.8.1版本 1.新建分区表 /de ...
- SQL Server表分区详解
原文:SQL Server表分区详解 什么是表分区 一般情况下,我们建立数据库表时,表数据都存放在一个文件里. 但是如果是分区表的话,表数据就会按照你指定的规则分放到不同的文件里,把一个大的数据文件拆 ...
随机推荐
- Linux安装gitlab
一.GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务.安装方法是参考GitLab在GitHub上的Wiki页面. 二.我相信使用过git的开 ...
- idea热部署时 编写Controller会接收不到参数
因为我是热部署启动服务器后才编写的request和getparameter 所以可能接收不到 重启一下服务器即可
- Sublime Text 3安装完美的Vim支持,ActualVim/NeoVim
很多IDE和编辑器都有Vim插件用于支持Vim模式,但大多数都有些问题,拿我一直用的Idea来说,它的vim在ctrl+v后,选择多行的行前插入,如果这几行中有空行,它不会把空格算在内,所以最终是会少 ...
- 九、EnterpriseFrameWork框架基础功能之消息管理
记得阿朱在<走出软件作坊>一书中有一章讲客户提的需求太邪门了,鼠标键盘不太会用要程序员开发一个语音输入功能,还要系统中带类似QQ的功能:确实刚开始的客户的想法有点天真,但是随着信息化的越来 ...
- nginx基础配置加基础实战演示
目录 基本配置 设置用户 工作衍生进程数 错误日志存放路径 pid文件存放路径 设置最大连接数 http->server gzip 字符编码 nginx的基本格式 实战配置 虚拟主机配置 开始配 ...
- [转]git学习------>git-rev-parse命令初识
git学习------>git-rev-parse命令初识 2017年06月13日 10:04:13 阅读数:2172 一.准备工作 第一步:在d盘git test目录下,新建工作区根目录dem ...
- mysql 5.5 zip配置安装
1.解压2.创建option文件 --defaults-file=../my.ini [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mys ...
- Halcon学习网
重码网是一个在线机器视觉学习网站,推出了Halcon,Visionpro机器视觉学习视频教程,视频内容通俗易懂,没有编程基础的同学,照着视频练习,也同样可以学会. 学机器视觉,拿高薪,成就技术大拿.重 ...
- oozie的shell-action中加入hive脚本命令启动执行shell同时操作hive,抛异常Container killed on request. Exit code is 143 Container exited with a non-zero exit code 143
使用oozie来调度操作,用shell的action执行命令,其中shell里包含着hive -e 操作执行时,oozie窗口报 WARN ShellActionExecutor: - SERVER[ ...
- Python:内建函数zip
1.语法 zip([iterable,...]) [说明]:iterable——一个或多个迭代器 2.功能 zip()函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个的元组,然后返回由这 ...