Linux命令(二十五) 磁盘管理命令(三) fdisk
一、fdisk命令介绍
fdisk 为Linux系统下的分区管理工具,类型windows下的 分区助手等工具软件。分过区装过操作系统的人都知道硬盘分区是必要和重要的。fdisk 的帮助如下所示:
[root@localhost hk]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
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 0xb7af7b64.
Command (m for help): h
h: unknown command
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
以上参数中常用参数说明:
d 删除存在的硬盘分区
n 添加分区
p 查看分区信息
w 保存分区变更信息
二、硬盘详细分区和挂载过程完整演示
# 先查看分区信息
[root@localhost hk]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c44fb
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
# 这里 /dev/sdb 为未使用的分区
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl-root: 39.7 GB, 39720058880 bytes, 77578240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
# 开始进行分区
[root@localhost hk]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
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 0xca00a0b9.
# m查看帮助
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
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system 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 (0 primary, 0 extended, 4 free)
e extended
# p 表示创建主分区,e 表示扩展分区
Select (default p): p
Partition number (1-4, default 1): 1 # 分区号选择1,也可以使用默认
First sector (2048-2097151, default 2048): # 起始节使用默认即可
Using default value 2048
# +400M 表示给分区分配400M 空间,默认分配磁盘所有剩余空间
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +400M
Partition 1 of type Linux and of size 400 MiB is set
# 使用 w 保存
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#查看分区情况
[root@localhost hk]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c44fb
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xca00a0b9
# 这是我们刚刚分配的分区
Device Boot Start End Blocks Id System
/dev/sdb1 2048 821247 409600 83 Linux
Disk /dev/mapper/cl-root: 39.7 GB, 39720058880 bytes, 77578240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
# 将新建的分区进行格式化,格式化为 ext3 格式
[root@localhost hk]# mkfs -t ext3 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
102400 inodes, 409600 blocks
20480 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
50 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
#创建挂载目录
[root@localhost hk]# mkdir /mnt/disk2
#将 /dev/sdb1 挂载到 /mnt/disk2
[root@localhost hk]# mount /dev/sdb1 /mnt/disk2/
# 查看分区已经正常挂载
[root@localhost hk]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 463M 0 463M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 13M 475M 3% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/mapper/cl-root 37G 3.6G 34G 10% /
/dev/sda1 1014M 246M 769M 25% /boot
tmpfs 98M 0 98M 0% /run/user/1000
/dev/sdb1 380M 2.3M 358M 1% /mnt/disk2 #这里可以看见分区已经正常挂载
# 编辑系统分区表 /etc/fstab 实现开机自动挂载
[root@localhost hk]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Nov 14 20:59:37 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/cl-root / xfs defaults 0 0
UUID=03cf4f74-827e-40a1-a67f-2227be43dee7 /boot xfs defaults 0 0
/dev/mapper/cl-swap swap swap defaults 0 0
/dev/sdb1 /mnt/disk2 ext3 defaults 0 0 # 将分区信息加到 /etc/fstab 文件末尾,保存并退出
# 切换到分区挂载的目录中,创建文件测试分区是否可用
[root@localhost hk]# cd /mnt/disk2/
[root@localhost disk2]# touch test.txt
[root@localhost disk2]# ls
lost+found test.txt
Linux命令(二十五) 磁盘管理命令(三) fdisk的更多相关文章
- Linux命令(二十四) 磁盘管理命令(二) mkfs,mount
一.格式化文件系统 mkfs 当完成硬盘分区以后要进行硬盘的格式化,mkfs系列对应的命令用于将硬盘格式化为指定格式的文件系统.mkfs 本身并不执行建立文件系统的工作,而是去调用相关的程序来执行.例 ...
- Linux命令(二十六) 用户管理命令
一.添加用户 useradd useradd 命令用于创建新用户,格式为useradd [选项] 用户名. 可以使用 useradd 命令创建用户帐户,使用该命令创建账户时,默认的用户目录在 /hom ...
- Linux学习之CentOS(十五)----磁盘管理之 启动挂载(转)
启动挂载 /etc/fstab 及 /etc/mtab 刚刚上面说了许多,那么可不可以在启动的时候就将我要的文件系统都挂好呢?这样我就不需要每次进入 Linux 系统都还要在挂载一次呀!当然可以啰!那 ...
- Linux系统下常用的磁盘管理命令——du / df / fdisk / mount / xxd
之前使用虚拟机体验Linux操作系统的使用,一般使用默认的磁盘分区设置,也很少涉及磁盘管理操作,且总有删除重装作为后盾.在安装Ubuntu双系统后,在使用过程中遇到了磁盘分区不合理导致的/boot分区 ...
- 攻城狮在路上(叁)Linux(二十八)--- 打包命令:tar
首先介绍一下tar打包命令的基本格式,下面的三种之间不能混淆. tar [-j|-z] [cv] [-f 新文件名] file1 file2 ...; tar [-j|-z] [tv] [-f 新文件 ...
- 性能测试二十五:redis-cli 命令总结
常用命令dbsize:查看redis中的kv数量 keys *:查看redis中所有的keyset key_1 v_1:新增一个key_1,包含v_1get key_1:查看key_1中的内容del ...
- Pytest 学习(二十五)- allure 命令行参数【转】
先看看 allure 命令的帮助文档 cmd 敲 allure -h allure 命令的语法格式 allure [options] [command] [command options] optio ...
- 攻城狮在路上(叁)Linux(二十五)--- linux内存交换空间(swap)的构建
swap的功能是应付物理内存不足的状况,用硬盘来暂时放置内存中的信息. 对于一般主机,物理内存都差不多够用,所以也就不会用到swap,但是对于服务器而言,当遇到大量网络请求时或许就会用到. 当swap ...
- Linux下磁盘管理命令df与du
Linux下磁盘管理命令df与du 对磁盘进行查看和控制的两个linux命令,df和du. 一.du命令 首先看一下du的help说明: [root@misdwh opt]# du --help ...
随机推荐
- 通过HttpClient调用服务
/** * 通过HttpClient调用服务 * * @param url 路径 * data json数据 * @return */ //post请求方法public String sendItsm ...
- Arduino入门笔记(8):利用12864和ADXL345学习重力感应控制
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.Arduino UNO板 https://item.t ...
- jqgrid 选中行触发编辑,切换下一行时验证和异步保存上一行数据
有时,我们需要批量修改或填写一些相似的数据.可以以jqgrid表来显示,可能的效果如下: 选中触发行编辑参考:jqgrid 单击行启用行编辑,切换行保存原编辑行 本文主要说说验证和异步保存上一条数据的 ...
- setInterval() 方法应用
setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式. setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭.由 s ...
- OO——电梯作业总结
目录 电梯作业总结 程序结构与复杂度的分析 第一次作业 第二次作业 第三次作业 程序BUG的分析 互测 自动评测 有效性 总结 电梯作业总结 程序结构与复杂度的分析 第一次作业 1.设计思路 第一次作 ...
- 牛客练习赛44 B题 (思维)
链接:https://ac.nowcoder.com/acm/contest/634/B 来源:牛客网 给出n条线段,第i条线段的长度为ai, 每次可以从第i条线段的j位置跳到第i + 1条线段的j+ ...
- mfc CListCtrl 报表格式
知识点: CListCtrl报表格式 CListCtrl报表格式添加列 CListCtrl报表格式添加行 CListCtrl报表格式设置单元格 一.CListCtrl报表格式 类名:SysListVi ...
- mfc CListCtrl
了解CListCtrl属性 了解CListCtrl常用成员函数 代码示例 一.CListCtrl常用属性 View:视图方式;.大(标准)图标2.小图标3.列表4.报表 Sort:排序; No Scr ...
- 【调试】Core Dump是什么?Linux下如何正确永久开启?
[调试]Core Dump是什么?Linux下如何正确永久开启?
- Python中类和对象在内存中是如何保存?
类以及类中的方法在内存中只有一份,而根据类创建的每一个对象都在内存中需要存一份,大致如下图: 如上图所示,根据类创建对象时,对象中除了封装 name 和 age 的值之外,还会保存一个类对象指针,该值 ...