0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Vagrant / debian で作成した仮想マシンのディスクを拡張する

Posted at

VagrantでUbuntuのboxを使って仮想マシンを作成し, ディスクサイズを指定する場合は次のような内容のVagrantfileを用意する.

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/jammy64"
  config.vm.disk :disk, size: "40GB", primary: true
end

ところで, UbuntuではなくDebianで仮想マシンを作成した場合, 認識されるディスクサイズが変わらない.

vagrant@bullseye:~$ df -text4 -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G  816M   18G   5% /

dfコマンドではなくfdiskで調べると, ちゃんと指定したサイズのパーティションになっている.

この原因がよくわからず, とりあえずUbuntuを使っていたけど, ふと気になってChatGPTに聞いてみたらあっさり解決した.

resize2fs コマンドをパーティションに実行してやると期待したディスクサイズになるらしい.

vagrant@bullseye:~$ sudo resize2fs /dev/sda1
resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 5
The filesystem on /dev/sda1 is now 10485499 (4k) blocks long.

vagrant@bullseye:~$ df -text4 -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        40G  864M   37G   3% /

Vagrantfile にはインラインスクリプトで指定しておけばよさそう.

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "debian/bullseye64"
  config.vm.disk :disk, size: "40GB", primary: true

  config.vm.provision "shell", inline: <<-SHELL
  resize2fs /dev/sda1
  SHELL
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?