使用情况:

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. ios真机测试问题

    前端页面在ios端真机测试出现的问题 由于苹果对于性能的要求是近乎苛刻,如果没有可点的特性的元素系统默认不会给它响应事件,因此真机测试时容易添加不上绑定事件 解决办法: 1.通过js判断当前是否为苹果 ...

  2. telent三种认证及vlan简单划分

    实验一 telent三种认证方式登录 实验拓扑图如下: 操作过程: 1.认证模式为none R1操作:       1.system-view进入系统试图2.telnet server enable开 ...

  3. FreeRTOS-01移植及任务创建和删除

    根据正点原子FreeRTOS视频整理 单片机:STM32F207VC FreeRTOS源码版本:v10.0.1 任务创建和删除API函数: 工程列表: 1. main.c /**/ #include ...

  4. 创建djangoapp

    1.python3 manage.py startapp goods 2.startapp users 3.启动django服务器 # make new migrationspython3 manag ...

  5. UML-6.2-用例-用例模型/用例/场景关系

    参与者:具有某些行为的人或事物.如上一章中的收银员. |_主要参与者:收银员. |_协助参与者:程序(自动付费.帮收银员验证输入要素) |_幕后参与者:政府等(电子签章取证找公证机构) 用例:一组相关 ...

  6. 练习 DOUBLE INSERT

      练习 DOUBLE INSERT 目标:从一张表取数据插入到另一张表中,此外需要为插入的目标表做一个应用级的日志表,也就是说在插入目标表的同时,还需要将相同的数据插入到日志表中. 在案例一中,我们 ...

  7. python3 zip压缩

    参考: https://docs.python.org/3/library/zipfile.html https://zhidao.baidu.com/question/149840976436638 ...

  8. python设计模式--读书笔记

    GoF在其设计模式一书中提出了23种设计模式,并将其分为三类: 创建型模式 将对象创建的细节隔离开来,代码与所创建的对象的类型无关. 结构型模式 简化结构,识别类与对象间的关系,重点关注类的继承和组合 ...

  9. google +ubuntu16.04

    1.在终端中输入以下命令 sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P /etc/apt/sources.list.d/ 2 ...

  10. SQLite3开发接口函数详解

    SQLite3是SQLite一个全新的版本,它虽然是在SQLite 2.8.13的代码基础之上开发的,但是使用了和之前的版本不兼容的数据库格式和API. SQLite3是为了满足以下的需求而开发的: ...