本文主要讲述使用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. maven解决“Could not calculate build plan”问题

    错误提示如下:(eclipse+maven) Could not calculate build plan: Failure to transfer org.apache.maven.plugins: ...

  2. sysbench 0.4.12安装

    前提:mysql已安装完成,请参考http://www.cnblogs.com/lizhi221/p/6813907.html   安装依赖环境包: yum install -y bzr yum in ...

  3. python16_day28【crm只读、权限、堡垒机】

    一.只读 二.万能权限 三.堡垒机

  4. 自定义 Repository 方法

    为某一个 Repository 上添加自定义方法 步骤: 定义一个接口: 声明要添加的, 并自实现的方法 提供该接口的实现类: 类名需在要声明的 Repository 后添加 Impl, 并实现方法 ...

  5. SpringData_PagingAndSortingRepository接口

    该接口提供了分页与排序功能 Iterable<T> findAll(Sort sort); //排序 Page<T> findAll(Pageable pageable); / ...

  6. SpringData_Repository接口概述

    Repository 接口是 Spring Data 的一个核心接口,它不提供任何方法,开发者需要在自己定义的接口中声明需要的方法  public interface Repository<T, ...

  7. some tools

    mac alfred http://www.cnblogs.com/chijianqiang/p/alfred.html

  8. windows live writer backup

    windows live writer backup备份:http://wlwbackup.codeplex.com/

  9. ng-深度学习-课程笔记-2: 神经网络中的逻辑回归(Week2)

    1 二分类( Binary Classification ) 逻辑回归是一个二分类算法.下面是一个二分类的例子,输入一张图片,判断是不是猫. 输入x是64*64*3的像素矩阵,n或者nx代表特征x的数 ...

  10. SQL学习笔记四(补充-2-1)之MySQL SQL查询作业答案

    阅读目录 一 题目 二 答案 一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成绩大于八十分的同学的姓名 ...