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 ...
随机推荐
- pytorch的一些函数
1.tensor的view函数: view(*args) → Tensor 返回一个有相同数据但大小不同的tensor. 返回的tensor必须有与原tensor相同的数据和相同数目的元素,但可以有不 ...
- Mysql 调优2个语句
一.explain 语句 查看语句的执行计划 二.查看具体每一步耗时 .; .执行SQL .show profiles; 获取2执行SQL的query_id .show profile for que ...
- DNS主从复制及子域(三)
主从DNS 主辅DNS服务器数据同步的过程,首先master DNS服务器每 次修改完成并重启服务后,将传送notify给所有的Slave DNS服务器. Slave DNS服务器将查询Master服 ...
- Docker学习2-虚拟化
虚拟化就是由位于下层的软件模块,根据上层的软件模块的期待,抽象(虚拟)出一个虚拟的软件或硬件模块,使上一层软件直接运行在这个与自己期待完全一致的虚拟环境上.从这个意义上来看,虚拟化既可以是软件层的抽象 ...
- Oracle 表删除操作
删除表内容(dml):delete from 删除表结构(ddl):drop table xx 清空表(ddl):truncate table 清空整张表,不能回滚,不会产生大量日志文件: 表空间会得 ...
- Linux系统扫描技术及安全防范
1.概述 一.主机扫描 二.路由扫描 三.批量服务扫描 四.linux防范恶意扫描安全策略 一个典型的网络安全事件 ·案例:通过网络扫描方式获取某运营商核心设备管理权限 step01:通过tracer ...
- [HNOI2012]矿场搭建 BZOJ2730 点双+结论
Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出口,使得无论哪一 ...
- English_word_learning
这次报名参加了学院的21天打卡活动,说实话,也是想给自己一个积累的平台. 毕竟,真的有时候感觉挺弱的 有的人用了一年考完了四六级,而有人却用四年还未考完. 听到有一位学长因为自己的四级成绩没有达到48 ...
- Android Notification的使用 - z
http://blog.csdn.net/new_one_object/article/details/55511253 另,博主其它文章也很好
- Android开发——Android进程保活招式大全
)前台进程(Foreground process),即用户当前操作所必需的进程,通常数量不多.举例如下: //拥有用户正在交互的 Activity(已调用 onResume()) //拥有某个 Ser ...