Updating a disk
After creating a disk, you can:
- Change the disk name and description.
- Increase the size of your disk, even if it is attached to a running VM.
Changing the disk name and description
To change the name and description of a disk:
- In the management console
, select the folder where you want to update a disk. - In the list of services, select Compute Cloud.
- In the left-hand panel, select
Disks. - Click
next to the disk and select Edit. - Edit the disk name and description.
- Click Save changes.
Compute Cloud will initiate disk updating.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for updating a disk:
yc compute disk update --help
-
Request a list of available disks:
yc compute disk list
Result:
+----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | PLACEMENT GROUP | DESCRIPTION | +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+ | a7lqgbt0bb9s******** | first-disk | 20401094656 | ru-central1-a | READY | a7lcvu28njbh******** | | | | a7lv5j5hm1p1******** | second-disk | 21474836480 | ru-central1-a | READY | | | | +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+
-
Select
ID
orNAME
of the disk, e.g.,first-disk
. -
Specify the name and description in the disk update command:
yc compute disk update first-disk \ --new-name updated-disk \ --description "Updated disk via CLI"
Compute Cloud will initiate disk updating.
To change the name or description of a disk, use the update REST API method for the Disk resource or the DiskService/Update gRPC API call.
To request a list of available disks, use the list REST API method or the DiskService/List gRPC API call.
Increasing the disk size
Note
You can only increase the size of a disk. Reducing it is not supported.
You can increase the disk size even on a running VM.
-
In the management console
, select the folder containing the disk. -
In the list of services, select Compute Cloud.
-
In the left-hand panel, select
Disks. -
Click
next to the disk and select Edit. -
Increase the disk size.
-
Click Save changes.
Compute Cloud will initiate disk resizing.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for updating a disk:
yc compute disk update --help
-
Request a list of available disks:
yc compute disk list
Result:
+----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | PLACEMENT GROUP | DESCRIPTION | +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+ | a7lqgbt0bb9s******** | first-disk | 20401094656 | ru-central1-a | READY | a7lcvu28njbh******** | | | | a7lv5j5hm1p1******** | second-disk | 21474836480 | ru-central1-a | READY | | | | +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+
-
Select
ID
orNAME
of the disk, e.g.,first-disk
. -
Specify the size, e.g., 32 GB, in the disk update command:
yc compute disk update first-disk \ --size 32
Compute Cloud will initiate disk resizing.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
If you don't have Terraform, install it and configure the Yandex Cloud provider.
Warning
You can increase the disk size using Terraform without recreating the VM if the disk is specified in the manifest as a separate yandex_compute_disk
resource.
If the disk is specified under initialize_params
in the yandex_compute_instance
resource, the VM will be recreated when increasing the disk size using Terraform. To increase the size of such a disk without recreating the VM, use the management console, CLI, or API.
-
In the Terraform configuration file, define the parameters of the resources you want to create:
# Creating a disk resource "yandex_compute_disk" "first-disk" { name = "<disk_name>" type = "<disk_type>" zone = "<availability_zone>" size = "<disk_size>" image_id = "<image_ID>" } # Creating a VM resource "yandex_compute_instance" "vm-lamp" { name = "<VM_name>" platform_id = "standard-v3" zone = "<availability_zone>" resources { core_fraction = <vCPU_performance_level> cores = <number_of_vCPUs> memory = <RAM_in_GB> } boot_disk { disk_id = yandex_compute_disk.first-disk.id } network_interface { subnet_id = "<subnet_ID>" nat = true security_group_ids = [<security_group_ID>] } metadata = { user-data = "#cloud-config\nusers:\n - name: <username>\n groups: sudo\n shell: /bin/bash\n sudo: 'ALL= (ALL) NOPASSWD:ALL'\n ssh_authorized_keys:\n - <SSH_key_contents>" } }
-
Create the resources:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-
-
To increase the disk size, make the following changes to the configuration file:
resource "yandex_compute_disk" "first-disk" { ... size = "<new_disk_size>" }
Where
size
is the new size for the disk. -
Apply the changes:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
This will increase the disk size. You can check the disk size and settings using the management console
or this CLI command:yc compute disk get <disk_name>
-
You can increase the disk size by using the update REST API method for the Disk resource or the DiskService/Update gRPC API call.
To request a list of available disks, use the list REST API method or the DiskService/List gRPC API call.
To change the size of the boot disk, restart the VM.
Increasing the size of a Linux disk partition
After increasing the disk size, you also need to increase the size of its partitions and file systems. For boot disks, this happens automatically after you restart the VM.
You can also increase the size of any VM disk without restarting the VM. The workflow depends on the file system of the disk partition in question:
-
Connect to the VM via SSH:
ssh <username>@<VM_public_IP_address>
-
See the disks attached to the VM:
lsblk
Result:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS vda 252:0 0 25G 0 disk ├─vda1 252:1 0 1M 0 part └─vda2 252:2 0 25G 0 part / vdb 252:16 0 64G 0 disk └─vdb1 252:17 0 32G 0 part /data
Disk partitions are listed under
NAME
. If theMOUNTPOINTS
column contains a value for the partition you need, it means the partition is mounted. -
Unmount the partition if you want to check and recover its file system before resizing the partition. Otherwise, proceed to the next step.
-
Unmount the disk:
sudo umount /data
Where
/data
is the partition mount point. -
Check and recover the file system:
sudo e2fsck -f /dev/vdb1
Result:
e2fsck 1.44.1 (24-Mar-2018) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vdb1: 11/2097152 files (0.0% non-contiguous), 143890/8388352 blocks
-
-
Resize the partition:
sudo growpart /dev/vdb 1
Where:
/dev/vdb
: Device name.1
: Partition number, which must be separated by a space.
Result:
CHANGED: partition=1 start=2048 old: size=67106816 end=67108864 new: size=134215647,end=134217695
-
Resize the file system:
sudo resize2fs /dev/vdb1
Where
dev/vdb1
is the partition name.Result:
Resizing the filesystem on /dev/vdb1 to 16776955 (4k) blocks. The filesystem on /dev/vdb1 is now 16776955 (4k) blocks long.
-
If you unmounted the partition to perform a file system check, remount it:
sudo mount /dev/vdb1 /data
-
Make sure the partition size has increased:
lsblk
Result:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS vda 252:0 0 25G 0 disk ├─vda1 252:1 0 1M 0 part └─vda2 252:2 0 25G 0 part / vdb 252:16 0 64G 0 disk └─vdb1 252:17 0 64G 0 part /data
-
Connect to the VM via SSH:
ssh <username>@<VM_public_IP_address>
-
See the disks attached to the VM:
lsblk
Result:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS vda 252:0 0 25G 0 disk ├─vda1 252:1 0 1M 0 part └─vda2 252:2 0 25G 0 part / vdb 252:16 0 64G 0 disk └─vdb1 252:17 0 32G 0 part /data
Disk partitions are listed under
NAME
. Partition mount points are displayed underMOUNTPOINTS
. -
Run this command:
sudo growpart /dev/vdb 1
Where:
/dev/vdb
: Device name.1
: Partition number, which must be separated by a space.
Result:
CHANGED: partition=1 start=2048 old: size=67106816 end=67108864 new: size=134215647,end=134217695
-
Resize the file system:
sudo xfs_growfs /data -d
Where:
/data
: Mount point of the partition whose size you need to increase.-d
: Parameter for increasing partition size.
Result:
meta-data=/dev/vdb1 isize=512 agcount=4, agsize=655360 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=0 inobtcount=0 data = bsize=4096 blocks=2621440, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 2621440 to 11796219
-
Make sure the partition size has increased:
lsblk /dev/vdb
Result:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS vdb 252:16 0 64G 0 disk └─vdb1 252:17 0 64G 0 part /data