mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
storage: Pass optional mount point to partition expansion
- Helps test cases. - In future, we can resize non-root partitions. Tests: - On an amd64 disk image, apply this patch. Increase the image size. Boot the image. During first setup. The root partition should get expanded successfully and show full disk size. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
244d0ba50c
commit
5ff172aedd
@ -33,6 +33,10 @@ def parse_arguments():
|
|||||||
help='Expand a partition to take adjacent free space')
|
help='Expand a partition to take adjacent free space')
|
||||||
subparser.add_argument('device',
|
subparser.add_argument('device',
|
||||||
help='Partition which needs to be resized')
|
help='Partition which needs to be resized')
|
||||||
|
subparser.add_argument(
|
||||||
|
'--mount-point', default='/',
|
||||||
|
help=('Mount point which the device is mounted. '
|
||||||
|
'Needed for btrfs filesystems'))
|
||||||
|
|
||||||
subparser = subparsers.add_parser('mount', help='Mount a filesystem')
|
subparser = subparsers.add_parser('mount', help='Mount a filesystem')
|
||||||
subparser.add_argument('--block-device',
|
subparser.add_argument('--block-device',
|
||||||
@ -68,6 +72,7 @@ def subcommand_is_partition_expandable(arguments):
|
|||||||
def subcommand_expand_partition(arguments):
|
def subcommand_expand_partition(arguments):
|
||||||
"""Expand a partition to take adjacent free space."""
|
"""Expand a partition to take adjacent free space."""
|
||||||
device = arguments.device
|
device = arguments.device
|
||||||
|
mount_point = arguments.mount_point
|
||||||
device, requested_partition, free_space = _get_free_space(device)
|
device, requested_partition, free_space = _get_free_space(device)
|
||||||
|
|
||||||
if requested_partition['table_type'] == 'msdos' and \
|
if requested_partition['table_type'] == 'msdos' and \
|
||||||
@ -80,7 +85,7 @@ def subcommand_expand_partition(arguments):
|
|||||||
_move_gpt_second_header(device)
|
_move_gpt_second_header(device)
|
||||||
|
|
||||||
_resize_partition(device, requested_partition, free_space)
|
_resize_partition(device, requested_partition, free_space)
|
||||||
_resize_file_system(device, requested_partition, free_space)
|
_resize_file_system(device, requested_partition, free_space, mount_point)
|
||||||
|
|
||||||
|
|
||||||
def _move_gpt_second_header(device):
|
def _move_gpt_second_header(device):
|
||||||
@ -126,15 +131,16 @@ def _resize_partition(device, requested_partition, free_space):
|
|||||||
sys.exit(5)
|
sys.exit(5)
|
||||||
|
|
||||||
|
|
||||||
def _resize_file_system(device, requested_partition, free_space):
|
def _resize_file_system(device, requested_partition, free_space,
|
||||||
|
mount_point='/'):
|
||||||
"""Resize a file system inside a partition."""
|
"""Resize a file system inside a partition."""
|
||||||
if requested_partition['type'] == 'btrfs':
|
if requested_partition['type'] == 'btrfs':
|
||||||
_resize_btrfs(device, requested_partition, free_space)
|
_resize_btrfs(device, requested_partition, free_space, mount_point)
|
||||||
elif requested_partition['type'] == 'ext4':
|
elif requested_partition['type'] == 'ext4':
|
||||||
_resize_ext4(device, requested_partition, free_space)
|
_resize_ext4(device, requested_partition, free_space, mount_point)
|
||||||
|
|
||||||
|
|
||||||
def _resize_ext4(device, requested_partition, free_space):
|
def _resize_ext4(device, requested_partition, _free_space, _mount_point):
|
||||||
"""Resize an ext4 file system inside a partition."""
|
"""Resize an ext4 file system inside a partition."""
|
||||||
partition_device = _get_partition_device(device,
|
partition_device = _get_partition_device(device,
|
||||||
requested_partition['number'])
|
requested_partition['number'])
|
||||||
@ -147,10 +153,10 @@ def _resize_ext4(device, requested_partition, free_space):
|
|||||||
sys.exit(6)
|
sys.exit(6)
|
||||||
|
|
||||||
|
|
||||||
def _resize_btrfs(device, requested_partition, free_space):
|
def _resize_btrfs(_device, _requested_partition, _free_space, mount_point='/'):
|
||||||
"""Resize a btrfs file system inside a partition."""
|
"""Resize a btrfs file system inside a partition."""
|
||||||
try:
|
try:
|
||||||
command = ['btrfs', 'filesystem', 'resize', 'max', '/']
|
command = ['btrfs', 'filesystem', 'resize', 'max', mount_point]
|
||||||
subprocess.run(command, stdout=subprocess.DEVNULL, check=True)
|
subprocess.run(command, stdout=subprocess.DEVNULL, check=True)
|
||||||
except subprocess.CalledProcessError as exception:
|
except subprocess.CalledProcessError as exception:
|
||||||
print('Error expanding filesystem:', exception, file=sys.stderr)
|
print('Error expanding filesystem:', exception, file=sys.stderr)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user