Linux系统磁盘管理
知识点:
[root@localhost ~]# fdisk /dev/sda #用fdisk命令对/目录下的dev目录下的sda磁盘进行分区Welcome to fdisk (util-linux 2.37.4).
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 disklabel with disk identifier 0x98c8e628.Command (m for help): m #Command这里输入m,获取帮助信息Help:DOS (MBR)a toggle a bootable flagb edit nested BSD disklabelc toggle the dos compatibility flagGenericd delete a partition #删除分区F list free unpartitioned space #列出未分区的剩余空间,一般不用l list known partition types #列出已有的分区类型n add a new partition #添加新分区p print the partition table #打印分区表t change a partition type #修改分区类型v verify the partition table #确认分区表,一般不用i print information about a partition #打印分区信息,一般不用Miscm print this menu #打印帮助u change display/entry units x extra functionality (experts only)ScriptI load disk layout from sfdisk script fileO dump disk layout to sfdisk script fileSave & Exitw write table to disk and exit #保存分区表并退出q quit without saving changes #退出且不保存Create a new labelg create a new empty GPT partition table #创建一个空的 GPT 分区表G create a new empty SGI (IRIX) partition tableo create a new empty DOS partition table #创建一个空的mbr分区表s create a new empty Sun partition table
Command (m for help): n #n,添加分区
Partition typep primary (0 primary, 0 extended, 4 free) #p,是主分区e extended (container for logical partitions) #e,是扩展分区
Select (default p): #选择分区类型,直接回车是默认,默认是p,主分区Using default response p.
Partition number (1-4, default 1): #选择分区编号(1-4),直接回车是默认,默认是1
First sector (2048-20971519, default 2048): #选择分区开始的扇区号,直接回车是默认,默认是2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): +2g #选择该分区的大小,+2g就是设置成2gCreated a new partition 1 of type 'Linux' and of size 2 GiB.Command (m for help): p #输入p,打印分区表
Disk /dev/nvme0n2: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual NVMe Disk
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: 0xd524af35Device Boot Start End Sectors Size Id Type
/dev/nvme0n2p1 2048 4196351 4194304 2G 83 Linux #刚刚分好的分区Command (m for help): n #输入n,添加分区
Partition typep primary (1 primary, 0 extended, 3 free)e extended (container for logical partitions)
Select (default p): e #输入e,选择添加的分区是扩展分区
Partition number (2-4, default 2): #选择分区编号,直接回车是默认,默认是2
First sector (4196352-20971519, default 4196352): #分区开始的位置,直接回车是默认
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4196352-20971519, default 20971519): +3g #设置分区的大小为3gCreated a new partition 2 of type 'Extended' and of size 3 GiB.Command (m for help): p #打印分区表
Disk /dev/nvme0n2: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual NVMe Disk
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: 0xd524af35Device Boot Start End Sectors Size Id Type
/dev/nvme0n2p1 2048 4196351 4194304 2G 83 Linux #
/dev/nvme0n2p2 4196352 10487807 6291456 3G 5 Extended #新增的扩展分区Command (m for help): n #添加
Partition type p primary (1 primary, 1 extended, 2 free) #l logical (numbered from 5) #l是逻辑分区
Select (default p): l #选择l,创建逻辑分区
windows:NTFS(Windows 常用 ,支持大分区和大文件 )、fat(不能存储大于4G的文件)、fat32(兼容性好 ,被多种操作系统支持 ,但单个文件大小有限制 )、exfat(U盘,可以兼容Linux或者windows系统或者mac)
Linux:ext2、ext3、ext4(常用于 Linux 系统,支持日志功能 ,可靠性较高 )、xfs(高性能、可扩展 ,适合大文件存储
【面试笔试】Linux常见的文件系统类型?
ext2、ext3、ext4、xfs
#fstab文件各个部分的解释
#第一部分:要挂载的设备或分区的设备文件名
#第二部分:指定了挂载点,即将要挂载设备的目标目录。
#第三部分:指定了要使用的文件系统类型。iso9660 是光盘标准文件系统的类型。
#第四部分:指定了挂载选项,这里表示使用默认的挂载选项。默认选项通常包括允许读取内容,但不允许写入。
#第五部分:指定了 dump 命令备份文件系统时的备份级别。通常设置为 0 表示不备份。
#第六部分:指定了 fsck 命令在引导时检查文件系统的顺序。 通常设置为 0 表示不进行检查。
#注意:
#1、/etc/fstab 文件内容不能有错,否则系统容易有问题!!!
#2、mount -a 命令会检查 /etc/fstab 文件中的每一行,如果找到尚未挂载的文件系统,则会按照其中的设定自动挂载它们。这个命令通常在系统启动时自动执行,以确保所有在 fstab 文件中列出的文件系统都正确挂载
[root@ghl ~]# reboot #系统重启
1、添加三块硬盘:
第一块硬盘,虚拟磁盘类型选择SCSI。大小选择5G。按mbr格式分区。分两个主分区,大小分别为2G和1G。第一个主分区创建ext2类型的文件系统。第一个主分区挂载到/guazai1目录,并在其中存入1.txt的文件。其文件内容是this is 1.txt。第二个主分区创建ext3的类型的文件系统。第二个主分区挂载到/guazai2目录,并在其中存入2.txt的文件。其文件内容是this is 2.txt。





第二块硬盘,虚拟磁盘类型选择STAT。大小选择10G。按mbr格式分区。分一个主分区,大小为1G 。分一个扩展分区。大小为6G。分一个逻辑分区,大小为4G。将主分区创建为ext4类型的文件系统。挂载到/guazai3目录。在其中存入3.txt的文件,其文件内容是this is 3.txt。将逻辑分区创建xfs类型的文件系统。挂载到/guazai4目录。在其中存入4.txt的文件,其文件内容是this is 4.txt。







第三块硬盘,虚拟磁盘类型选择NVME。大小选择15G。按gpt格式分区。分一个主分区。大小为5G。主分区创建xfs类型的文件系统,挂载到/guazai5目录,在其中存入5.txt的文件,其文件内容是this is 5.txt。





