硬盘分区管理大容量的硬盘分区使用C盘系统盘D盘办公E盘娱乐等…类似于一个房子里面隔断出来有厨房卫生间卧室客厅等文件系统挂载和卸载识别硬盘设备实践1.添加一块sata硬盘2.添加一块NVMe硬盘添加 - 硬盘 -选择目标硬盘##查看硬盘[rootcontenOS7 ~10:02:00]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda8:00200G0disk ├─sda18:101G0part /boot └─sda28:20199G0part ├─centos_contenos7-root253:0050G0lvm / ├─centos_contenos7-swap253:103.9G0lvm[SWAP]└─centos_contenos7-home253:20145.1G0lvm /home sdb8:16020G0disk#sate硬盘sr011:014.4G0rom nvme0n1259:0040G0disk#新增NVMe硬盘硬盘分区方案直接管理主板上外接设备的系统称之为固件例如调整设备启动顺序光盘作为第一启动项用来安装系统MBR主分区数量限制支持最多4个主分区。扩展分区和逻辑分区在 Linux系统上管理员可以使用扩展分区和逻辑分区来创建最多 15个分区。逻辑分区是可以格式化format扩展分区是不可以格式化。容量限制 最大能表示2的32次方的扇区个数按每扇区512字节计算每个分区最大不能超过 2 TiB。类比为笔记本只有4个usb接口如果不够用则将第四个usb接口外接扩展坞由扩展坞提供多个usb接口。GPT全局唯一标识分区表GPT是运行 统一可扩展固件接口UEFI 系统的磁盘分区标准。容量支持使用8个字节存储分区总扇区数单分区/磁盘最大支持 18 ZiB18亿 TiB完全满足大磁盘需求。分区数量默认支持 128个分区无需扩展分区/逻辑分区实际使用中建议不超过120个避免格式化异常。数据冗余GPT 分区表包含主表和备份表且自带 CRC32 校验码可自动检测并恢复损坏的分区表。fdisk管理MBRfdisk 工具用于管理 MBR 分区方案的硬盘新版本的fdisk也可以用来管理GPT。查看硬盘信息[rootcontenOS7 ~10:11:15]# fdisk -l | grep sdDisk /dev/sda:214.7GB,214748364800bytes,419430400sectors /dev/sda1 *20482099199104857683Linux /dev/sda220992004194303992086656008e Linux LVM Disk /dev/sdb:21.5GB,21474836480bytes,41943040sectors[rootcontenOS7 ~10:22:00]# fdisk -l /dev/sdaDisk /dev/sda:214.7GB,214748364800bytes,419430400sectors Unitssectors of1*512512bytes Sector size(logical/physical):512bytes /512bytes I/O size(minimum/optimal):512bytes /512bytes Disk label type: dos Disk identifier: 0x00099356 Device Boot Start End Blocks Id System /dev/sda1 *20482099199104857683Linux /dev/sda220992004194303992086656008e Linux LVM[rootcontenOS7 ~10:22:32]# fdisk -l /dev/sdbDisk /dev/sdb:21.5GB,21474836480bytes,41943040sectors Unitssectors of1*512512bytes Sector size(logical/physical):512bytes /512bytes I/O size(minimum/optimal):512bytes /512bytes创建分区##交互方式管理sdb硬盘[rootcontenOS7 ~10:34:44]# fdisk /dev/sdbWelcome tofdisk(util-linux2.23.2). Changes will remaininmemory only,untilyou decide towritethem. Be careful before using thewritecommand. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xb439b0fd.## m 查看帮助Command(mforhelp): 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 nadda new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partitions systemidu change display/entryunitsvverify the partition table wwritetable to disk andexitx extra functionality(experts only)Command(mforhelp): p##查看分区表##注意第一行硬盘总容量为21.5GBDisk /dev/sdb:21.5GB,21474836480bytes,41943040sectors Unitssectors of1*512512bytes Sector size(logical/physical):512bytes /512bytes I/O size(minimum/optimal):512bytes /512bytes Disk label type: dos Disk identifier: 0xb439b0fd Device Boot Start End Blocks Id System### sdb硬盘是空盘没有分区Command(mforhelp): n###新建分区Partition type: p primary(0primary,0extended,4free)e extended Select(default p):##回车 主分区类型Using default response p Partition number(1-4, default1):##回车 分区号First sector(2048-41943039, default2048):##回车 分区起始位置Using default value2048Last sector, sectors or size{K,M,G}(2048-41943039, default41943039): 5G##增加5个GbPartition1oftypeLinux and of size5GiB isset##查看分区表Command(mforhelp): p Disk /dev/sdb:21.5GB,21474836480bytes,41943040sectors Unitssectors of1*512512bytes Sector size(logical/physical):512bytes /512bytes I/O size(minimum/optimal):512bytes /512bytes Disk label type: dos Disk identifier: 0xb439b0fd Device Boot Start End Blocks Id System /dev/sdb1204810487807524288083Linux Command(mforhelp): w##保存修改The partition table has been altered!Calling ioctl()to re-read partition table. Syncing disks.##查看sdb硬盘[rootcontenOS7 ~10:36:09]# lsblk /dev/sdbNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb8:16020G0disk └─sdb18:1705G0part删除分区[rootcontenOS7 ~10:47:01]# fdisk /dev/sdbWelcome tofdisk(util-linux2.23.2). Changes will remaininmemory only,untilyou decide towritethem. Be careful before using thewritecommand. Command(mforhelp): d##删除分区Selected partition1Partition1is deleted Command(mforhelp): p##查看分区表Disk /dev/sdb:21.5GB,21474836480bytes,41943040sectors Unitssectors of1*512512bytes Sector size(logical/physical):512bytes /512bytes I/O size(minimum/optimal):512bytes /512bytes Disk label type: dos Disk identifier: 0xb439b0fd Device Boot Start End Blocks Id System Command(mforhelp): w##保存退出The partition table has been altered!Calling ioctl()to re-read partition table. Syncing disks.计算机存储单位。GB1000MBGiB1024MiBgdisk 工具gdisk 工具用于管理 GPT 分区方案的硬盘。##安装gbisk工具[rootcontenOS7 ~10:47:24]# yum install -y gdisk查看硬盘信息[rootcontenOS7 ~10:48:30]# gdisk -l /dev/sdbGPTfdisk(gdisk)version0.8.10 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR;converting MBR to GPTformatinmemory. *************************************************************** Disk /dev/sdb:41943040sectors,20.0GiB Logical sector size:512bytes Disk identifier(GUID): BCD0FE91-8BE6-43DA-9FA6-955B8AACFCC8 Partition table holds up to128entries First usable sector is34, last usable sector is41943006Partitions will be aligned on2048-sector boundaries Totalfreespace is41942973sectors(20.0GiB)Number Start(sector)End(sector)Size Code Name帮助信息[rootcontenOS7 ~11:01:24]# gdisk /dev/sdbGPTfdisk(gdisk)version0.8.10 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR;converting MBR to GPTformatinmemory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE!Exit by typingqifyou dont want to convert your MBR partitions to GPT format! *************************************************************** Command (? for help): ? b back up GPT data to a file c change a partitions name d delete a partition i show detailed information on a partition l list known partition types nadda new partition o create a new empty GUID partition table(GPT)p print the partition table q quit without saving changes r recovery and transformation options(experts only)ssortpartitions t change a partitionstypecodevverify disk wwritetable to disk andexitx extra functionality(experts only)? print this menu查看分区表Command(?forhelp): p Disk /dev/sdb:41943040sectors,20.0GiB Logical sector size:512bytes Disk identifier(GUID): A0F20410-B78C-4D07-883E-EF71F12A99CA Partition table holds up to128entries First usable sector is34, last usable sector is41943006Partitions will be aligned on2048-sector boundaries Totalfreespace is41942973sectors(20.0GiB)Number Start(sector)End(sector)Size Code Name创建分区Command(?forhelp): n Partition number(1-128, default1): First sector(34-41943006, default2048)or{-}size{KMGTP}: Last sector(2048-41943006, default41943006)or{-}size{KMGTP}: 10G CurrenttypeisLinux filesystemHex code or GUID(L to show codes, Enter8300): Changedtypeof partition toLinux filesystemCommand(?forhelp): p Disk /dev/sdb:41943040sectors,20.0GiB Logical sector size:512bytes Disk identifier(GUID): A0F20410-B78C-4D07-883E-EF71F12A99CA Partition table holds up to128entries First usable sector is34, last usable sector is41943006Partitions will be aligned on2048-sector boundaries Totalfreespace is20971453sectors(10.0GiB)Number Start(sector)End(sector)Size Code Name120482097356710.0GiB8300Linux filesystem保存分区Command(?forhelp): w##保存Final checks complete. About towriteGPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!Do you want to proceed?(Y/N): Y##是否继续OK;writing new GUID partition table(GPT)to /dev/sdb. The operation has completed successfully.##再次查看[rootcontenOS7 ~11:04:31]# lsblk /dev/sdbNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb8:16020G0disk └─sdb18:17010G0part删除分区##查看分区[rootcontenOS7 ~11:04:46]# gdisk /dev/sdbGPTfdisk(gdisk)version0.8.10 Partition table scan: MBR: protective##保护式MBR 输入GPT的一部分BSD: not present APM: not present GPT: present##GPT格式Found valid GPT with protective MBR;using GPT.##查看分区Command(?forhelp): p Disk /dev/sdb:41943040sectors,20.0GiB Logical sector size:512bytes Disk identifier(GUID): A0F20410-B78C-4D07-883E-EF71F12A99CA Partition table holds up to128entries First usable sector is34, last usable sector is41943006Partitions will be aligned on2048-sector boundaries Totalfreespace is20971453sectors(10.0GiB)Number Start(sector)End(sector)Size Code Name120482097356710.0GiB8300Linux filesystem##删除Command(?forhelp): d Using1##再次查看确认Command(?forhelp): p Disk /dev/sdb:41943040sectors,20.0GiB Logical sector size:512bytes Disk identifier(GUID): A0F20410-B78C-4D07-883E-EF71F12A99CA Partition table holds up to128entries First usable sector is34, last usable sector is41943006Partitions will be aligned on2048-sector boundaries Totalfreespace is41942973sectors(20.0GiB)Number Start(sector)End(sector)Size Code Name##保存退出Command(?forhelp): w Final checks complete. About towriteGPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!##是否继续Do you want to proceed?(Y/N): Y OK;writing new GUID partition table(GPT)to /dev/sdb. The operation has completed successfully.[rootcontenOS7 ~11:06:39]# lsblk /dev/sdbNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb8:16020G0disk文件系统基本管理文件系统格式化硬盘分区不能直接使用需要格式化完成相应的文件系统ext4、xfs才能使用##提前准备好分区[rootcontenOS7 ~11:35:42]# lsblk /dev/sdbNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb8:16020G0disk ├─sdb18:1705G0part └─sdb28:18010G0part[rootcontenOS7 ~11:36:02]# mkfs.ext4 /dev/sdb1mke2fs1.42.9(28-Dec-2013)FilesystemlabelOS type: Linux Blocksize4096(log2)Fragmentsize4096(log2)Stride0blocks, Stripewidth0blocks327680inodes,1310720blocks65536blocks(5.00%)reservedforthe super user First datablock0Maximum filesystemblocks134217728040blockgroups32768blocks per group,32768fragments per group8192inodes per group Superblock backups stored on blocks:32768,98304,163840,229376,294912,819200,884736Allocating group tables:doneWriting inode tables:doneCreating journal(32768blocks):doneWriting superblocks and filesystem accounting information:done[rootcontenOS7 ~11:43:02]# mkfs.xfs /dev/sdb2meta-data/dev/sdb2isize512agcount4,agsize655360blkssectsz512attr2,projid32bit1crc1finobt0,sparse0databsize4096blocks2621440,imaxpct25sunit0swidth0blks namingversion2bsize4096ascii-ci0ftype1loginternal logbsize4096blocks2560,version2sectsz512sunit0blks, lazy-count1realtimenoneextsz4096blocks0,rtextents0文件系统挂载硬盘挂载之后才能使用类似于windows中分配盘##准备挂载点目录[rootcontenOS7 ~11:43:13]# mkdir /mnt/web##挂载/dev/sdb1到/mnt/web ,后续写入分区sdb1的数据通过路径为/mnt/web引用[rootcontenOS7 ~11:48:56]# mount /dev/sdb1 /mnt/web##查看设备和挂载点[rootcontenOS7 ~11:49:26]# df -h /mnt/webFilesystem Size Used Avail Use% Mounted on /dev/sdb14.8G 20M4.6G1% /mnt/web##写入测试[rootcontenOS7 ~11:49:38]# echo hello world /mnt/web/web.txt[rootcontenOS7 ~11:50:14]# cat /mnt/web/web.txthello world##此时文件/mnt/web/web.txt ,存储到sdb1中##准备挂载点[rootcontenOS7 ~11:50:30]# mkdir /mnt/db[rootcontenOS7 ~11:50:47]# mount /dev/sdb2 /mnt/db[rootcontenOS7 ~11:51:13]# df -h /mnt/dbFilesystem Size Used Avail Use% Mounted on /dev/sdb2 10G 33M 10G1% /mnt/db[rootcontenOS7 ~11:51:21]# echo hello world /mnt/db/db.txt[rootcontenOS7 ~11:51:48]# cat /mnt/db/db.txthello world##可以使用UUID挂载[rootcontenOS7 ~14:42:43]# mount UUIDb046f551-32b2-4285-a460-2b13fd0a88fd /mnt/db[rootcontenOS7 ~14:43:36]# lsblk /dev/sdb2NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb28:18010G0part /mnt/db部署web服务器web服务器提供web页面分享提供一些动态网站部署服务流程1.安装相关软件包2.准备相关材料3.配置服务4.启用并启动服务器5.设置防火墙6.客户端访问测试##安装相关软件包[rootcontenOS7 ~11:51:59]# yum install -y nginx##准备相关材料[rootcontenOS7 ~13:42:06]# echo Hello World Nginx /mnt/web/index.html##配置服务[rootcontenOS7 ~13:52:23]# cp /etc/nginx/nginx.conf /etc/nginx/conf.d/vhost-www.zhusheng.cloud.conf[rootcontenOS7 ~13:53:11]# vim /etc/nginx/conf.d/vhost-www.zhusheng.cloud.conf[rootcontenOS7 ~13:59:49]# vim /etc/hosts##在hosts文件里面追加如下ip10.1.8.10 www.zhusheng.cloud www##启用并启动服务器[rootcontenOS7 ~13:59:06]# systemctl enable nginx --now##设置防火墙[rootcontenOS7 ~13:59:28]# systemctl stop firewalld##客户端访问测[rootcontenOS7 ~14:01:23]# curl http://www.zhusheng.cloud/Hello World Nginx##返回结果/etc/nginx/conf.d/vhost-www.zhusheng.cloud.conf 文件里面修改内容如下如果是windows访问则修改C:\Windows\System32\drivers\etc\hosts也添加相应记录在windows里面hosts文件追加一行10.1.8.10 www.zhusheng.cloud www文件系统卸载文件系统不使用的时候可以卸载取消目录与设备之间的映射关系[rootcontenOS7 ~14:16:22]# lsblk /dev/sdbNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb8:16020G0disk ├─sdb18:1705G0part /mnt/web └─sdb28:18010G0part /mnt/db##卸载挂载点[rootcontenOS7 ~14:40:33]# umount /mnt/db[rootcontenOS7 ~14:40:58]# lsblk /dev/sdbNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb8:16020G0disk ├─sdb18:1705G0part /mnt/web └─sdb28:18010G0part##查看挂载点的信息[rootcontenOS7 ~14:42:23]# blkid /dev/sdb2/dev/sdb2:UUIDb046f551-32b2-4285-a460-2b13fd0a88fdTYPExfsPARTLABELLinux filesystemPARTUUID0d6bda07-f163-4a29-91e4-a97923e024e8##可以使用UUID挂载[rootcontenOS7 ~14:42:43]# mount UUIDb046f551-32b2-4285-a460-2b13fd0a88fd /mnt/db[rootcontenOS7 ~14:43:36]# lsblk /dev/sdb2NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb28:18010G0part /mnt/db##可以使用设备名称卸载[rootcontenOS7 ~14:43:53]# umount /dev/sdb2[rootcontenOS7 ~14:44:53]# lsblk /dev/sdbNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb8:16020G0disk ├─sdb18:1705G0part /mnt/web └─sdb28:18010G0part[rootcontenOS7 ~14:45:07]# lsblk /dev/sdb2NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb28:18010G0part文件系统卸载失败模拟占用[rootcontenOS7 ~14:48:08]# tail -f /mnt/web/index.html [1]1904[rootcontenOS7 ~14:57:11]# Hello World Nginx卸载文件报错 target is busy.[rootcontenOS7 ~14:57:29]# umount /mnt/webumount: /mnt/web: target is busy.(In some cases useful info about processes that use the device is found by lsof(8)or fuser(1))找到使用设备的进程[rootcontenOS7 ~14:57:44]# yum install -y lsof[rootcontenOS7 ~14:58:02]# lsof /mnt/web/COMMAND PIDUSERFD TYPE DEVICE SIZE/OFF NODE NAMEtail1904root 3r REG8,171813/mnt/web/index.html##tail 读取文件##关闭进程[rootcontenOS7 ~14:58:13]# kill -15 1904##卸载挂载点[rootcontenOS7 ~14:58:32]# umount /mnt/web[1] Terminatedtail-f/mnt/web/index.html持久化挂载计算机重启后文件系统自动挂载。/etc/fstab存储了系统自动挂载设备清单。[rootcontenOS7 ~15:59:12]# cat /etc/fstab## /etc/fstab# Created by anaconda on Fri Apr 3 14:14:05 2026## Accessible filesystems, by reference, are maintained under /dev/disk# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#/dev/mapper/centos_contenos7-root / xfs defaults00UUIDf565c0d7-85cf-46fe-b9dc-015f375fc0e5 /boot xfs defaults00/dev/mapper/centos_contenos7-home /home xfs defaults00/dev/mapper/centos_contenos7-swap swap swap defaults00设置/dev/sdb1 自动挂载到 /mnt/web[rootcontenOS7 ~16:05:56]# cp /etc/fstab /etc/fstab-0408[rootcontenOS7 ~16:06:29]# vim /etc/fstab条目参数说明/dev/sdb1挂载的设备/mnt/web设备挂载点ext4设备的文件系统defaults挂载选项用于控制文件系统属性例如defaults改为ro则文件系统只能读readonly0是否备份现在已弃用可用之为0或者10文件系统监测顺序值越小越优先检查。基本不用重启查看##重启之后查看[rootcontenOS7 ~16:09:14]# lsblk /dev/sdbNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb8:16020G0disk ├─sdb18:1705G0part /mnt/web └─sdb28:18010G0part