Linux系统扩容根目录磁盘空间的操作方法.docx
Linux系统扩容根目录磁盘空间的操作方法Linux系统扩容根目录磁盘空间的操作方法加城8G容量。rootubuntu14:/opt#df-h文件系统容量已用可用已用%挂载点/dev/mapper/ubuntu14-vg-root28G23G3.3G88%/none4.0K04.0K0%/sys/fs/cgroupudev3.9G4.0K3.9G1%/devtmpfs799M384K799M1%/runnone5.0M05.0M0%/run/locknone3.9G03.9G0%/run/shmnone100M0100M0%/run/user/dev/vda1236M37M188M17%/boot2.增加磁盘空间,例如下列图使用VM虚拟机增加的方式。3.使用fdisk-l命令查看磁盘信息。当看到第一行Disk/dev/vda:161.1GB与实际df-h显示内容不符时,讲明增加磁盘成功了。rootubuntu14:/opt#fdisk-lDisk/dev/vda:161.1GB,161061273600bytes16heads,63sectors/track,312076cylinders,total314572800sectorsUnits=扇区of1_512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0_0001a023设备启动起点终点块数Id系统/dev/vda1_204849971124883283Linu_/dev/vda250175862912511312053775扩展/dev/vda550176062912511312053768eLinu_LVMDisk/dev/mapper/ubuntu14-vg-root:29.8GB,29804724224bytes255heads,63sectors/track,3623cylinders,total58212352sectorsUnits=扇区of1_512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0_00000000Disk/dev/mapper/ubuntu14-vg-rootdoesntcontainavalidpartitiontableDisk/dev/mapper/ubuntu14-vg-swap_1:2147MB,2147483648bytes255heads,63sectors/track,261cylinders,total4194304sectorsUnits=扇区of1_512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0_00000000Disk/dev/mapper/ubuntu14-vg-swap_1doesntcontainavalidpartitiontable4.使用fdisk/dev/vda,创立新分区。注意:不同操作系统的磁盘命名方式不同,有些是/dev/sda。详细使用方式参考第三步中fdisk-l首行显示Disk。如笔者在该系统中首行显示为Disk/dev/vda:161.1GB,161061273600bytes,故使用命令fdisk/dev/vda)根据下面Linu_操作进行分区。rootubuntu14:/opt#fdisk/dev/vda命令(输入m获取帮助):m命令操作atoggleabootableflagbeditbsddisklabelctogglethedoscompatibilityflagddeleteapartitionllistknownpartitiontypesmprintthismenunaddanewpartitionocreateanewemptyDOSpartitiontablepprintthepartitiontableqquitwithoutsavingchangesscreateanewemptySundisklabeltchangeapartitionssystemiduchangedisplay/entryunitsvverifythepartitiontablewwritetabletodiskande_it_e_trafunctionality(e_pertsonly)命令(输入m获取帮助):n#new新分区Partitiontype:pprimary(1primary,1e_tended,2free)llogical(numberedfrom5)Select(defaultp):p#选择主分区分区号(1-4,默以为3):3#分区序号起始sector(499712-314572799,默以为499712):#分区开场回车默认将使用默认值499712Lastsector,+扇区or+sizeK,M,G(499712-501757,默以为501757):将使用默认值501757命令(输入m获取帮助):n#new新分区Partitiontype:pprimary(2primary,1e_tended,1free)llogical(numberedfrom5)Select(defaultp):p#选择主分区Selectedpartition4#分区序号起始sector(62912512-314572799,默以为62912512):#分区开场回车默认将使用默认值62912512Lastsector,+扇区or+sizeK,M,G(62912512-314572799,默以为314572799):将使用默认值314572799命令(输入m获取帮助):t#修改分区格式分区号(1-5):4#修改分区号He_code(typeLtolistcodes):8e#格式选择8elinu_LVMChangedsystemtypeofpartition4to8e(Linu_LVM)命令(输入m获取帮助):p#显示分区信息Disk/dev/vda:161.1GB,161061273600bytes16heads,63sectors/track,312076cylinders,total314572800sectorsUnits=扇区of1_512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0_0001a023设备启动起点终点块数Id系统/dev/vda1_204849971124883283Linu_/dev/vda250175862912511312053775扩展/dev/vda3499712501757102383Linu_/dev/vda4629125123145727991258301448eLinu_LVM/dev/vda550176062912511312053768eLinu_LVMPartitiontableentriesarenotindiskorder命令(输入m获取帮助):w#保存信息Thepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.WARNING:Re-readingthepartitiontablefailedwitherror16:设备或资源忙.Thekernelstillusestheoldtable.Thenewtablewillbeusedatthene_trebootorafteryourunpartprobe(8)orkpart_(8)Syncingdisks.5.重启Linu_操作系统,使用reboot命令。6.创立物理卷,使用pvcreate/dev/vda4命令。rootubuntu14:#pvcreate/dev/vda4Physicalvolume/dev/vda4successfullycreated7.查看新建的物理卷和大小,使用pvdisplay命令。rootubuntu14:#pvdisplay-Physicalvolume-PVNameubuntu14-vgPVSize29.76GiB/notusable2.00MiBAllocatableyes(butfull)PESize4.00MiBTotalPE7618FreePE0AllocatedPE7618PVUUID_R32TY-aRQC-IQC6-oC_7-aa9_-KdJe-bHmaBd/dev/vda4/dev/vda5VGNameisanewphysicalvolumeof120.00GiB-NEWPhysicalvolume-PVName/dev/vda4VGNamePVSize120.00GiBAllocatableNOPESize0TotalPE0FreePE0AllocatedPE0PVUUIDMVK0IT-LDgP-eWwZ-fzQM-tdyY-kRQ-nbk1228.将添加新的物理卷,加载到ubuntu14-vg卷组,使用vge_tendubuntu14-vg/dev/vda4命令。rootubuntu14:#vge_tendubuntu14-vg/dev/vda4Volumegroupubuntu14-vgsuccessfullye_tended9.查看卷组信息,使用vgdisplay命令。rootubuntu14:#vgdisplay-Volumegroup-VGNameubuntu14-vgSystemIDFormatlvm2MetadataAreas2MetadataSequenceNo4VGAccessread/writeVGStatusresizableMA_LV0CurLV2OpenLV2Ma_PV0CurPV2ActPV2VGSize149.76GiBPESize4.00MiBTotalPE38338AllocPE/Size7618/29.76GiBFreePE/Size30720/120.00GiBVGUUIDcq2Z6G-P6j1-S2gM-mibz-d63V-NjkS-dHYe7D10.增加ubuntu14-vg大小,增加120G。使用lvresize-L+120G/dev/mapper/ubuntu14-vg-root命令。rootubuntu14:#lvresize-L+120G/dev/mapper/ubuntu14-vg-rootE_tendinglogicalvolumerootto147.76GiBLogicalvolumerootsuccessfullyresized11.重新识别ubuntu14-vg大小,使用resize2fs/dev/mapper/ubuntu14-vg-root命令。rootubuntu14:#resize2fs/dev/mapper/ubuntu14-vg-rootresize2fs1.42.9(4-Feb-2021)Filesystemat/dev/mapper/ubuntu14-vg-rootismountedon/;on-lineresizingrequiredold_desc_blocks=2,new_desc_blocks=10Thefilesystemon/dev/mapper/ubuntu14-vg-rootisnow38733824blockslong.12.查看扩容后的大小,使用df-h命令。rootubuntu14:#df-h文件系统容量已用可用已用%挂载点/dev/mapper/ubuntu14-vg-root146G23G117G17%/none4.0K04.0K0%/sys/fs/cgroupudev3.9G4.0K3.9G1%/devtmpfs799M388K799M1%/runnone5.0M05.0M0%/run/locknone3.9G03.9G0%/run/shmnone100M0100M0%/run/user/dev/vda1236M37M188M17%/boot当看到/dev/mapper/ubuntu14-vg-root已经更新到新的大小时,则表示增加成功。补充:Linu_基本命令ls意为list列出当前文件夹中的文件-l显示文件的属性可用ll来表示alias别名看看能否有别名的文件cddir跳跃目录-P选项将途径中的链接文件替换成链接指向的文件途径pwd查看当前工作的文件夹名使用-P的选项,会直接进入到其中,相当于cd相关浏览:Linu_shell脚本不执行问题实例分析shell脚本不执行问题:某天研发某同事找我讲帮他看看他写的shell脚本,死活不执行,报错。我看了下,脚本很简单,也没有常规性的错误,报ldquo;:badinterpreter:Nosuchfileordirectoryrdquo;错。看这错,我就问他是不是在windows下编写的脚本,然后在上传到linu_服务器的hellip;hellip;果然。原因:在DOS/windows里,文本文件的换行符为rn,而在_i_系统里则为n,所以DOS/Windows里编辑过的文本文件到了_i_里,每一行都多了个M。解决:1)重新在linu_下编写脚本;2)vi:%s/r/g:%s/M/g(M输入用Ctrl+v,Ctrl+m)附:sh-_脚本文件名,能够单步执行并回显结果,有助于排查复杂脚本问题。Linu_系统扩容根目录磁盘空间的操作方法