Article directory
Disk partition steps
Linux使用使用磁盘步骤
加硬盘->分区->格式化->挂载
Linux删除分区步骤
删除添加在挂载配置文件的内容,取消挂载之后再删除分区(在主磁盘中)
View existing disk usage
df -h
显示已挂载磁盘使用情况
lsblk
列出所有可用的磁盘
fdisk -l
查看当前所有磁盘的分区情况
Partition the disk
fdisk /dev/vdb #进入分区模式 (fdisk + 你自己的目标磁盘)
d delete a partition # 删除一个分区
l list known partition types # 列出当前支持的分区种类
n add a new partition # 添加一个新的分区
p print the partition table # 列出当前状态的所有分区
t change a partition's system id # 修改分区系统ID,类型;无意义
输入 n 创建一个分区
输入 p 创建一个主分区
输入 e 创建一个扩展分区
我们选择创建主分区
然后输入分区区号, 直接回车会默认按序号创建
然后选择分区开始的位置, 直接回车
然后选择分区的结束位置, 我们可以直接输入目标的磁盘大小
这里我选择创建50G的分区
然后输入 w 保存分区
Check available partitions again
df -h
查看发现没有新创建的分区, 因为还没有挂载
Screenshots of complete steps
Format disk
LInux分区只有格式化之后才能使用磁盘,不格式化是无法使用的
Linux分区格式化之后才会变成文件系统,格式化就相当于给对应的分区做了一个文件系统
Linux常用的文件系统有ext系列的:如ext2、ext3、ext4;之后还有xfs格式;btrfs格式(性能可以的)
另外ext4的文件系统要求单个文件大小不能超过1T
xfs的文件系统单个文件支持16TB;每个文件系统量最大支持8EB
从centos7和红帽7开始,默认安装文件系统是xfs
format command
使用 mkfs 来进行分区格式化
mkfs -t ext4 /dev/vdb1 # ext4 是文件系统类型, /dev/vdb1 是你的分区名称
如果执行 mkfs 时报错
则需要 执行一下 partprobe 命令
mkfs.ext4 is equivalent to mkfs -t ext4
Mount partition
将分区挂载到指定的文件夹,
我挂载到 var 目录
View mounted disk usage
partition to successfully mount
Automount
上面挂载完成后实现的是临时挂载, 服务器重启之后依然需要手动挂载一遍
要想永久挂载,则需要将挂载信息写入/etc/fstab配置文件中
另外/etc/fstab配置文件一旦被删除或者里面参数错误,会导致系统无法启动,因此写入信息时候切记好好看
修改完成后执行mount -a或reboot即可生效
注意: 建议最好备份一份原件,以防遭遇不测
cp /etc/fstab /etc/fstab.bak
vim /etc/fstab 或者 vi /etc/fstab
配置文件内容说明:
第一列: 文件系统所在分区路径
第二列: 文件系统的挂载点
第三列: 文件系统的类型
第四列: 挂载参数
第五列和第六列写0
一些特殊文件系统,才需要将后两列改为非0
使用 lsblk -f 命令查看磁盘分区的uuid
Extended and logical partitions
When we go to the second step of disk partitioning, the system will give me a choice by default.
Disk partitioning can only be divided into four partitions.
When it comes to the first three partitions, the default partition type is p (primary partition).
When it comes to the fourth partition, , the default partition type is e (extended partition)
. After we create the extended partition, the extended partition cannot be used directly. You
need to create a logical partition again in the extended partition before it can be used.
The logical partition can be formatted like the primary partition. Then mount