西数超哥博客
运维经验教程分享

linux环境下如何通过fdisk 进行已有磁盘分区扩容

这篇文章基本是之前老东家公司上班时候一直用的linux磁盘扩容,采用fdisk,后边改成了parted进行扩容。 这里也顺便记录一下用fdisk扩容方法。
注意:未防止意外发生,请提前备份要操作的磁盘,避免操作失败导致数据丢失。

[root@localhost ~]# df -lh    //查看扩容分区所在的硬盘名称,这里以home对应的/dev/sdb1 为例。

文件系统              容量  已用 可用 已用% 挂载点
/dev/sda1             9.7G  2.6G  6.7G  28% /
tmpfs                 252M     0  252M   0% /dev/shm
/dev/sdb1             9.9G  172M  9.2G   2% /home

[root@localhost ~]# fdisk /dev/sdb    //输入fdisk /dev/sdb 请确认扩容分区对应的硬盘名称,以免误删其他分区!

The number of cylinders for this disk is set to 41610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): d    //输入d删除分区
Selected partition 1     //显示要删除的分区号,因为只有一个分区,所以显示1
Command (m for help): n    //输入n新建分区
Command action
   e   extended
   p   primary partition (1-4)
p                                               //输入p,选择要操作的项目
Partition number (1-4): 1    //输入要新建的分区号,这里输入1
First cylinder (1-41610, default 1):    //选择要截止的磁盘位置,这里直接按回车,全部增加。
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-41610, default 41610):   //直接按回车。
Using default value 41610
Command (m for help): w    //输入w保存设置
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

输入reboot重启服务器:

[root@localhost ~]# reboot    //输入reboot重启服务器

重启服务器后执行以下命令:

[root@localhost ~]# resize2fs -f /dev/sdb1   //输入resize2fs -f /dev/sdb1,sdb1这里指要扩容分区对应的硬盘分区名称
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/sdb1 is mounted on /home; on-line resizing required
Performing an on-line resize of /dev/sdb1 to 5242852 (4k) blocks.
The filesystem on /dev/sdb1 is now 5242852 blocks long.
[root@localhost ~]# df –lh    //再用df –lh 查询下home分区大小,可以看到已经增加了。
文件系统              容量  已用 可用 已用% 挂载点
/dev/sda1             9.7G  2.6G  6.7G  28% /
tmpfs                 252M     0  252M   0% /dev/shm
/dev/sdb1              20G  177M   19G   1% /home

至此,扩容已经完成。另外如果个别有显示不正确的朋友,可以再进一步进行重启,避免df 显示不正确。
喜欢用parted扩容的,可以参考文章《Linux服务器升级硬盘以后通过parted进行磁盘分区扩容操作流程》

转载请注明:西数超哥博客www.ysidc.top» linux环境下如何通过fdisk 进行已有磁盘分区扩容

https://www.ysidc.top 西数超哥博客,数据库,西数超哥,虚拟主机,域名注册,域名,云服务器,云主机,云建站,ysidc.top

赞(0)
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥博客 » linux环境下如何通过fdisk 进行已有磁盘分区扩容