详解:Hyper-V虚拟主机数据磁盘扩容
一直以来对Hyper-V Linux虚拟主机的磁盘扩容困扰,今天将介绍如何利用 fdisk 和 resize2fs 进行数据磁盘扩容。
情况说明:
宿主机系统:Windwos Server 2012 R2 Hyper-V
虚拟主机:CentOS Linux release 7.4.1708 (Core)
平时接触Hyper-V较多,所以对磁盘扩容那是常有的事。Windwos磁盘扩容最简单,本文就不多介绍了。
今天我将以Centos虚拟主机进行演示,该小机分为两块磁盘(都是独立磁盘),一块是系统盘/dev/sda,另一块是数据库盘/dev/sdb,现在的需求是sdb需要在不影响数据的情况下从原来的30GB扩容为100GB。
[root@renwole-com ~]# fdisk -lDisk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0x5f149419Device Boot Start End Blocks Id System /dev/sdb1 2048 62914559 31456256 83 LinuxDisk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0x00043041Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 20971519 9436160 8e Linux LVMDisk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes[root@renwole-com ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cl-root xfs 8.0G 950M 7.1G 12% / devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs tmpfs 1.9G 8.3M 1.9G 1% /run tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 138M 877M 14% /boot tmpfs tmpfs 379M 0 379M 0% /run/user/0 /dev/sdb1 ext4 30G 60M 28G 1% /apps
注意:橙色部分 /dev/sdb1 分区大小是30GB,挂载的也是30GB。
删除 /etc/fstab 文件中以下开机磁盘自动挂载信息:
/dev/sdb1 /apps ext4 defaults 0 0
Hyper-V虚机操作:
打开Hyper-V 管理器,找到需要扩容的小机并关机,然后右击设置,点击需要扩容的磁盘,(一般是数据盘)编辑 – 默认下一步 – 选择扩展下一步,这一步骤需要注意,假设你原有磁盘为30G,那么你想扩展到100G,请填写100即可,点击下一步完成。然后启动虚拟主机。
查看扩容后的磁盘分区情况:
[root@renwole-com ~]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0x00043041Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 20971519 9436160 8e Linux LVMDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0x5f149419Device Boot Start End Blocks Id System /dev/sdb1 2048 62914559 31456256 83 LinuxDisk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes
sdb分区大小由原来的30GB扩展到100GB了,但分区sdb1并没有使用扩容的70GB空间,怎么办呢?
删除分区不同等删除数据,删除分区再重建:
[root@renwole-com ~]# fdisk /dev/sdbThe device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted. Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them. Be careful before using the write command.Command (m for help): d # 删除sdb1分区 Selected partition 1 Partition 1 is deletedCommand (m for help): n # 新建分区 Partition type:p primary (0 primary, 0 extended, 4 free)e extended Select (default p): p Partition number (1-4, default 1): 1 # 指定分区号 First sector (2048-209715199, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): Using default value 209715199 Partition 1 of type Linux and of size 100 GiB is setCommand (m for help): w # 输入w保存 The partition table has been altered!Calling ioctl() to re-read partition table. Syncing disks.
再次查看磁盘分区情况
[root@renwole-com ~]# fdisk -l ... Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0x5f149419Device Boot Start End Blocks Id System /dev/sdb1 2048 209715199 104856576 83 Linux ...
已经从原来的30G扩展成100G了,但现在还不能使用,需要进行如下操作才算真正扩容成功:
[root@renwole-com ~]# resize2fs -f /dev/sdb1 resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/sdb1 to 26214144 (4k) blocks. The filesystem on /dev/sdb1 is now 26214144 blocks long.
扩容成功。
[root@renwole-com ~]# mount /dev/sdb1 /apps/ [root@renwole-com ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cl-root xfs 8.0G 950M 7.1G 12% / devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs tmpfs 1.9G 8.3M 1.9G 1% /run tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 138M 877M 14% /boot tmpfs tmpfs 379M 0 379M 0% /run/user/0 /dev/sdb1 ext4 99G 60M 94G 1% /apps [root@renwole-com ~]# ls /apps/ web mysql
如上所示,Linux虚拟主机数据盘已经成功扩容,查看数据并无丢失。
另外再次将你的磁盘信息写入到 /etc/fstab 文件中,不然重启后磁盘还需要手动挂载。
注意:还是那句话,操作任何数据之前,一定要先备份,养成良好的习惯,以防止数据丢失。
免费提供最新Linux技术教程书籍,为开源技术爱好者努力做得更多更好:https://www.linuxprobe.com/
详解:Hyper-V虚拟主机数据磁盘扩容相关推荐
- Nginx详解+身份验证+虚拟主机+反向代理负载均衡
一.差异对比 Apache Nginx 配置相对复杂 配置相对简单 原生支持动态和静态页面 支持静态页面 模块相对安全 高性能模块出产迅速.社区活跃 BUG相对较少,消耗资源较多 BUG相对较多,节省 ...
- 详解iPhone Tableview分批显示数据
iPhone Tableview分批显示数据是本文要介绍的内容,主要讲解的是数据的显示.iPhone屏幕尺寸是有限的,如果需要显示的数据很多,可以先数据放到一个table中,先显示10条,table底 ...
- python提取邮件附件_详解python实现读取邮件数据并下载附件的实例
详解python实现读取邮件数据并下载附件的实例 实现结果图: 实现代码: #!/usr/bin/python2.7 # _*_ coding: utf-8 _*_ """ ...
- 详解智能交通应用大数据“三重门”
文章讲的是详解智能交通应用大数据"三重门",武汉市悬在路口立杆上的金属小盒子--超级电子眼3个月抓了13万起交通违法,逆行.压线.套牌一眼识别,并能自动报警. 只需10秒,重庆市凭 ...
- python列表拆包_详解python 拆包可迭代数据如tuple, list
详解python 拆包可迭代数据如tuple, list 拆包是指将一个结构中的数据拆分为多个单独变量中. 以元组为例: >>> a = ('windows', 10, 25.1, ...
- 《策略驱动型数据中心——ACI技术详解》一1.3 数据中心设计
本节书摘来自异步社区<策略驱动型数据中心--ACI技术详解>一书中的第1章,第1.3节,作者[美]Lucien Avramov [意]Maurizio Portolani,更多章节内容可以 ...
- 万字HBase详解带你畅游大数据的海豚湾
写在前面:我是「且听风吟」,目前是某上市游戏公司的大数据开发工程师,热爱大数据开源技术,喜欢分享自己的所学所悟,现阶段正在从头梳理大数据体系的知识,以后将会把时间重点放在Spark和Flink上面. ...
- 子网划分-详解为何两台主机网络掩码不一致却能ping通
可参考:子网划分方法和例题详解_wj31932的博客-CSDN博客_ip子网划分方法 网络地址不同,没有网关,为什么直接能ping通? 看到网上有人问网络地址不同的两台pc,没配置网关,为啥 ...
- 【Qt开发】V4L2 API详解 Buffer的准备和数据读取
前面主要介绍的是:V4L2 的一些设置接口,如亮度,饱和度,曝光时间,帧数,增益,白平衡等.今天看看V4L2 得到数据的几个关键ioctl,Buffer的申请和数据的抓取. 1. 初始化 Memory ...
最新文章
- sql server面试题
- Sklearn的train_test_split用法
- SAP QM创建一个包含Multiple Specification的检验计划
- swift选择类或结构体
- ThreadLocal 变量和 与线程池配合使用时可能会出现的问题
- 剖析入侵技术 嗅探软件了解
- spark实验遇到的问题
- Sublime Text 3 插件安装
- 路由器和交换机的区别详解
- 击败酷睿i9之后,有人又拿苹果M1去挑战英伟达V100了
- Fedora和Red Hat Enterprise Linux实用指南(第6版)(套装上下册)火热上市!!!!
- SAP License:SAP Business One系统功能
- 第一次冲刺-站立会议08
- 网平差中的基线定权(松弛因子)
- ORACLE函数返回数据或字符串
- python什么意思g_python字符串%%g的格式是什么?
- java实现多模匹配算法_多模字符串匹配算法-Aho–Corasick
- 【数据分享】我国地级市绿地利用现状数据(9个指标\Shp格式)
- Hide column
- Badusb 攻击之MacOSX系统实战
热门文章
- 【关键词排名提升工具】快排宝快速提升网站排名
- freerdp 解压安装_linux下使用FreeRDP 连接 Windows 远程桌面
- freerdp 解压安装_Linux下安装FreeRDP,连接Windows远程桌面的好软件软件
- 16年就火起来的VR技术,为什么还没有崛起?
- zuiqingchun3
- Java小程序开发实例!字节跳动Java岗经典面试真题,实战解析
- 火爆全网送给女朋友的微信每日多次消息推送程序来了!多版本多平台!
- 【springmvc】九大组件之HandlerExceptionResolver
- Sea-thru: A Method For Removing Water From Underwater Images论文研读
- fufu笔记之多线程