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

來源:互聯網
上載者:User

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

擴充磁碟空間

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

擴充完後,重啟系統,再次使用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

重新建立分區,調整分區資訊

本次實驗主要對/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.


重新建立分區後,需要重啟一下;

[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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.