本文主要讲述使用fdisk工具对磁盘进行分区和格式化的方法

首先要明确分区是针对磁盘进行的操做,磁盘分区会创建分区表,类似vda,sda的是磁盘,vda1,sda1的是分区

1.查看磁盘分区状态

1.1. 查看分区挂载情况

df -h

1.2.查看服务器挂载的磁盘

fdisk -l
fdisk -l /dev/vdb

2.磁盘分区

2.1.对vdb磁盘进行分区

fdisk /dev/vdb

进入交互式的分区界面,以下是分区操作步骤

m打印菜单
n新建分区
p选择主分区
e选择扩展分区
1选择分区号
选择初始位置,默认为1
选择结束为止,默认为磁盘结尾

分区创建完成,可以列表查看,保存退出

p打印分区表
w写入分区表保存
q退出

2.2.重新载入磁盘分区信息

无返回就是载入磁盘信息成功,针对磁盘进行操作

partprobe /dev/vdb

注意:
使用fdisk工具只是将分区信息写到磁盘,
在格式化分区值前需要使用partprobe让kernel重新读取分区信息,如果不成功则需要重启系统

2.3.对磁盘分区进行格式化

使用ext4文件系统

mkfs.ext4 /dev/vdb1

2.4.格式化完成后续优化配置,取消磁盘自检

tune2fs -c - /dev/vdb1 

3.分区挂载

3.1.挂载磁盘分区到指定目录

mkdir -p /data
mount /dev/vdb1 /data

3.2.配置开机自动挂载分区

/etc/fstab 增加一行

vim /etc/fstab
-------------------------------------------------------
/dev/vdb1 /data ext4 defaults
-------------------------------------------------------

5.实例演示:使用Ubuntu系统进行磁盘分区操作

5.1.查看磁盘分区信息

root@zstest:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev .9G .9G % /dev
tmpfs .6G 3.2M .6G % /run
/dev/vda1 50G .7G 41G % /
tmpfs .9G .9G % /dev/shm
tmpfs 5.0M 5.0M % /run/lock
tmpfs .9G .9G % /sys/fs/cgroup
tmpfs .6G .6G % /run/user/

5.2.列表查看磁盘信息

root@zstest:~# fdisk -l
Disk /dev/vda: GiB, bytes, sectors
Units: sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disklabel type: dos
Disk identifier: 0xd6804155 Device Boot Start End Sectors Size Id Type
/dev/vda1 * 50G Linux Disk /dev/vdb: GiB, bytes, sectors
Units: sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes

5.3.对磁盘vdb进行分区

root@zstest:~# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.27.).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command. Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x63c3e6e0. Command (m for help): n
Partition type
p primary ( primary, extended, free)
e extended (container for logical partitions)
Select (default p): p
Partition number (-, default ):
First sector (-, default ):
Last sector, +sectors or +size{K,M,G,T,P} (-, default ): Created a new partition of type 'Linux' and of size GiB. Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

5.4.查看分区信息

root@zstest:~# fdisk -l
Disk /dev/vda: GiB, bytes, sectors
Units: sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disklabel type: dos
Disk identifier: 0xd6804155 Device Boot Start End Sectors Size Id Type
/dev/vda1 * 50G Linux Disk /dev/vdb: GiB, bytes, sectors
Units: sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disklabel type: dos
Disk identifier: 0x63c3e6e0 Device Boot Start End Sectors Size Id Type
/dev/vdb1 50G Linux

5.5.重新载入磁盘分区信息

root@zstest:~# partprobe /dev/vdb

5.6.对指定磁盘分区进行格式化,使用ext4文件系统

root@zstest:~# mkfs.ext4 /dev/vdb1
mke2fs 1.42. (-May-)
Creating filesystem with 4k blocks and inodes
Filesystem UUID: 047fb8b0-e6ed-42db-bf5c-2a6d388fc34d
Superblock backups stored on blocks:
, , , , , , , , ,
, , Allocating group tables: done
Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.

5.7.根据提示进行操作,取消磁盘自检

root@zstest:~# tune2fs -c - /dev/vdb1
tune2fs 1.42. (-May-)
Setting maximal mount count to -

5.8.挂载分区到指定目录

mkdir -p /data
mount /dev/vdb1 /data

5.9.配置开机自动挂载分区

vim /etc/fstab
-------------------------------------------------------
# made by tssc
/dev/vdb1 /data ext4 defaults
-------------------------------------------------------

完毕,呵呵呵呵

