当前位置: 首页 > 科技观察

如何在不重启系统的情况下在CentOS7中添加新磁盘

时间:2023-03-15 15:20:04 科技观察

对于大多数系统管理员来说,扩展Linux服务器的磁盘空间是日常工作之一。因此本文将通过Linux命令的使用。1、虚拟机客户端扩展磁盘空间:在Linux系统中添加磁盘卷之前,首先需要添加一个新的物理磁盘,或者在VMwarevShereVMwar工作站等虚拟环境软件中设置,增加一个虚拟机的容量磁盘。2.检查磁盘空间:运行以下命令检查当前磁盘空间。#df-h#fdisk-l3。不重启虚拟机扩展空间现在运行如下命令,通过重新扫描SCSI(注:SmallComputSystemInterfacSmallComputerSystemInterface)总线,添加SCSI设备,系统可以扩展操作系统的物理卷磁盘空间,没有需要重启虚拟机。#ls/sys/class/scsi_host#echo"---">/sys/class/scsi_host/host0/scan#echo"---">/sys/class/scsi_host/host1/scan#echo"---">/sys/class/scsi_host/host2/scan使用以下命令查看SCSI设备的名称,然后重新扫描SCSI总线。#ls/sys/class/scsi_device/#echo1>/sys/class/scsi_device/0:0:0:0/device/rescan#echo1>/sys/class/scsi_device/2:0:0:0/device/如下图,rescan会重新扫描SCSI总线,然后我的虚拟机客户端设置的磁盘大小就会正常显示了。4.创建新的磁盘分区:当您在系统中看到扩展的磁盘空间后,您可以运行以下命令来格式化您的磁盘以创建一个新的分区。请按照以下步骤来扩展您的物理磁盘空间。#fdisk/dev/sdaWelcomtofdiskutil-linux2.23.2pressthe'm'keiforhelpCommandmforhelp:mCommandactionatogglabootablflagbeditbsddisklabelctogglthedocompatflagddeletapartitiongcreatanewemptiGPTpartittableGcreatanIRIXSGIpartittablellistknownpartittypesmprintthimenunaddanewpartitionocreatanewemptiDOSpartittablepprintthepartittableqquitwithoutsavechangescreatanewemptiSundisklabeltchangapartition'systemiduchangdisplay/entriunitsvverifithepartittablewwritetabltodiskandexitxextrafunctionexpertonliCommandmforhelp:键入'p'来查看当前的分区表信息,然后键入'n'键来创建一个新的主分区,选择所有Foravailablesectors,usethe't'commandtochangethedisktypeto'LinuxLVM'andthenselecttheencoding'8e'orleaveitunselectedbydefault.Thedefaulttypeencodingis'83'5.Createaphysicalvolume:run'partprob'accordingtotheabovepromptsOr'kpartx'commandtomakethepartitiontableeffective,andthenusethefollowingcommandtocreateanewphysicalvolume.#partprobe#pvcreat/dev/sda3Tocheckthenewlycreatedvolume,runthefollowingcommandtoseewhetherthenewphysicalvolumehasbeencreatedandisavailable.Next,youcanusethisnewphysicalvolumetoexpandthe'centos'volumegroup,asshownbelow:#pvdisplay#vgextendcento/dev/sda36.Extendlogicalvolume:Nowusethefollowingcommandtoexpandthelogicalvolumetoincreasethevolumethatmysystemisusingofdiskspace.7.Expandtherootpartitionbyaddinganewdiskwithoutrestartingthesystem:Thisisthesecondmethod,thecommandusedisverysimple,anditisusedtoincreasethesizeofthelogicalvolumespaceontheCentOS7system.Sothefirststepistoopenthesettingspageofyourvirtualmachineclient,clickthe'Add'button,andproceedtothenextstep.#ls/sys/class/scsi_device/#echo1>/sys/class/scsi_device/1:0:0:0/device/rescan#echo1>/sys/class/scsi_device/2:0:0:0/device/rescan#echo1>/sys/class/scsi_device/3:0:0:0/device/rescan#fdisk-l结论:在LinuxCentOS7系统上管理磁盘分区的操作过程非常简单,可以使用本文介绍的操作article方法来扩展任何逻辑卷的磁盘空间。生产线上的服务器不需要重启,只需要简单的重新扫描SCSI设备,扩展你想要的LVM逻辑卷管理即可)希望这篇文章对你有用。请随时发表有用的意见和建议。