Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btrfs hack: shrink the allocated size #2076

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build_library/build_image_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ EOF
sudo fstrim "${root_fs_dir}/usr" || true
fi

"${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" btrfsresetallocation \
"${root_fs_dir}/usr"
# Make the filesystem un-mountable as read-write and setup verity.
if [[ ${disable_read_write} -eq ${FLAGS_TRUE} ]]; then
# Unmount /usr partition
Expand Down
23 changes: 23 additions & 0 deletions build_library/disk_util
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,25 @@ def Tune(options):
if not action_done:
raise Exception("No options specified!")

def SudoOutputToConsole(cmd):
print(SudoOutput(cmd).decode())

def LogBtrfsUsage(mount_point, section=None):
print('Btrfs usage for mount point `%s` %s' % (mount_point, section))
try:
SudoOutputToConsole(['btrfs', 'fi', 'usage', mount_point])
except Exception as ex:
print('Btrfs usage could not be retrieved for mount point `%s` %s' % (mount_point, section))
print(ex)

def BtrfsResetAllocation(options):

LogBtrfsUsage(options.disk_image, 'before disk resize')
try:
Sudo(['btrfs', 'fi', 'resize', '-500m', options.disk_image])
except Exception as ex:
print(ex)
LogBtrfsUsage(options.disk_image, 'after disk resize')

def Verity(options):
"""Hash verity protected filesystems.
Expand Down Expand Up @@ -1119,6 +1138,10 @@ def main(argv):
a = actions.add_parser('parseonly', help='validate config')
a.set_defaults(func=DoParseOnly)

a = actions.add_parser('btrfsresetallocation', help='btrfs reset allocation')
a.add_argument('disk_image', help='path to disk image file')
a.set_defaults(func=BtrfsResetAllocation)

options = parser.parse_args(argv[1:])
options.func(options)

Expand Down