使用情况:

1. 虚拟机配置150G硬盘,初始化为/dev/sdb1,后因为磁盘空间不够使用,动态扩容至300G,扩容完成后,想要动态扩容/dev/sdb1分区。

2. 磁盘空间300G,之前分区只划分150G的/data分区,现在/data不够使用,想要把剩余150G容量动态增加到之前/data分区,并且保证/data数据不损坏

操作(以/data为例):

1.  关闭/data分区使用的服务

2. 卸载磁盘

使用umount命令卸载正在使用的/data磁盘

umount -l /data
若遇到磁盘繁忙,可以使用fuser查看正在使用磁盘的程序。
fuser -mv /data
手工退出或关闭占用文件的用户或程序。或者采用如下交互式命令强制kill掉使用/data进程
fuser -mvik /data
fuser命令参数含义:

-m     name specifies a file on a mounted file system or a block device that is mounted. All processes accessing files  on  that  file system  are  listed.  If a directory file is specified, it is automatically changed to name/. to use any file system that might be mounted on that directory.
-c Same as -m option, used for POSIX compatibility.
-V Display version information.
-k Kill processes accessing the file. Unless changed with -signal, SIGKILL is sent. An fuser process never kills itself, but may kill other fuser processes. The effective user ID of the process executing fuser is set to its real user ID before attempting to kill.
-i Ask the user for confirmation before killing a process. This option is silently ignored if -k is not present too.

3. 磁盘分区

使用fdisk命令重新调整磁盘分区大小。删除之前的分区,然后建立新分区。开始的磁柱号要和原来一致(否则会导致数据丢失),结束的磁柱号默认使用全部空间。

fdisk -cu /dev/sdb

p            #查看磁柱号 ,记住,后面要用到
d #删除之前的分区
n #建立新分区
p #主分区
#第一个主分区
wq #保存退出

4. 调整分区文件系统

e2fsck -f /dev/sdb1                  #检查分区信息
resize2fs /dev/sdb1 #调整分区文件系统 命令含义:
e2fsck - check a Linux ext2/ext3/ext4 file system
e2fsck is used to check the ext2/ext3/ext4 family of file systems. For ext3 and ext4 filesystems that use a journal, if the system
has been shut down uncleanly without any errors, normally, after replaying the committed transactions in the journal, the file system
should be marked as clean. Hence, for filesystems that use journalling, e2fsck will normally replay the journal and exit, unless its
superblock indicates that further checking is required.
resize2fs -   ext2/ext3/ext4 file system resizer
The resize2fs program will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system
located on device. If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel
supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and
ext4.). 如果采用虚拟机动态增加磁盘方式,需要重新通知内核分区表变化或者重启设备
partprobe /dev/sdb partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system
re-read the partition table.

5. 重新挂载文件系统

手工挂载/data目录
mount /dev/sdb1 /data 如果想要重启后自动挂载目录,需要在/etc/fstab增加下边的配置
/dev/sdb1 /data ext4 defaults

