歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習Linux

centos下使用fdisk擴展分區容量大小

centos下使用fdisk擴展分區容量大小


centos下使用fdisk擴展分區容量大小


擴展磁盤空間

硬盤空間為20G,使用vSphere Client增加磁盤大小,需要再增加10G空間;
fdisk_l-20Gvshere_add

擴展完後,重啟系統,再次使用fdisk -l查看,會發現硬盤空間變大了;

[root@linuxprobe~]#fdisk-lDisk/dev/sda:32.2GB,32212254720bytes255heads,63sectors/track,3916cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x0005210cDeviceBootStartEndBlocksIdSystem/dev/sda1*12620480083LinuxPartition1doesnotendoncylinderboundary./dev/sda22613011024000083Linux/dev/sda313011497157286482Linuxswap/Solaris/dev/sda414972611895283283Linux[root@linuxprobe~]#df-hTFilesystemTypeSizeUsedAvailUse%Mountedon/dev/sda2ext49.7G1.5G7.7G16%/tmpfstmpfs939M0939M0%/dev/shm/dev/sda1ext4194M34M151M19%/boot/dev/sda4ext48.5G148M7.9G2%/data

fdisk_l-30

重新創建分區,調整分區信息

本次實驗主要對/dev/sda4這個分區擴展,如果是生產環境,請提前做好備份保存到其他分區,雖然擴展分區大小不會導致數據丟失,安全起見,請提前做好備份;
首先模擬出一些數據:

[root@linuxprobedata]#mkdirtest[root@linuxprobedata]#echo"weareLinuxer">linuxprobe[root@linuxprobedata]#lltotal24-rw-r--r--.1rootroot15May2321:59linuxprobedrwx------.2rootroot16384May2315:07lost+founddrwxr-xr-x.2rootroot4096May2321:51test[root@linuxprobe~]#umount/dev/sda4#卸載磁盤分區

若提示磁盤忙,使用fuser找出將正在使用磁盤的程序並結束掉;

fuser-m-v/datafuser-m-v-i-k/data

使用fdisk工具先刪除/dev/sda4分區,然後創建新分區,注意開始的磁柱號要和原來的一致(是保證數據不丟失的關鍵步驟),結束的磁柱號默認回車使用全部磁盤。

[root@linuxprobe~]#fdisk/dev/sdaWARNING:DOS-compatiblemodeisdeprecated.It'sstronglyrecommendedtoswitchoffthemode(command'c')andchangedisplayunitstosectors(command'u').Command(mforhelp):p#查看分區表信息Disk/dev/sda:32.2GB,32212254720bytes255heads,63sectors/track,3916cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x0005210cDeviceBootStartEndBlocksIdSystem/dev/sda1*12620480083LinuxPartition1doesnotendoncylinderboundary./dev/sda22613011024000083Linux/dev/sda313011497157286482Linuxswap/Solaris/dev/sda414972611895283283LinuxCommand(mforhelp):d#刪除分區Partitionnumber(1-4):4#刪除第四個Command(mforhelp):p#再次查看分區信息,/dev/sda4已被刪除Disk/dev/sda:32.2GB,32212254720bytes255heads,63sectors/track,3916cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x0005210cDeviceBootStartEndBlocksIdSystem/dev/sda1*12620480083LinuxPartition1doesnotendoncylinderboundary./dev/sda22613011024000083Linux/dev/sda313011497157286482Linuxswap/SolarisCommand(mforhelp):n#創建新的分區Commandactioneextendedpprimarypartition(1-4)p#創建為主分區Selectedpartition4Firstcylinder(1497-3916,default1497):#經對比,正好和上一個磁盤柱一致,默認即可Usingdefaultvalue1497Lastcylinder,+cylindersor+size{K,M,G}(1497-3916,default3916):Usingdefaultvalue3916#直接默認就可以Command(mforhelp):p#查看分區表信息Disk/dev/sda:32.2GB,32212254720bytes255heads,63sectors/track,3916cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x0005210cDeviceBootStartEndBlocksIdSystem/dev/sda1*12620480083LinuxPartition1doesnotendoncylinderboundary./dev/sda22613011024000083Linux/dev/sda313011497157286482Linuxswap/Solaris/dev/sda4149739161943658283LinuxCommand(mforhelp):wp#保存並退出,如果創建有誤,直接退出不要保存即可Thepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.WARNING:Re-readingthepartitiontablefailedwitherror16:Deviceorresourcebusy.Thekernelstillusestheoldtable.Thenewtablewillbeusedatthenextrebootorafteryourunpartprobe(8)orkpartx(8)Syncingdisks.

fdisk-dfdisk-p
重新創建分區後,需要重啟一下;

[root@linuxprobe~]#init6[root@linuxprobe~]#e2fsck-f/dev/sda4#檢查分區信息[root@linuxprobe~]#resize2fs-p/dev/sda4#調整分區大小

重新掛載、查看分區大小、數據

[root@linuxprobe~]#mount/dev/sda4/data[root@linuxprobe~]#df-hT[root@linuxprobe~]#cat/data/linuxprobeweareLinuxer

df-hT_19G

http://xxxxxx/Linuxjc/1134095.html TechArticle

Copyright © Linux教程網 All Rights Reserved