openstack VM 磁盘扩容,修复 GPT 分区,更新分区表后,拉伸文件系统

2014-06-23 分类:Hardware 标签:Openwrt Route

起因

之前,厂里 openstack 虚拟机,「云主机类型」不同模板定义的磁盘大小。是在原镜像的 「根磁盘」 上 附加 (attach) 相应大小的 「临时磁盘」 来实现的。在虚拟机里面看到的是 2 块独立的磁盘设备。将虚拟机「临时磁盘」扩容到逻辑卷组,以此做的快照启动,找不到之前附加的「临时磁盘」,杯具发生了: 起不来 -_-!

现在,不同模板直接指定不同大小的 「根磁盘」 ,不再使用 「临时磁盘」 。生成的虚拟机,就只看到一个 扩容后 (resize) 的磁盘。但由于母盘镜像大小和模板定义的磁盘大小不一样,parted 分区操作时,需要先修复分区,系统才能识别到相对母盘 扩容 的磁盘空间,然后分区,扩容逻辑卷组,拉伸文件系统,这样做的快照才可以正常使用。

经过

修复 GPT 分区

# parted /dev/vda

Using /dev/vda

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) p

Error: The backup GPT table is not at the end of the disk, as it should be.

This might mean that another operating system believes the disk is smaller.

Fix, by moving the backup to the end (and removing the old backup)?

Fix/Ignore/Cancel? f

Warning: Not all of the space available to /dev/vda appears to be used,

you can fix the GPT to use all of the space (an extra 125829120 blocks) or continue

with the current setting?

Fix/Ignore? f

parted 没有可以自动 Fix 分区表的命令行参数,只好用 expect 交互式修复 GPT 分区,并扩增分区

expect -c 'spawn parted /dev/vda; \

expect "(parted)"; send -- "p\r"; \

expect "Fix/Ignore/Cancel?"; send -- "f\r"; \

expect "Fix/Ignore?"; send -- "f\r"; \

expect "(parted)"; send -- "mkpart primary 42.9GB 100%\r"; \

expect "(parted)"; send -- "p\r"; \

expect "(parted)"; send -- "q\r"; \

exit'

更新分区表

上面修复完 GPT 分区后,会出现下面的提示,要重启才能重新识别 新分区 :

WARNING: the kernel failed to re-read the partition table on /dev/vda (Device or resource busy).

As a result, it may not reflect all of your changes until after reboot.

parted 虽然可以看到新分区,但系统里找不到 新分区 对应的 block 设备

# parted /dev/vda print

Model: Virtio Block Device (virtblk)

Disk /dev/vda: 129GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Number Start End Size File system Name Flags

1 1049kB 211MB 210MB ext4 boot

2 211MB 42.9GB 42.7GB lvm

3 42.9GB 129GB 85.9GB primary

# ls /dev/vda

vda vda1 vda2

# cat /proc/partitions

major minor #blocks name

252 0 125829120 vda

252 1 204800 vda1

252 2 41736192 vda2

尝试使用 partprobe 刷新分区表,结果无效。依然会提示 reboot 才能更新分区表When you update the partition table, you need to tell the kernel it has been updated. Normally you can use partprobe. However, on RHEL6 , this no longer works for disks that have partitions already mounted (e.g. your system disk on sda) This is considered too dangerous, so the developers stopped this in RHEL6 . You can work around this (although not advisable) by using partx to forcibly add new partitions to /proc/partitions

上面帖子说 RHEL6 中 partprobe 不支持更新 已挂载 的磁盘设备,要用 partx 命令 强制 更新分区表:

$ man partx

-a, --add

Add the specified partitions, or read the disk and add all partitions.

# partx -av /dev/vda

device /dev/vda: start 0 size 2097152000

gpt: 3 slices

# 1: 2048- 411647 ( 409600 sectors, 209 MB)

# 2: 411648- 83884031 ( 83472384 sectors, 42737 MB)

# 3: 83884032-251656191 (167772160 sectors, 85899 MB)

BLKPG: Device or resource busy

error adding partition 1

BLKPG: Device or resource busy

error adding partition 2

added partition 3

上面输出的 BLKPG: Device or resource busy,error adding partition 1 报错没关系。 因为前两个分区已经 被识别挂载 了,就不用再 画蛇舔脚 的重复添加到分区表了。 执行完后,就可以在 /proc/partitions 看到新识别的分区了

# cat /proc/partitions

major minor #blocks name

252 0 125829120 vda

252 1 204800 vda1

252 2 41736192 vda2

252 3 83886080 vda3

扩容文件系统

修复完分区表、更新完分区表。是该做正经事的时候了:扩容文件系统将新分区,添加物理卷

扩容逻辑卷组

拉伸逻辑卷

扩容文件系统

doit

+ pvcreate /dev/vda3

Writing physical volume data to disk "/dev/vda3"

Physical volume "/dev/vda3" successfully created

+ vgextend vg /dev/vda3

Volume group "vg" successfully extended

+ lvextend -l +100%FREE /dev/vg/home

Extending logical volume home to 87.75 GiB

Logical volume home successfully resized

+ resize2fs -p -F /dev/vg/home

Filesystem at /dev/vg/home is mounted on /home; on-line resizing required

old desc_blocks = 1, new_desc_blocks = 6

Performing an on-line resize of /dev/vg/home to 23003136 (4k) blocks.

The filesystem on /dev/vg/home is now 23003136 blocks long.

OVER

到此就完成了,虚拟机扩容文件系统的任务就完成了。。。