CentOS使用fdisk扩展磁盘空间的更多相关文章

  1. VirtualBox下Linux(centos)扩展磁盘空间

    最近在Linux里做文件合并,做分词,磁盘空间不够,把扩展磁盘空间方法记录一下. 1.在VirtualBox安装路径下(例如C:\Program Files\Oracle\VirtualBox> ...

  2. VMwave下Ubuntu扩展磁盘空间

    VMwave下Ubuntu扩展磁盘空间 Ubuntu原预装磁盘空间20G,随着系统安装软件越来越多,空间慢慢不够用. 打算安装DB2,许扩展磁盘空间. 环境: No LSB modules are a ...

  3. Centos7在虚拟机中扩展磁盘空间

    说明 情况:已经在VirtualBox虚拟机创建了一个磁盘并已经装好了系统,发现磁盘空间太小,需要再添加一个磁盘的大小.或者说Centos7系统需要扩展磁盘空间. 步骤 1.VirtualBox新建磁 ...

  4. kvm虚拟机扩展磁盘空间

    kvm虚拟机磁盘空间扩展与xen虚拟机磁盘空间扩展思路一致.原因在于xen/kvm默认的虚拟机磁盘格式为raw,所以方式可以通用. raw磁盘格式扩展思路如下 (1) 新添加一块raw格式的磁盘加入到 ...

  5. virtualBox下Centos系统扩展磁盘空间

    (1)查看空间容量: 打开windows命令终端.然后打开virtualbox安装目录,找到VBoxManage.exe,拖动到终端里面.输入命令:list hdds,回车. 我安装的位置是 : C: ...

  6. centos虚拟机扩展磁盘空间(经历无数坑,血一样总结,史上最全)

    第一步 在vmware中将虚拟机关机后,鼠标右键设置,直接点击扩展加自己想要扩展的数量就可以了,这个比较简单不多说. 2 第二步 设置后进系统查看空间大小变化,实际并没有什么变化,我用的命令是df - ...

  7. 虚拟机vmware centos7 扩展磁盘空间

    0.思路 创建一个新的逻辑分区,将新的逻辑分区格式化ext3(或其他类型)的文件系统,mount到磁盘空间不够的文件系统,就跟原来的分区/文件系统一样的使用 1.准备 1.1 注意使用VMware自带 ...

  8. Centos7扩展磁盘空间(LVM管理)

    vmware或hyperv,扩容磁盘,本例中使用的是vmware,关闭系统,在vmware—>设置—>硬盘—>扩展—>输入数字大于当前系统内存—>点击扩展,如图: 1.  ...

  9. 给VMware下的Linux扩展磁盘空间(以CentOS6.5为例)

    #查看挂载点:df -h#显示: 文件系统 容量 已用 可用 已用%% 挂载点/dev/mapper/vg_dc01-lv_root47G 12G 34G 25% /tmpfs 504M 88K 50 ...

随机推荐

  1. python高级(四)—— 文本和字节序列(编码问题)

    本文主要内容 字符 字节 结构体和内存视图 字符和字节之间的转换——编解码器 BOM鬼符  标准化Unicode字符串 Unicode文本排序 python高级——目录 文中代码均放在github上: ...

  2. [Alpha]Scrum Meeting#4

    github 本次会议项目由PM召开,时间为4月5日晚上10点30分 时长20分钟 任务表格 人员 昨日工作 下一步工作 木鬼 调整&分配工作 撰写博客目录 SiMrua 手工建立再训练数据( ...

  3. [BZOJ 4857][Jsoi2016]反质数序列

    传送门 $ \color{green} {solution : } $ 因为 $ 1 $ 的个数我们最多只能选一个,所以剩下的数如果组成素数那么只有一奇一偶,显然是个二分图模型 #include &l ...

  4. Go语言包和文件

    工作空间 Go语言工作空间:编译工具对源码目录有严格要求,每个工作空间 (workspace) 必须由bin.pkg.src三个目录组成. src ---- 项目源码目录,里面每一个子目录,就是一个包 ...

  5. Chrome打开网页都提示Flash Player因过期而遭到阻止

    1. 运行Chrome浏览器,地址栏输入:chrome://plugins/,找到pepflashplayer.dll安装位置, 如:D:\Program Files\GoogleChromePort ...

  6. sklearn的train_test_split

    train_test_split函数用于将矩阵随机划分为训练子集和测试子集,并返回划分好的训练集测试集样本和训练集测试集标签. 格式: X_train,X_test, y_train, y_test ...

  7. C++ 流控制函数setw()、setfill()、setbase()、setprecision()的使用

    头文件: #include <iostream> #include <iomanip> 功能: std::setw :需要填充多少个字符,默认填充的字符为' '空格 std:: ...

  8. 《WCF全面解析》-上册 1-3章 读书笔记

    第一章.WCF简介 ESB全称为Enterprise Service Bus,即企业服务总线.把所有的服务统筹到一个总线里面请求和分发,方便管理. WCF(Windows Communication ...

  9. springboot实现服务器端消息推送(H5原生支持)

    随着互联网的发展,传统的HTTP协议已经很难满足Web应用日益复杂的需求了.近年来,随着HTML5的诞生,WebSocket协议被提出,它实现了浏览器与服务器的全双工通信,扩展了浏览器与服务端的通信功 ...

  10. Access如何判断字符串从左边第一个数字为5

    步骤如下: 1.打开VBA(ALT+F11)2.右键模块=>插入=>模块3.粘贴以下代码: Public Function CutStr(chkStr As String) As Stri ...