Skip to content

Commit

Permalink
hyperv: expand root partition
Browse files Browse the repository at this point in the history
  • Loading branch information
AASTHA RAWAT committed Jan 17, 2025
1 parent f6e8d5e commit 52abe12
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lisa/sut_orchestrator/hyperv/platform_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from lisa.environment import Environment
from lisa.node import RemoteNode
from lisa.platform_ import Platform
from lisa.tools import Cp, HyperV, Mkdir, PowerShell
from lisa.tools import Cp, HyperV, Mkdir, Mount, PowerShell
from lisa.util import LisaException, constants
from lisa.util.logger import Logger, get_logger
from lisa.util.parallel import run_in_parallel
Expand Down Expand Up @@ -315,6 +315,8 @@ def _deploy_environment(self, environment: Environment, log: Logger) -> None:
address=ip_addr, username=username, password=password
)

self._expand_root_partition(node)

def _resize_vhd_if_needed(
self, vhd_path: PurePath, node_runbook: HypervNodeSchema
) -> None:
Expand All @@ -326,6 +328,28 @@ def _resize_vhd_if_needed(
f"-SizeBytes {node_runbook.osdisk_size_in_gb * 1024 * 1024 * 1024}"
)

def _expand_root_partition(self, node: RemoteNode) -> None:
# Get the root partition info
# The root partition is the one that has the mount point "/"
# sample root partition info: name: /dev/sda2, disk: sda,
# mount_point: /, type: ext4, options: ('rw', 'relatime')
root_partition = node.tools[Mount].get_partition_info("/")[0]
device_name = root_partition.name
partition = root_partition.disk
# for root partition name: /dev/sda2, partition is "sda" and
# we need to extract the partition number i.e. 2
root_part_num = device_name[-1]
# Grow the partition and resize the filesystem
cmd_result = node.execute(
f"growpart /dev/{partition} {root_part_num}", sudo=True
)
# In case, the partition is already expanded to full disk size, the
# command will print "NOCHANGE: partition 2 is size <size>. it cannot
# be grown". In this case, it returns exit code 1 which we can ignore
if cmd_result.exit_code != 0 and "NOCHANGE" not in cmd_result.stdout:
raise LisaException(f"Failed to grow partition: {cmd_result.stdout}")
node.execute(f"resize2fs {device_name}", sudo=True, expected_exit_code=0)

def _delete_environment(self, environment: Environment, log: Logger) -> None:
self._delete_nodes(environment, log)

Expand Down

0 comments on commit 52abe12

Please sign in to comment.