什么是分区?
分区是将一个硬盘驱动器分成若干个逻辑驱动器,分区是把硬盘连续的区块当做一个独立的磁硬使用。分区表是一个硬盘分区的索引,分区的信息都会写进分区表。
为什么要有多个分区?
防止数据丢失:如果系统只有一个分区,那么这个分区损坏,用户将会丢失所的有数据。
增加磁盘空间使用效率:可以用不同的区块大小来格式化分区,如果有很多1K的文件,而硬盘分区区块大小为4K,那么每存储一个文件将会浪费3K空间。这时我们需要取这些文件大小的平均值进行区块大小的划分。
数据激增到极限不会引起系统挂起:将用户数据和系统数据分开,可以避免用户数据填满整个硬盘,引起的系挂起。
分区工具fdisk用法介绍
- fdisk命令参数介绍
- p、打印分区表。
- n、新建一个新分区。
- d、删除一个分区。
- q、退出不保存。
- w、把分区写进分区表,保存并退出。
开始分区
给虚拟机挂载了一块硬盘
用命令lsblk
查看磁盘是否挂载
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
├─vda1 253:1 0 4G 0 part [SWAP]
└─vda2 253:2 0 36G 0 part /
vdb 253:16 0 100G 0 disk
可以看到 vdb 没有进行分区
fdisk /dev/vdb
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 0xd698e7e1.
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 crea