Updating a disk
After you create 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 disk name and description:
- 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 you need and select Edit. - Change the disk name and description.
- Click Save changes.
Compute Cloud will start the operation to update the disk.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI disk update command:
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 the
ID
orNAME
of the disk you need, 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 start the operation to update the disk.
To change the disk name or description, use the update REST API method for the Disk resource or the DiskService/Update gRPC API call.
To request the 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 change the size of a disk by increasing it. You cannot reduce the size of a disk.
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 you need and select Edit. -
Increase the disk size.
-
Click Save changes.
Compute Cloud will launch the operation to change the disk size.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI disk update command:
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 the
ID
orNAME
of the disk you need, 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 launch the operation to change the disk size.
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, describe 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_vCPU_cores> memory = <RAM_size_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 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 disk size. -
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 size of the disk and its 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 the 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 disk of the VM without restarting it. The workflow depends on the file system of the disk partition you need:
-
Connect to the VM over 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 in the
NAME
column. 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 restore its file system before changing the partition size. Otherwise, proceed to the next step.
-
Unmount the disk:
sudo umount /data
Where
/data
is the partition mount point. -
Check and restore 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
-
-
Change the partition size:
sudo growpart /dev/vdb 1
Where:
/dev/vdb
: Device name.1
is the partition number, so it is separated by a space.
Result:
CHANGED: partition=1 start=2048 old: size=67106816 end=67108864 new: size=134215647,end=134217695
-
Change the file system size:
sudo resize2fs /dev/vdb1
Where
dev/vdb1
is the name of the partition.Result:
Resizing the filesystem on /dev/vdb1 to 16776955 (4k) blocks. The filesystem on /dev/vdb1 is now 16776955 (4k) blocks long.
-
If you ran a file system check and unmounted the partition, mount it again:
sudo mount /dev/vdb1 /data
-
Make sure that the partition 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 over 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 in the
NAME
column. Partition mount points are shown in theMOUNTPOINTS
column. -
Run this command:
sudo growpart /dev/vdb 1
Where:
/dev/vdb
: Device name.1
is the partition number, so it is separated by a space.
Result:
CHANGED: partition=1 start=2048 old: size=67106816 end=67108864 new: size=134215647,end=134217695
-
Change the file system size:
sudo xfs_growfs /data -d
Where:
/data
: Mount point of the partition whose size you need to increase.-d
: Partition extension parameter.
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 that the partition 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