怎么使用fdisk扩展磁盘空间
这篇文章主要介绍了怎么使用fdisk扩展磁盘空间的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇怎么使用fdisk扩展磁盘空间文章都会有所收获,下面我们一起来看看吧。
fdisk用来管理linux的磁盘,进行分区,格式化等操作,fdisk命令用于观察硬盘实体使用情况,也可对硬盘分区。它采用传统的问答式界面,而非类似DOS fdisk的cfdisk互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣。
硬盘空间为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
关于“怎么使用fdisk扩展磁盘空间”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“怎么使用fdisk扩展磁盘空间”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。