一、添加新硬盘添加三个类型的硬盘每个类型硬盘内存不一样方便知道二、分区fdisk2.1fdisk指令作用指令作用a调整磁盘的启动分区p显示当权磁盘分区信息d删除磁盘分区t更改分区类型l显示所有支持的分区类型u切换分区大小的显示单位m查看所有指令的帮助信息n创建新分区q不保存更改退出 fdisk 命令w保存更改退出 fdisk 命令g新建一个空的 GPT 分区表o新建一个空的 DOSMBR分区表2.1.1。MBR格式对 /dev/sda 磁盘进行分区PPPElll容量自定[rootZXY ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.40.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. Created a new DOS (MBR) disklabel with disk identifier 0x990495ff. Command (m for help): o # 新建 MBR 分区表 Created a new DOS (MBR) disklabel with disk identifier 0xc3b2ba40. Command (m for help): n # 新建分区 Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p # p主分区 e扩展分区 Partition number (1-4, default 1): # 分区号 First sector (2048-44040191, default 2048): # 起始扇区号 Last sector, /-sectors or /-size{K,M,G,T,P} (2048-44040191, default 44040191): 2G # 结束扇区号 Created a new partition 1 of type Linux and of size 2 GiB. Command (m for help): n # 新建 Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p # 主分区 Partition number (2-4, default 2): # 默认编号 First sector (4196352-44040191, default 4196352): Last sector, /-sectors or /-size{K,M,G,T,P} (4196352-44040191, default 44040191): 2G Created a new partition 2 of type Linux and of size 2 GiB. Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (3,4, default 3): First sector (8390656-44040191, default 8390656): Last sector, /-sectors or /-size{K,M,G,T,P} (8390656-44040191, default 44040191): 3G Created a new partition 3 of type Linux and of size 3 GiB. Command (m for help): n Partition type p primary (3 primary, 0 extended, 1 free) e extended (container for logical partitions) Select (default e): e # 扩展分区 Selected partition 4 First sector (14682112-44040191, default 14682112): Last sector, /-sectors or /-size{K,M,G,T,P} (14682112-44040191, default 44040191): # 结束扇区号直接回车表示默认直接把剩余所有空间分配给该分区 Created a new partition 4 of type Extended and of size 14 GiB. Command (m for help): n All primary partitions are in use. Adding logical partition 5 First sector (14684160-44040191, default 14684160): Last sector, /-sectors or /-size{K,M,G,T,P} (14684160-44040191, default 44040191): 3G Created a new partition 5 of type Linux and of size 3 GiB. Command (m for help): n All primary partitions are in use. Adding logical partition 6 First sector (20977664-44040191, default 20977664): Last sector, /-sectors or /-size{K,M,G,T,P} (20977664-44040191, default 44040191): 3G Created a new partition 6 of type Linux and of size 3 GiB. Command (m for help): n All primary partitions are in use. Adding logical partition 7 First sector (27271168-44040191, default 27271168): Last sector, /-sectors or /-size{K,M,G,T,P} (27271168-44040191, default 44040191): Created a new partition 7 of type Linux and of size 8 GiB. Command (m for help): p # 打印当前分区信息 Disk /dev/sda: 21 GiB, 22548578304 bytes, 44040192 sectors Disk model: VMware Virtual S Units: sectors of 1 * 512 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xc3b2ba40 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 4196351 4194304 2G 83 Linux /dev/sda2 4196352 8390655 4194304 2G 83 Linux /dev/sda3 8390656 14682111 6291456 3G 83 Linux /dev/sda4 14682112 44040191 29358080 14G 5 Extended /dev/sda5 14684160 20975615 6291456 3G 83 Linux /dev/sda6 20977664 27269119 6291456 3G 83 Linux /dev/sda7 27271168 44040191 16769024 8G 83 Linux Command (m for help): w # 保存并退出 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.2.1.2.GPT格式对 /dev/sdb 进行gdisk 分区三个分区容量自定[rootZXY ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.40.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. Created a new DOS (MBR) disklabel with disk identifier 0x76f4ae84. Command (m for help): g # 创建 GPT 格式分区表 Created a new GPT disklabel (GUID: CA42BD46-2412-4200-9885-6C329228F30C). Command (m for help): n # 新建 Partition number (1-128, default 1): # 分区编号 First sector (2048-41943006, default 2048): # 起始扇区号 Last sector, /-sectors or /-size{K,M,G,T,P} (2048-41943006, default 41940991): 4G # 结束扇区号 Created a new partition 1 of type Linux filesystem and of size 4 GiB. Command (m for help): n Partition number (2-128, default 2): First sector (8390656-41943006, default 8390656): Last sector, /-sectors or /-size{K,M,G,T,P} (8390656-41943006, default 41940991): 3G Created a new partition 2 of type Linux filesystem and of size 3 GiB. Command (m for help): n Partition number (3-128, default 3): First sector (14682112-41943006, default 14682112): Last sector, /-sectors or /-size{K,M,G,T,P} (14682112-41943006, default 41940991): # 结束扇区号默认代表把剩余所有空间分配给该分区 Created a new partition 3 of type Linux filesystem and of size 13 GiB. Command (m for help): p # 打印当前分区信息 Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors Disk model: VMware Virtual S Units: sectors of 1 * 512 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: CA42BD46-2412-4200-9885-6C329228F30C Device Start End Sectors Size Type /dev/sdb1 2048 8390655 8388608 4G Linux filesystem /dev/sdb2 8390656 14682111 6291456 3G Linux filesystem /dev/sdb3 14682112 41940991 27258880 13G Linux filesystem Command (m for help): w # 保存并退出 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.三、格式化3.1mkfs[rootZXY ~]# mkfs # 注意不要加空格点击两次 tab 键 mkfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs选项参数功能-f强制格式化覆盖已存在的文件系统-c建立文件系统前先检查坏块-v输出建立文件系统的详细信息-d指定核心数# 查看当前分区情况 [rootZXY ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 21G 0 disk ├─sda1 8:1 0 2G 0 part ├─sda2 8:2 0 2G 0 part ├─sda3 8:3 0 3G 0 part ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 3G 0 part ├─sda6 8:6 0 3G 0 part └─sda7 8:7 0 8G 0 part # 格式化 [rootrhcsa ~]# mkfs.xfs /dev/sda1 [rootrhcsa ~]# mkfs.ext4 /dev/sda2 # 格式化成功过后可以看到该分区的 FSTYPE文件系统 和 UUID [rootrhcsa ~]# lsblk -f NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS sda ├─sda1 xfs 9457ccee-7b50-459f-819d-ce16963e666f ├─sda2 ext4 1.0 8ef7c3cf-fc4e-4cb4-98cc-e287d7ef0167 ├─sda3 ├─sda4 ├─sda5 ├─sda6 └─sda7四、挂载4.1.mount选项参数功能-a将配置文件 /etc/fstab 的所有未挂载的磁盘都挂载上来-t指定文件系统类型-o指定挂载文件系统时的自定义参数# 名称挂载 /dev/sda1 [rootZXY ~]# mkdir /guazai1 # 创建挂载点 [rootZXY ~]# mount /dev/sda1 /guazai1/ [rootZXY ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 21G 0 disk ├─sda1 8:1 0 2G 0 part /guazai1 ├─sda2 8:2 0 2G 0 part ├─sda3 8:3 0 3G 0 part ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 3G 0 part ├─sda6 8:6 0 3G 0 part └─sda7 8:7 0 8G 0 part ... # UUID 挂载 /dev/sda2 [rootZXY ~]# mkdir /guazai2 [rootZXY ~]# blkid /dev/sda2 /dev/sda2: UUID8ef7c3cf-fc4e-4cb4-98cc-e287d7ef0167 BLOCK_SIZE4096 TYPEext4 PARTUUIDc3b2ba40-02 [rootZXY ~]# mount UUID8ef7c3cf-fc4e-4cb4-98cc-e287d7ef0167 /guazai2 [rootZXY ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 21G 0 disk ├─sda1 8:1 0 2G 0 part /guazai1 ├─sda2 8:2 0 2G 0 part /guazai2 ├─sda3 8:3 0 3G 0 part ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 3G 0 part ├─sda6 8:6 0 3G 0 part └─sda7 8:7 0 8G 0 part ...