mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-22 21:25:43 -05:00
image: shrink_filesystem(): align file end to 4096b
otherwise fastboot seems to get upset
This commit is contained in:
parent
de76641fa1
commit
efe4bf085d
1 changed files with 8 additions and 1 deletions
|
@ -69,6 +69,13 @@ def get_fs_size(partition: str) -> tuple[int, int]:
|
|||
return fs_blocks, fs_block_size
|
||||
|
||||
|
||||
def align_bytes(size_bytes: int, alignment: int = 4096) -> int:
|
||||
rest = size_bytes % alignment
|
||||
if rest:
|
||||
size_bytes += alignment - rest
|
||||
return size_bytes
|
||||
|
||||
|
||||
def shrink_fs(loop_device: str, file: str, sector_size: int):
|
||||
partprobe(loop_device)
|
||||
logging.debug(f"Checking filesystem at {loop_device}p2")
|
||||
|
@ -130,7 +137,7 @@ def shrink_fs(loop_device: str, file: str, sector_size: int):
|
|||
if end_sector == 0:
|
||||
raise Exception(f'Failed to find end sector of {loop_device}p2')
|
||||
|
||||
end_size = (end_sector + 1) * sector_size
|
||||
end_size = align_bytes((end_sector + 1) * sector_size, 4096)
|
||||
|
||||
logging.debug(f'({end_sector} + 1) sectors * {sector_size} bytes/sector = {end_size} bytes')
|
||||
logging.info(f'Truncating {file} to {end_size} bytes')
|
||||
|
|
Loading…
Add table
Reference in a new issue