fdisk

  常用的磁盘分区工具,受mbr分区表的限制,只能给小于2TB的磁盘划分分区,如果使用fdisk对大于2TB的磁盘进行分区,虽然可以分区,但只能识别2T的空间,一般使用parted分区工具

  -l  # 显示所有磁盘分区信息

[root@puppet105 ~]# fdisk -l
Disk /dev/sda: 64.4 GB, bytes, sectors    # 磁盘/dev/sda 的大小
Units = sectors of * = bytes                  # 每个柱面大小512字节
Sector size (logical/physical): bytes / bytes        # 每个扇区的字节数
I/O size (minimum/optimal): bytes / bytes          # 每次读写的字节数
Disk label type: dos
Disk identifier: 0x000a9f20

Device Boot Start End Blocks Id System
/dev/sda1 * Linux
/dev/sda2 Linux swap / Solaris
/dev/sda3 8e Linux LVM Disk /dev/mapper/centos_centos7-root: 62.3 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes

    Device  # 分区名称

  Boot    # 启动分区,用*表示的是启动分区

  Start    # 表示开始的柱面

  End    # 表示结束的柱面

  Blocks    # block块数量

  Id      # 分区类型ID

  System    # 分区类型

  磁盘分区步骤

# 加了一块20G的磁盘
[root@centos7 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes # 查看分区前设备状态 [root@centos7 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb # 开始分区
[root@centos7 ~]# fdisk /dev/sdb        # 后面直接跟设备文件,或者-cu参数
Welcome to fdisk (util-linux 2.23.). 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
Building a new DOS disklabel with disk identifier 0xfe05c2f7. Command (m for help): m             # 输入m是帮助菜单
Command action
a toggle a bootable flag           # 设置引导扇区
b edit bsd disklabel              # 编辑bsd卷标
c toggle the dos compatibility flag      # 设置dos兼容扇区
d delete a partition                # 删除一个分区
g create a new empty GPT partition table    # 创建空白gpt分区表
G create an IRIX (SGI) partition table      # 创建IRIX分区表
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      # 创建新的空sun卷标
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): n                # 创建一个新分区
Partition type:
p primary ( primary, extended, free)  # 主分区,只能创建4个,第五个必须为扩展分区
e extended                      # 扩展分区
Select (default p): p                  # 创建主分区标识
Partition number (-, default ): 1          #编号(1-4)
First sector (-, default ):     # 起始位置,直接回车,默认是1
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ): +5G # 设置主分区大小
Partition of type Linux and of size GiB is set Command (m for help): n              # 创建一个新分区
Partition type:
p primary ( primary, extended, free)
e extended                    # 创建一个扩展分区
Select (default p): e
Partition number (-, default ): 2        # 编号2
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ): +5G  # 也是5G的容量
Partition of type Extended and of size GiB is set Command (m for help): n              # 创建一个新分区
Partition type:
p primary ( primary, extended, free)  # 此时因为创建了扩展分区,所以只剩下主分区和逻辑分区了
l logical (numbered from )
Select (default p): l                # 创建逻辑分区
Adding logical partition 5              # 逻辑分区编号必须是从5开始,默认的就是5
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ): +2G  # 给2G的容量
Partition of type Linux and of size GiB is set Command (m for help): p                # 打印创建的分区列表 Disk /dev/sdb: 21.5 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0xfe05c2f7 Device Boot Start End Blocks Id System
/dev/sdb1 Linux
/dev/sdb2 Extended
/dev/sdb5 Linux Command (m for help): w                # 保存
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks. [root@centos7 ~]# ls /dev/sdb*            # 查看设备状态
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 [root@centos7 ~]# partprobe /dev/sdb        # 通知内核分区表已经更改
[root@centos7 ~]# mkfs.ext4 /dev/sdb1        #格式化文件系统
mke2fs 1.42. (-Dec-)  
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , Allocating group tables: done
Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done [root@centos7 ~]# tune2fs -c 0 -i 0 /dev/sdb1    # 此命令可以米面磁盘过载自动检查
tune2fs 1.42. (-Dec-)
Setting maximal mount count to [root@centos7 ~]# df -h            # 格式化后的磁盘需要挂载才能使用,此处未显示已经创建的磁盘
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 98G .7G 97G % /
devtmpfs 901M 901M % /dev
tmpfs 911M 911M % /dev/shm
tmpfs 911M 9.5M 902M % /run
tmpfs 911M 911M % /sys/fs/cgroup
/dev/sda1 1014M 135M 880M % /boot
tmpfs 183M 183M % /run/user/
[root@centos7 ~]# mount /dev/sdb1 /mnt    # 挂载磁盘分区
[root@centos7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 98G .7G 97G % /
devtmpfs 901M 901M % /dev
tmpfs 911M 911M % /dev/shm
tmpfs 911M 9.5M 902M % /run
tmpfs 911M 911M % /sys/fs/cgroup
/dev/sda1 1014M 135M 880M % /boot
tmpfs 183M 183M % /run/user/
/dev/sdb1 .8G 20M .6G % /mnt      # 磁盘已经挂载上去了   
[root@centos7 ~]# vi /etc/fstab      # 开机启动有两种方式,此为第一种,另外一种 echo "mount /dev/sdb1 /mnt" >>/etc/rc.local
#
# /etc/fstab
# Created by anaconda on Fri Oct ::
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(), findfs(), mount() and/or blkid() for more info
#
UUID=fc662da3-4f5b-480b-bae9-cc9c8698742a / xfs defaults
UUID=e1b67cc9-08ff-47e7-b1e9-3ce2d9ee5eb6 /boot xfs defaults
UUID=47b26d55--48e1-adba-91fe4f420b03 swap swap defaults
/dev/sdb1 /mnt ext4 defaults

  # 关于LVM进行分区,会单独写博文

  fdisk非交互式分区(批量创建)

[root@centos7 ~]# fdisk /dev/sdb<<EOF
> n
> p
>
>
> +2G
> p
> w
> EOF
Welcome to fdisk (util-linux 2.23.). Changes will remain in memory only, until you decide to write them.
Be careful before using the write command. Command (m for help): Partition type:
p primary ( primary, extended, free)
l logical (numbered from )
Select (default p): Partition number (,, default ): First sector (-, default ): Using default value
Last sector, +sectors or +size{K,M,G} (-, default ): Partition of type Linux and of size GiB is set Command (m for help):
Disk /dev/sdb: 21.5 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0xfe05c2f7 Device Boot Start End Blocks Id System
/dev/sdb1 Linux
/dev/sdb2 Extended
/dev/sdb3 Linux
/dev/sdb5 Linux Command (m for help): The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error : Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe() or kpartx()
Syncing disks.

partprobe

  在硬盘分区发生改变时,更新Linux内核中的硬盘分区表数据。不需要重启系统就能生效

tnue2fs

  调整或者查看ex2/ex3/3x4文件系统的参数,如可以调整文件系统开机自检周期,用的较少

  -c  # 设置强制自检的挂载次数,没挂载一次计数就会加1,超过次数就会强制自检,设置0或-1,此功能关闭

  -i  # 强制自检的时间间隔

  -l  # 查案文件系统信息

parted

 大于2TB磁盘的分区命令,需要将磁盘转换为GPT格式

   -l  # 小时需哦有磁盘分区的信息

    -h  # 查看帮助

[root@centos7 ~]# parted
GNU Parted 3.1    # 版本号
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) h # 查看帮助

