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 ...
随机推荐
- Moleskine智能笔+专用本:写完随时传到手机
http://www.totiot.com/61805.html Moleskine公司生产的速写本和速写板一直是涂鸦爱好者和速记员们的首选.该公司还联合Adobe. Livescribe. Ever ...
- shiro实战系列(十三)之单元测试
由于我们已经涉及到了 Subject reference,我们知道 Subject 是“当前执行”用户的特定安全视图,且该 Subject 实 例绑定到一个线程来确保我们知道在线程执行期间的任何时间是 ...
- XML 读写(XmlDocument、XPathNavigator、XDocument)
内存中的 XML 处理 基于流的 XML 处理提供了最小的负载,但也只提供了最小的灵活性.在很多 XML 处理场景里,你不会在这么低的层次下工作. 对内存中的 XML 的处理则更加方便,但没有单一.标 ...
- redis集群遇到的坑
[root@insure src]# ./redis-cli -c -h 172.16.*.* -p 6370 输入密码: auth 密码 查看节点信息 172.16.*.*:6370> clu ...
- (三) DRF 序列化
一.单表的GET和POST: 使用serializers序列化,针对每一个表,需要单独写函数.一般会写在views.py里面,但是这样做,会导致整个文件代码过长.需要分离出来! 在app01(应用名) ...
- ansible role 理解
1.roles意为角色,主要用于封装playbook实现复用性.在ansible中,roles通过文件的组织结构来展现.
- Docker搭建Mysql容器
转载自:http://blog.csdn.net/Mungo/article/details/78521832?locationNum=9&fps=1 本文介绍如何使用docker迅速搭建My ...
- 大数据入门第二十五天——elasticsearch入门
一.概述 推荐路神的ES权威指南翻译:https://es.xiaoleilu.com/010_Intro/00_README.html 官网:https://www.elastic.co/cn/pr ...
- 《基于Arm实验箱的国密算法应用》课程设计 结题报告
<基于Arm实验箱的国密算法应用>课程设计 结题报告 小组成员姓名:20155206赵飞 20155220吴思其 20155234昝昕明 指导教师:娄嘉鹏 设计方案 题目要求:基于Arm实 ...
- Selenium-Switch与SelectApi接口详解
Switch 我们在UI自动化测试时,总会出现新建一个tab页面.弹出一个浏览器级别的弹框或者是出现一个iframe标签,这时我们用WebDriver提供的Api接口就无法处理这些情况了.需要用到Se ...