规划硬盘中的分区
• Fdisk:只支持mbr的启动方式,不支持4tb以上硬盘的划分,也就是即使给它一个10tb的硬盘,有6tb是它看不见的
• Parted
• gdisk: 支持efi,mbr,支持4tb以上硬盘的划分
在虚拟机页面右键设置,CD/DVD SATA,添加,硬盘,添加好了以后右下角会多出一个硬盘
lsblk
或者fdisk -l
可以看当前分区的状况
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 4G 0 part /home
├─sda3 8:3 0 1G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 14G 0 part /
sdb 8:16 0 20G 0 disk
sr0 11:0 1 3.8G 0 rom /run/media/root/RHEL-7.4 Server.x86_64
#这里的sdb是新添加进来的硬盘,如果再添加会是sdc,以此类推
fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000d1ef1
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 10487807 4194304 83 Linux
/dev/sda3 10487808 12584959 1048576 82 Linux swap / Solaris
/dev/sda4 12584960 41943039 14679040 5 Extended
/dev/sda5 12587008 41943039 14678016 83 Linux
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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
fdisk /dev/sdb
功能:分区,后面跟绝对路径
m进入help看下面这些参数的含义:
d: delete a partition
l: list known partition types
m: print this menu
n: add a new partition
p: print the partition table
q: quit without saving changes
t: change a partition's system id
w: write table to disk and exit
☆如果误删除了分区,只要q退出去不保存里面的分区不会被删除

这里1,2,3为主分区,4为扩展分区。扩展分区里面想分多少个分区都可以
p #打印分区列表
Device Boot Start End Blocks Id System
#发现是空的,说明没有进行任何的分区
n #新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free) 主分区
#一个硬盘只能划分为4个主分区,如果再想多划分,需要设置扩展分区。这样扩展分区也相当于一个硬盘,里面还可以继续划分
e extended 扩展分区
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1G
#要多大空间写+空间大小即可
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (2099200-41943039, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-41943039, default 41943039): +2G
Partition 2 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (6293504-41943039, default 6293504):
Using default value 6293504
Last sector, +sectors or +size{K,M,G} (6293504-41943039, default 41943039): +2G
Partition 3 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xa2f9123c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 6293503 2097152 83 Linux
/dev/sdb3 6293504 10487807 2097152 83 Linux
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e):
Using default response e
Selected partition 4
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039):
Using default value 41943039
Partition 4 of type Extended and of size 15 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xa2f9123c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 6293503 2097152 83 Linux
/dev/sdb3 6293504 10487807 2097152 83 Linux
/dev/sdb4 10487808 41943039 15727616 5 Extended
# 主分区的ID是83,System是Linux。扩展分区的ID是5,System是Extended
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (10489856-41943039, default 10489856):
Using default value 10489856
Last sector, +sectors or +size{K,M,G} (10489856-41943039, default 41943039): +3G
Partition 5 of type Linux and of size 3 GiB is set
# 这时再新建的时候直接就是在扩展分区4里建主分区
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (16783360-41943039, default 16783360):
Using default value 16783360
Last sector, +sectors or +size{K,M,G} (16783360-41943039, default 41943039):
Using default value 41943039
Partition 6 of type Linux and of size 12 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xa2f9123c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 6293503 2097152 83 Linux
/dev/sdb3 6293504 10487807 2097152 83 Linux
/dev/sdb4 10487808 41943039 15727616 5 Extended
/dev/sdb5 10489856 16781311 3145728 83 Linux
/dev/sdb6 16783360 41943039 12579840 83 Linux
# 这时可用的分区只有5个,sdb4的空间是属于sdb5和sdb6的,因此sdb4是不可用的
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 4G 0 part /home
├─sda3 8:3 0 1G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 14G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 1G 0 part
├─sdb2 8:18 0 2G 0 part
├─sdb3 8:19 0 2G 0 part
├─sdb4 8:20 0 1K 0 part
├─sdb5 8:21 0 3G 0 part
└─sdb6 8:22 0 12G 0 part
sr0 11:0 1 3.8G 0 rom /run/media/root/RHEL-7.4 Server.x86_64
#sdb的部分是新创建出来的分区
❉ 一块硬盘买到手需要进行分区→再进行格式化才可以进行使用
格式化其实就是创建文件系统。文件系统标识自己系统的性能
文件系统是操作系统用于明确存储设备或分区上的文件的方法和数据结构,即在存储设备上组织文件的方法。文件系统由三部分组成:文件系统的接口,对对象操纵和管理的软件集合,对象及属性。从系统角度来看,文件系统是对文件存储设备的空间进行组织和分配,负责文件存储并对文件进行保护和检索的系统。它负责为用户建立文件,存入,读出,修改,转储文件,控制文件的存取,当用户不再使用时撤销文件等。一个分区或磁盘在作为文件系统使用前,需要初始化,并将记录数据结构写到磁盘上,这个过程就叫建立文件系统。
硬盘是用来存储数据的,可以将其想象成存储衣物的柜子。分区相当于把一个大柜子按照要求分割成几个小柜子;格式化好比在每个小柜子中打入隔断,决定每个隔断的大小和位置,然后在柜门上贴上标签,标签中写清楚每件依附保存的隔断的位置和这件衣服的一些特性(比如衣服是谁的,衣服的颜色大小等)。因为不同的操作系统,管理系统中文件的方式也不相同,因此为了使硬盘有效存放当前系统中的文件数据,就需要将硬盘进行格式化。
Linux识别ext 1,2,3,4,xfs,vfat
ext1不识别1024M以上,1和2都没有人用了
ext3 有日志,通过日志可以做数据恢复
ext是分时操作系统的基础
xfs 对大数据处理很有利,能存储的文件的数量很大
格式化处理:
mkfs.ext3 /dev/sdb1
mkfs.xfs /dev/sdb2
mkfs.vfat /dev/sdb3
1.将sdb1分区设置成ext3文件系统,sdb2分区设置成xfs文件系统,sdb3设置成vfat文件系统。后面跟绝对路径,不能只跟/dev/sdb,需要跟分区名
2.设置成不同的文件系统回显不一样
lsblk -f
或者blkid
可以查看所有分区的文件系统类型
网友评论