align-check TYPE N  #检查磁盘分区,type分为min/opt,N表示磁盘分区号
mklabel,mktable LABEL-TYPE # 创建分区表
table)    
mkpart PART-TYPE [FS-TYPE] START END # 创建分区
name NUMBER NAME # 为分区命名
print [devices|free|list,all|NUMBER] # 显示分区表信息,简写p
quit # 退出 resizepart NUMBER END # 重设分区大小
rm NUMBER # 删除编号number的分区
select DEVICE #选择要编辑的设备 set NUMBER FLAG STATE # 改变分区标志
toggle [NUMBER [FLAG]] # 设置分区标志
unit UNIT   # 设置默认单位 copyright information of GNU Parted
(parted) quit

  分区步骤,本次使用20GB来做演示

[root@centos7 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb
[root@centos7 ~]# parted /dev/sdb      # 开始分区,交互式
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt              # 为sdb磁盘创建GPT分区表,大于2T必须执行此步骤,fdisk 是mdos分区表 (parted) mkpart primary 5G    # 创建主分区
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore     # 忽略掉
(parted) p #显示分区表
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: .7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: Number Start End Size File system Name Flags
.4kB 5000MB 5000MB primary    #主分区创建完毕,创建完成之后系统会自动识别, (parted) mkpart logical 5G 10G                  # 创建逻辑分区
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: .7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: Number Start End Size File system Name Flags
.4kB 5000MB 5000MB primary
5001MB .0GB 5000MB logical (parted) quit
Information: You may need to update /etc/fstab. [root@centos7 ~]# ls /dev/sd*        # 查看分区的设备
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdb1 /dev/sdb2 # 后面的格式化分区,挂载,开机自动挂载和fdisk分区步骤一样,因为parted在创建分区时,会自动让内核识别,所以不用使用partprobe命令

  # fdisk非交互式分区(批量创建)

  parted /dev/sdb mklabel gpt yes

  parted /dev/sdb mkpart primary 0 5G

  parted /dev/sdb p

mkfs

  创建Linux文件系统,只有格式化创建文件系统后,才能存储数据

  -t  #指定要创建的文件系统类型

  -c  # 创建文件系统时检查磁盘坏块

  -v  # 显示详细信息

  

[root@centos7 ~]# mkfs    # 此命令是一个前端命令,会通过-t参数调用mkfs.fstype 因此可以直接使用mkfs.ext4创建
mkfs mkfs.cramfs mkfs.ext3 mkfs.minix
mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.xfs

dumpe2fs

  用于导出ext2/ext3/ext4文件系统内部的相关信息,如,文件系统的组成bao包含超级块,块组,inode,bock等信息

  -b  # 打印文件系统中预留的块信息

  -h  # 进现实超级块信息

  -i  # 从指定的文件系统影像文件中读取文件的系统信息

  -x  # 以16进制格式打印信息块成员

resize2fs

  用于扩容或收缩未挂载的ext2,3,4文件系统,在2.6内核版本或者更高,还支持在线扩容已挂在的文件系统,常用开针对LVM扩容后的分区使用,对于fdisk和parted应事先规划好

  -p  # 打印完成任务的进度条

  -r  # 强制执行操作

 

最新文章

  1. css3中的animation
  2. 【EF 2】浅谈ADO数据模型生成串(二):数据库连接串分析
  3. 我的VS2013中,用Ado.net给SQLParameter赋值的时候,当赋值null的时候,生成的sql语句是default
  4. uniform 中checkbox通过jquery 选中
  5. CLR via C# 异常管理读书笔记
  6. 关于新feature对应的增加一个新的测试单子(QA)和文档单子(Doucmentation)的步骤
  7. 关于wtl的一个实验
  8. A5营销访谈:卢松松和你聊新媒体运营那些事
  9. 十二、享元(Flyweight)模式--结构模式(Structural Pattern)
  10. 全国计算机等级考试二级教程-C语言程序设计_第3章_顺序结构
  11. leetcode first bad version python
  12. Material Master
  13. iframe滚动条问题:显示/隐藏滚动条
  14. [转]ps命令详解
  15. 用ajax对数据进行删除和查看
  16. 一点不懂到小白的linux系统运维经历分享
  17. DevExpress控件使用方法:第一篇 gridControl详解
  18. 在javascript中substr和substring的区别是什么
  19. MySQL 5.7.18 解压版安装
  20. HTML5 位运算符

热门文章

  1. MapReduce:Shuffle过程详解
  2. 图片按钮(imageButton)
  3. Struts2中 Path (getContextPath与basePath)
  4. Promise 初步
  5. ubuntu安装zeromq
  6. python 基础-----数字,字符串,if while 循环 数据类型的转换简单介绍
  7. iOS设计模式 - 责任链
  8. Linux xargs命令详解
  9. linux之安装nali本地解析IP归属
  10. 2018.08.31 10:57 swift 学习心得