linux磁盘分区格式化-fdisk命令工具的更多相关文章

  1. 【linux磁盘分区--格式化】fdisk,parted,mkfs.ext3

    磁盘分区完成后,一般就需要对分区进行格式化 磁盘分区命令主要有两个: fdisk :最大支持不超过2T分区: parted :支持GPT,适用于大容量分区: 分区指令的选择: 在RHEL系统上,用fd ...

  2. Linux磁盘分区/格式化/挂载(树莓派3挂载硬盘)

    [前言] 本文将要讲解的功能为Linux环境下对磁盘进行操作.包括分区.格式化.挂载外接移动存储设备等. 该文的写作背景为本人的树莓派需要外接一个固态硬盘作为存储设备,因此,便开始了一系列的折腾. [ ...

  3. Linux磁盘分区格式化和扩容

    Note:根据各系统上磁盘的类型不同,磁盘命名规则也会不同:例如/dev/xvd,/dev/sd,/dev/vd,/dev/hd 目录 磁盘格式化 MBR格式 GPT分区 磁盘扩容 MBR格式扩容 G ...

  4. linux硬盘分区和fdisk命令

    分区的几个概念 硬盘分区有三种,主分区.扩展分区.逻辑分区.一个硬盘主分区至少有1个,最多4个,扩展分区可以没有,最多1个.且主分区+扩展分区总共不能超过4个.逻辑分区可以有若干个.在windows下 ...

  5. Linux磁盘分区/格式化/挂载目录

    分区及挂载目录 以CentOS7.2为例,一般我们服务端应用部署前需要确认部署机的磁盘空间及挂载目录.操作如下: 如上图,如果操作系统是新装的,未挂盘的话需要先挂载盘.操作如下: fdisk -l # ...

  6. Linux基础------文件打包解包---tar命令,文件压缩解压---命令gzip,vim编辑器创建和编辑正文件,磁盘分区/格式化,软/硬链接

    作业一:1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) cat /etc/passwd /etc/group > /1.txt2) 将用户信息数据库文件和用户 ...

  7. Linux磁盘分区(一)之fdisk命令

    Linux磁盘分区(一)之fdisk命令转自:https://www.cnblogs.com/machangwei-8/p/10353683.html 一.fdisk 的介绍fdsik 能划分磁盘成为 ...

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

    fdisk 命令 linux磁盘分区管理 用途:观察硬盘之实体使用情形与分割硬盘用. 使用方法: 一.在 console 上输入 fdisk -l /dev/sda ,观察硬盘之实体使用情形. 二.在 ...

  9. Linux磁盘分区fdisk命令操作(简洁版)

    实例(环境为: CentOS Linux release 7.2.1511 (Core), 3.10.0-327.el7.x86_64) 选择要具体操作的第二块磁盘(linux下一切是文件形式对应): ...

随机推荐

  1. 认识与设计Serverless(一)

    一.什么是Serverless 定义:Serverless是一种无服务器的架构,区别于传统的Baas,SAAS,作为FAAS(函数即服务)而存在,函数由事件驱动触发并按需调用. 按需调用:区别于传统的 ...

  2. The same month as the adidas NMD Singapore is releasing

    Earlier this December 2017, the inaugural adidas NMD Singapore silhouette released in the first colo ...

  3. Horizon代码的层次结构

    Horizon中包含多个dashboard,每个dashboard又包含多个panel,每个panel有可以包含多个Tab.

  4. 2017-2018-2 20165207 实验三《敏捷开发与XP实践》实验报告

    java 实验三 实验报告 实验内容 代码规范 不规范的代码可能妨碍阅读,在粘贴下来老师在云班课中设置的提交点一的代码之后,我首先使用了IDEA中Code选项卡的Reformat Code功能规范代码 ...

  5. 微信小程序中公用内容

    微信小程序中各个页面调用公用的js 在util.js文件中 // 跳转哪里 function go(where) { wx.reLaunch({ url: where, }) } // 将方法暴露出去 ...

  6. 前端学习笔记之CSS属性设置

    CSS属性设置   阅读目录 一 字体属性 二 文本属性 三 背景属性 四 盒子模型 五 盒子模型各部分详解 一 字体属性 1.font-weight:文字粗细 取值 描述 normal 默认值,标准 ...

  7. 隐藏Apche、Nginx、PHP的版本号提高网站安全性

    隐藏Apache版本号 在apache配置文件httpd.conf中,加入以下代码 ServerTokens Prod ServerSignature Off 隐藏Nginx版本号 在nginx的配置 ...

  8. asp.net调用opencv类库,实现图像处理显示

    asp.net调用opencv类库,实现图像处理显示     ​      原理上来说,通过dll的调用,无论是asp.net还是winform都可以调用opencv及其类库.但是在实现的过程还是有许 ...

  9. 【前端】特效-Javascript实现购物页面图片放大效果

    实现效果 实现代码: <!DOCTYPE html> <html> <head> <title>购物图片放大</title> <met ...

  10. sed删除包含指定字符串的所有行

    1.以删除文件example.txt中包含字符串"=yes"的行为例,example.txt文件有以下内容: dadasdfsadf=yes=sds dsdadasdkfk dsd ...