コンテンツにスキップ

VMのディスクサイズを広げる

雑に書いたので,後で丁寧に書き直す. 基本的には以下のサイトを見ればできる.

参考 https://blog.k-san.info/expand-fs-on-ubuntu

1. パーティション構成をfdiskコマンドでみる.

sudo fdisk -l
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x15ecc3a4

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   2000895   1998848  976M 83 Linux
/dev/sda2       2000896 209715199 207714304   99G 83 Linux

2. swapパーティションが後ろにいる場合は,それを無効化する.

swapの確認

free -m

swapon -s

swapの無効化

sudo swapoff /dev/sda3

swapが無効化出来たか確認

swapon -s

3. swapパーティションを消す

4. パーティションを拡張する

esxiのwebコンソールから仮想ディスクの容量を増やす.

VMを再起動する.

partedに入る

koyama@koyama-log0:~$ sudo parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)                                                                  
(parted)                                                                  
(parted) p free                                                           
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 161GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1024MB  1023MB  primary               boot
 2      1024MB  107GB   106GB   primary  ext4
        107GB   161GB   53.7GB           Free Space

(parted)                                                                  
(parted)                                                                  
(parted) resizepart 2                                                       
Warning: Partition /dev/sda2 is being used. Are you sure you want to continue?
Yes/No? yes                                                               
End?  [107GB]? 100%                                                       
(parted) p free                                                           
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 161GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1024MB  1023MB  primary               boot
 2      1024MB  161GB   160GB   primary  ext4

(parted) quit                                                             
Information: You may need to update /etc/fstab.

koyama@koyama-log0:~$                        

5. /etc/fstabを修正

UUIDが変更されている場合は更新する.swapを無効化したのでコメントアウトする. 必要に応じてswapファイルで対応しても良い.

koyama@koyama-log0:~$ sudo blkid
/dev/sda2: UUID="c59f5603-b816-4e65-bace-024313d1ca5f" TYPE="ext4" PARTUUID="15ecc3a4-02"
/dev/sda1: PARTUUID="15ecc3a4-01"

6. ファイルシステムを拡張

koyama@koyama-log0:~$ sudo resize2fs /dev/sda2
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 19
The filesystem on /dev/sda2 is now 39071488 (4k) blocks long.