分区概念
1. 什么是分区: 起始扇区和结束扇区形成的区域就是分区(扇区是磁盘的最小单位)2. 分区信息:记录起始扇区和结束扇区的记录就是分区信息3. 主分区: ①分区信息存在于0磁柱0磁道0扇区的位置 ②能被格式化、能被挂载、能读写数据4. 扩展分区: ①分区信息存在于0磁柱0磁道0扇区的位置 ②不能被格式化、不能被挂载、不能读写数据 ③主要的作用是划分逻辑分区,原因是电脑的分区最多只能划分4个5. 逻辑分区 ①分区编号从5开始6. MBR分区:可以划分主分区、拓展分区、逻辑分区,最多划分4个主分区7. GPT分区:只能划分主分区,最多可以划分128个主分区
查看分区
lsblk ordisk -loutput:root@archiso ~ # fdisk -lDisk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectorsDisk model: VMware Virtual SUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/loop0: 556.19 MiB, 583208960 bytes, 1139080 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
建立硬盘分区
fdisk /dev/sda# 第一步:创建一个空的分区表g: create a new empty GPT partition table# 第二步:创建分区, 需要注意序号、First sector和Last sectorCommand (m for help): nPartition number (1-128, default 1):First sector (2048-268435422, default 2048):Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-268435422, default 268435422): +1G# 第三步:查看分区表Command (m for help): pDisk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectorsDisk model: VMware Virtual SUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: 701EBB8C-25D8-624E-8EE6-70D36D4AEF90Device Start End Sectors Size Type/dev/sda1 2048 2099199 2097152 1G Linux filesystem/dev/sda2 18876416 268435422 249559007 119G Linux filesystem/dev/sda3 2099200 18876415 16777216 8G Linux filesystemPartition table entries are not in disk order.# 第四步:将分区的类型改成正确的,# 例如efi分区的类型是EFI System, swap的分区是类型是Linux swapCommand (m for help): tPartition number (1-3, default 3): 1Partition type or alias (type L to list all): L 1 EFI System C12A7328-F81F-11D2-BA4B-00A0C93EC93B 2 MBR partition scheme 024DEE41-33E7-11D3-9D69-0008C781F39F 3 Intel Fast Flash D3BFE2DE-3DAF-11DF-BA40-E3A556D89593 ... ... 43 FreeBSD ZFS 516E7CBA-6ECF-11D6-8FF8-00022D09712BPartition type or alias (type L to list all): 1# 第五步:再次查看分区类型Command (m for help): pDisk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectorsDisk model: VMware Virtual SUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: 701EBB8C-25D8-624E-8EE6-70D36D4AEF90Device Start End Sectors Size Type/dev/sda1 2048 2099199 2097152 1G EFI System/dev/sda2 18876416 268435422 249559007 119G Linux filesystem/dev/sda3 2099200 18876415 16777216 8G Linux swap# 第六步:检查无错,即可保存分区Command (m for help): wThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.
格式化分区
# 根分区 /dev/root_partition 上创建一个 Ext4 文件系统
130 root@archiso ~ # mkfs.ext4 /dev/sda2
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 31194875 4k blocks and 7798784 inodes
Filesystem UUID: e6bc7b6c-1a5f-4818-a244-2a1a163f04e0
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done
# 交换分区 (例如 /dev/sda3),请使用 mkswap(8) 将其初始化
130 root@archiso ~ # mkswap /dev/sda3
Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)
no label, UUID=0907097c-ab50-4f82-ad9d-5d34ad84186b
# EFI 格式化
root@archiso ~ # mkfs.fat -F 32 /dev/sda1
mkfs.fat 4.1 (2017-01-24)
挂载
root@archiso ~ # df -h
Filesystem Size Used Avail Use% Mounted on
dev 2.4G 0 2.4G 0% /dev
run 2.4G 151M 2.2G 7% /run
/dev/sr0 679M 679M 0 100% /run/archiso/bootmnt
cowspace 256M 736K 256M 1% /run/archiso/cowspace
/dev/loop0 557M 557M 0 100% /run/archiso/sfs/airootfs
airootfs 256M 736K 256M 1% /
tmpfs 2.4G 0 2.4G 0% /dev/shm
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
tmpfs 2.4G 0 2.4G 0% /tmp
tmpfs 2.4G 2.1M 2.4G 1% /etc/pacman.d/gnupg
tmpfs 479M 0 479M 0% /run/user/0
# 挂载sda2
root@archiso ~ # mount /dev/sda2 /mnt
root@archiso ~ # df -h
Filesystem Size Used Avail Use% Mounted on
dev 2.4G 0 2.4G 0% /dev
run 2.4G 151M 2.2G 7% /run
/dev/sr0 679M 679M 0 100% /run/archiso/bootmnt
cowspace 256M 736K 256M 1% /run/archiso/cowspace
/dev/loop0 557M 557M 0 100% /run/archiso/sfs/airootfs
airootfs 256M 736K 256M 1% /
tmpfs 2.4G 0 2.4G 0% /dev/shm
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
tmpfs 2.4G 0 2.4G 0% /tmp
tmpfs 2.4G 2.1M 2.4G 1% /etc/pacman.d/gnupg
tmpfs 479M 0 479M 0% /run/user/0
/dev/sda2 117G 61M 111G 1% /mnt
# 挂载sda1
mount /dev/sda1 /mnt/boot
# 开启swap,相当于挂载
130 root@archiso ~ # swapon /dev/sda3