Linux Server

(3)ゲストのCentOS7サーバのディスク容量が不足してきたので拡張(トラブル編)

  

ご注意下さい

この記事は3年以上前に書かれた記事ですので、内容が古い可能性があります。

5
(1)

さて、3回目はトラブル編です。

仮想サーバを起動し、fdiskで/dev/sda3を一回削除し、拡張したサイズまでで再作成することで/dev/sda3を拡張しようとしたところ、

# fdisk /dev/sda
 
The 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.
 
 
コマンド (m でヘルプ): p
 
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0x00000000
 
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 1 20971519 10485759+ ee GPT
パーティション 1 は物理セクタ境界で始まっていません:
 
コマンド (m でヘルプ):
 

なんだかパーティションテーブルが壊れてしまっていました。Hyper-Vを再起動する為にWidows2012R2を再起動しても同様の事象は変わらず途方にくれましたが事前に情報は取ってあるし、バックアップも取ってあるので思い切ってfdiskで以前のパーティションサイズ分だけ割り当てることとしました。

以前のバックアップ情報は以下の通りです。

# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
 
Disk /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 サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: gpt
 
 
# Start End Size Type Name
1 2048 411647 200M EFI System EFI System Partition
2 411648 1435647 500M Microsoft basic
3 1435648 20969471 9.3G Linux LVM
 
Disk /dev/mapper/centos-root: 8883 MB, 8883535872 bytes, 17350656 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
 
 
Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
 
#

上記の通りに割り当てていきます。ここで上記のDisk label typeが「gpt」で、今回は「dos」なっていることに気付いていれば別の方法があったかもしれません。fdiskではなくgdiskを使うとか…。

# fdisk /dev/sda
 
The 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.
 
 
コマンド (m でヘルプ): d
Selected partition 1 /dev/sda1を消してしまいます
Partition 1 is deleted
 
コマンド (m でヘルプ): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
パーティション番号 (1-4, default 1): 1 /dev/sda1を作り直します
最初 sector (2048-41943039, 初期値 2048):
初期値 2048 を使います
Last sector, +sectors or +size{K,M,G} (2048-41943039, 初期値 41943039): 411647
Partition 1 of type Linux and of size 200 MiB is set
 
コマンド (m でヘルプ): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
パーティション番号 (2-4, default 2):/dev/sda2を作り直します
最初 sector (411648-41943039, 初期値 411648):
初期値 411648 を使います
Last sector, +sectors or +size{K,M,G} (411648-41943039, 初期値 41943039): 1435647
Partition 2 of type Linux and of size 500 MiB is set
 
コマンド (m でヘルプ): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
パーティション番号 (3,4, default 3):/dev/sda3を作り直します
最初 sector (1435648-41943039, 初期値 1435648):
初期値 1435648 を使います
Last sector, +sectors or +size{K,M,G} (1435648-41943039, 初期値 41943039):
初期値 41943039 を使います
Partition 3 of type Linux and of size 19.3 GiB is set 10GBから20GBに拡張された(はずでした)

ファイルシステムのタイプが全部Linuxになってしまったので、コマンド tで変更しようとしましたが、該当するファイルタイプがない…。なんでだろう。
ということでとりあえず似たようなファイルタイプを設定しました。
 

 
コマンド (m でヘルプ): p
 
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0x00000000
 
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 2048 411647 204800 ef EFI (FAT-12/16/32)
/dev/sda2 411648 1435647 512000 83 Linux
/dev/sda3 1435648 41943039 20253696 8e Linux LVM
 

なんか違うと思いましたが、まぁいいや、ということで再起動。無事に起動しました。
ここでなんかおかしいと思いようやくDisk label typeがdosになってしまっていることに気づき、まずはgdiskを使ってMBR⇒GPTに移行しました。

# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.6
 
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: present GPTも残っていました
 
Found valid MBR and GPT. Which do you want to use?
1 - MBR
2 - GPT
3 - Create blank GPT
 
Your answer: 2 GPTを使います
Using GPT and creating fresh protective MBR.
 
Command (? for help): w 書き込みます
Warning! Secondary header is placed too early on the disk! Do you want to
correct this problem? (Y/N): y
Have moved second header and partition table to correct location.
 
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
 
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
 

ここで一旦リブートします。再度gdiskします。

 
# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.6
 
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
 
Found valid GPT with protective MBR; using GPT.
 
Command (? for help): p
Disk /dev/sda: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): E599B533-2652-47B4-8C5F-A215B495F593
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 20975549 sectors (10.0 GiB)
 
Number Start (sector) End (sector) Size Code Name
1 2048 411647 200.0 MiB EF00 EFI System Partition
2 411648 1435647 500.0 MiB 0700
3 1435648 20969471 9.3 GiB 8E00 なぜか拡張前に戻ってます
 
Command (? for help): t
Partition number (1-3): 2
Current type is 'Microsoft basic data'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS
7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved
8200 Linux swap 8300 Linux filesystem 8301 Linux reserved
8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot
a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS
a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot
a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS
a585 Midnight BSD Vinum a800 Apple UFS a901 NetBSD swap
a902 NetBSD FFS a903 NetBSD LFS a904 NetBSD concatenated
a905 NetBSD encrypted a906 NetBSD RAID ab00 Apple boot
af00 Apple HFS/HFS+ af01 Apple RAID af02 Apple RAID offline
af03 Apple label af04 AppleTV recovery af05 Apple Core Storage
be00 Solaris boot bf00 Solaris root bf01 Solaris /usr & Mac Z
bf02 Solaris swap bf03 Solaris backup bf04 Solaris /var
bf05 Solaris /home bf06 Solaris alternate se bf07 Solaris Reserved 1
bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 bf0a Solaris Reserved 4
bf0b Solaris Reserved 5 c001 HP-UX data c002 HP-UX service
ed00 Sony system partitio ef00 EFI System ef01 MBR partition scheme
ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved
fc00 VMWare kcore crash p fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 8300): 0700
Changed type of partition to 'Microsoft basic data'
 
Command (? for help): p
Disk /dev/sda: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): E599B533-2652-47B4-8C5F-A215B495F593
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 20975549 sectors (10.0 GiB)
 
Number Start (sector) End (sector) Size Code Name
1 2048 411647 200.0 MiB EF00 EFI System Partition
2 411648 1435647 500.0 MiB 0700
3 1435648 20969471 9.3 GiB 8E00
 
Command (? for help): p
Disk /dev/sda: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): E599B533-2652-47B4-8C5F-A215B495F593
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 20975549 sectors (10.0 GiB)
 
Number Start (sector) End (sector) Size Code Name
1 2048 411647 200.0 MiB EF00 EFI System Partition
2 411648 1435647 500.0 MiB 0700
3 1435648 20969471 9.3 GiB 8E00
 
Command (? for help): w
 
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
 
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
#

上記操作はあまり意味が結局ありませんでした。よく見るとファイルタイプは拡張前と同じになっていますね。MBR⇒GPTすることで復活したものと思ってます。
結論としては、最初からgdiskを使ってDisk Labelをgptに変更するオペレーションで治ったものと思われます。

さて、次回はいよいよ、というかようやくLVの拡張をしたいと思います。

ゲストのCentOS7サーバのディスク容量が不足してきたので拡張(目次)

この記事は役に立ちましたか? | Is this article useful for you?

評価をお願いします | Please leave your rating.

平均 | Av.: 5 / 5. 投票数 | Votes: 1

最初の評価を下さい | Please vote for the first rating.

-Linux Server
-, ,

© 1999 - 2021 蒲田ネット