栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

CentOS6.8 使用 fdisk 命令 手动硬盘分区 手动挂载

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CentOS6.8 使用 fdisk 命令 手动硬盘分区 手动挂载

  • 环境

    • 虚拟机:VMware-10.0.7 build-2844087

    • Linux系统:CentOS 6.8

    • 远程工具:Xshell 6

CentOS6.8 使用 fdisk 命令 手动硬盘分区 手动挂载

一、前言

        初装Linux,使用安装引导界面进行分区, 当再增加一块硬盘时,需要手动分区,使用命令 fdisk 进行手动分区。

二、fdisk命令手动分区步骤

第一步、 新增一块磁盘
  • 虚拟机:关机,直接手动添加一块硬盘,电脑开机,检查网络状态;
  • 物理机:关机,加入一块物理硬盘,电脑开机。

第二步、查看所有硬盘及分区 fdisk -l
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000db990

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131         392     2097152   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             392        2611    17824768   83  Linux

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00000000

 说明:第一块硬盘 /dev/sda 已经正常分区,第二块硬盘 /dev/sdb 还没有分区,接下来针对第二块硬盘进行分区。

第三步、开始分区
  • 使用 fdisk /dev/sdb 进行分区
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x692e7205.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

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

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):  
#命令提示输入 m 获取帮助 
  • 输入 m  获取命令帮助
  • 命令说明:
    • 常用命令
      • n:新建一个分区
      • d:删除一个分区
      • p:显示分区列表
      • l :显示已知的文件系统,比如 83 代表 Linux 分区,82 代表 Linux swap/So 分区;
      • t :改变一个分区的系统ID
      • w:保存退出
      • q:不保存退出
      • m:帮助菜单 
    • 不常用命令
      • a:设置可引导标记
      • b:编辑bsb磁盘标签
      • c:设置DOS系统兼容标记
      • o:建立DOS空白分区表
      • s:新建SUM磁盘标签
      • u:改变显示记录单位
      • v:验证分区表
      • x:附加功能(仅专家)

  • 查看分区情况 p
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x692e7205

   Device Boot      Start         End      Blocks   Id  System

说明:目前还没有分区,所以列表中无数据 

  • 新建第一主分区 p
#新建主分区
Command (m for help): n
Command action
   e   extended                    #扩展分区
   p   primary partition (1-4)     #主分区(1-4)
#创建主分区
p
#创建并指定第一主分区
Partition number (1-4): 1
#起始柱面从 1 开始
First cylinder (1-2610, default 1): 1
#结束柱面,不加单位代表柱面,加K,M,G表示SIZE
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G
#查看分区情况
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x692e7205

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
#已创建第一主分区
  •  新建扩展分区 e
Command (m for help): n
Command action
   e   extended                #扩展分区
   p   primary partition (1-4) #主分区(1-4)
#选择扩展分区
e
#第2主分区设置为扩展分区
Partition number (1-4): 2
#起始柱面263
First cylinder (263-2610, default 263): 263
#结束柱面,不选择用默认 2610
Last cylinder, +cylinders or +size{K,M,G} (263-2610, default 2610): 
Using default value 2610
#查看当前分区情况
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x692e7205

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb2             263        2610    18860310    5  Extended
  • 新建第一个逻辑分区 l
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
#选择逻辑分区 l
l
#起始柱面263
First cylinder (263-2610, default 263): 263
#结束柱面 525 ( 263 + 262 )
Last cylinder, +cylinders or +size{K,M,G} (263-2610, default 2610): +262
#查看逻辑分区
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x692e7205

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb2             263        2610    18860310    5  Extended
/dev/sdb5             263         525     2112516   83  Linux

Command (m for help):
  • 保存退出
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
第四步、格式化 mkfs
  •  格式:mkfs -t ext4 文件系统名

  • 格式化 /dev/sdb1 
[root@localhost ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526120 blocks
26306 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

正在写入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override
  • 格式化 /dev/sdb5
[root@localhost ~]# mkfs -t ext4 /dev/sdb5
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
132192 inodes, 528129 blocks
26406 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7776 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

正在写入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
第五步、建立挂载点
  • 根目录下 / 建立挂载空目录 /disk1 和 /disk5
[root@localhost /]# mkdir /disk1
[root@localhost /]# mkdir /disk5
第六步、挂载 
[root@localhost /]# mount /dev/sdb1 /disk1
[root@localhost /]# mount /dev/sdb5 /disk5
第七步、查看挂载情况 
[root@localhost /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        17G  2.2G   14G  14% /
tmpfs           495M     0  495M   0% /dev/shm
/dev/sda1       976M   33M  892M   4% /boot
/dev/sdb1       2.0G  3.1M  1.9G   1% /disk1
/dev/sdb5       2.0G  3.1M  1.9G   1% /disk5

        说明:此时我们看到前面创建的两个分区都挂载完成。

  • 补充知识:查看挂载点
    • df -h         :查看系统当前磁盘状态及分区
    • mount      :查看所有已经挂载的分区和光盘
    • fdisk -l     : 查看系统分区        
三、小结
  • 知识点总结
    • fdisk命令手动分区
    • 查看挂载点方法        

        如文章内有错误,欢迎批评指正

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/858980.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号