linux桌面环境|linux环境下通过fdisk 进行已有磁盘分区扩容

更新时间:2020-11-27    来源:linux    手机版     字体:

【www.bbyears.com--linux】

这篇文章基本是之前老东家公司上班时候一直用的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 显示不正确。

fdisk 的说明

  当我们通过 fdisk 设备,进入相应设备的操作时,会发现有如下的提示;以 fdisk /dev/sda 设备为例,以下同;

[root@localhost beinan]# fdisk /dev/sda
Command (m for help): 在这里按m ,就会输出帮助;
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition 注:这是删除一个分区的动作;
l list known partition types 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
o create a new empty DOS partition table
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition"s system id 注:t 改变分区类型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分区表写入硬盘并退出;
x extra functionality (experts only) 注:扩展应用,专家功能;

  其实我们常用的只有注有中文的,其它的功能我们不常用(呵,主要是我不会用,否则早会卖弄一下了);x扩展功能,也不是常用的;一般的情况下只要懂得 d l m p q t w 就行了;

本文来源:http://www.bbyears.com/caozuoxitong/113008.html