日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

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

發布時間:2024/7/23 linux 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux expect 扩容磁盘,openstack VM 磁盘扩容,修复 GPT 分区,更新分区表后,拉伸文件系统... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 分区,更新分区表后,拉伸文件系统...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。