linux expect 扩容磁盘,openstack VM 磁盘扩容,修复 GPT 分区,更新分区表后,拉伸文件系统...相关推荐

  1. 磁盘基础基础知识(MBR,GPT分区格式)

    一,硬盘知识 硬盘接口类型: 并行: IDE: 133MB/s SCSI: 640MB/s 串口: SATA: 6Gbps(字节) SAS: 6Gbps USB: 480MB/s 硬盘结构示意图: 硬 ...

  2. MBR磁盘和GPT磁盘的基本磁盘和动态磁盘,FAT和NTFS文件系统——小结

    一.(针对一个分区)文件系统FAT和NTFS的结构区别 FAT文件系统:DBR-FAT1-FAT2-根目录-数据区(-剩余扇区) ->winhex查看FAT ,一般比较依赖boot templa ...

  3. linux扩容根目录空间_Linux系统扩容根目录磁盘空间的操作方法

    Linux系统扩容根目录磁盘空间的操作方法 一.使用背景 Linux根目录磁盘空间不够用了,当修改了虚拟机模版增加磁盘大小或者插入了一块新硬盘,但是发现系统里的大小还是没改变. 产生的原因是没有给磁盘 ...

  4. Linux基础篇——Linux磁盘操作(磁盘基础知识、分类、分区、挂载、卸载、扩容)详解

    目 录 1. 概 念 2. 为啥要分区 3. 磁盘的结构 4. 磁盘的分类 4.1 IDE硬盘 4.2 SCSI硬盘 4.3 SATA硬盘 4.4 固态硬盘 5. 磁盘分区命名规则 6. 磁盘分区类型 ...

  5. 完美解决VMware虚拟机 Linux系统 Ubuntu 20.04 硬盘/磁盘扩容的问题(超级超级详细)

    感谢CSDN博主的文章,我使用ubuntu20.04进行以下ubuntu16.04同样的操作步骤之后已经将40G扩充为80G 本文参考转装链接:https://blog.csdn.net/m0_434 ...

  6. Linux学习总结(八)-磁盘格式化,挂载,swap扩容

    上次我们学习了磁盘分区,磁盘分区完后还不能直接使用,需要对分区进行格式化,载入某个类型的文件系统,然后挂载到相应目录下才可使用. 一 磁盘格式化 格式化命令: mke2fs -t [ext2 ext3 ...

  7. linux(虚拟机) ext4系统磁盘扩容操作(磁盘多个分区,新增分区新增物理卷来扩容逻辑卷)

    目录 ext4文件系统磁盘扩容 目标 途径 操作步骤 改变前的现状 操作和改变后的状态 ext4文件系统磁盘扩容 一个磁盘有多个分区.分别创建了物理卷.卷组.逻辑卷.通过虚拟机软件对虚拟机的磁盘/de ...

  8. Linux下释放磁盘空间方法-磁盘不扩容处理

    目录 磁盘情况 磁盘清理 核对磁盘占用 磁盘使用情况查询df -h 磁盘目录层级查询 du -h --max-depth=1 系统磁盘空间 /opt + 6% /var/log/journal +7% ...

  9. (十一)openstack------块存储服务cinder,磁盘(卷)扩容,使用 NFS---后端存储

    文章目录 一. 介绍Cinder 二. 开始配置 初始化数据库 配置haproxy 1. 控制节点:8776 开始安装cinder服务 2. 计算节点---都要配置 3. 配置存储节点 3. 1存储安 ...

最新文章

  1. RecyclerView的使用(1)之HelloWorld
  2. 如何让UTF-8能对文档XML编辑
  3. Java直接内存与堆内存
  4. TabHost刷新activity的方法
  5. 读取html文件,让其中的内容和notepad打开这个html的样子一样。
  6. 3578. 最大中位数
  7. springboot+jsp+mybatis项目实例(后台成功,但是无法跳转jsp页面,没有实体类的注解,看springboot+jsp第二弹相关配置,即可成功配置jsp)...
  8. 游标sql server_了解游标并将其替换为SQL Server中的JOIN
  9. 在linux通过源码编译安装redis详细步骤
  10. 在PaddlePaddle框架下通过两层全连接网络实现IRIS数据分类
  11. 下列哪个滤波器是非线性的_上海海事数字信号处理2006试卷A参考答案
  12. html怎么设置自动音乐播放器,运用js教你轻松制作html音乐播放器
  13. 阶段1 语言基础+高级_1-3-Java语言高级_03-常用API第二部分_第2节 Date类_3_DateFormat类SimpleDateFormat类...
  14. c语言/abs()函数和fabs ()函数
  15. 计算机基础知识msoffice高级应用,2017计算机二级MS Office高级应用考试大纲
  16. 我们为何要选择使用LINUX?--大家自己体会
  17. 安卓app里播放youtube视频
  18. 关于parser.add_argument中choices参数问题
  19. EasyStack林冠宇当选OpenStack基金会技术委员会成员
  20. JavaScript三种注释写法

热门文章

  1. CRISP-DM:数据挖掘标准流程
  2. [poj3261]Milk Patterns
  3. ftp服务器PDF文件在线查看
  4. 两种方法解决tomcat的 Failed to initialize end point associated with ProtocolHandler [http-apr-8080]...
  5. SharePoint创建web application的时候报错
  6. [导入]Visual Studio 2005 Team Edition软件架构系列课程(1): 概述
  7. linux的基础知识——TCP异常断开
  8. Leetcode--238. 除自身以外数组的乘积
  9. linux java amr转mp3_本工具用于将微信语音 amr 格式转换为 mp3 格式以便在 html5 的 audio 标签中进行播放...
  10. python实现邮件客户端_利用python实现简单的邮件发送客户端示例