mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-05 04:06:33 +02:00
btrfs hack: shrink the allocated size
We are using read-only btrfs compressed for the /usr partition, and sometimes the free space shown by `btrfs fi usage` and the `df` IS diverging, with `df` showing the free space from the `btrfs fi usage`'s `Device unallocated. I have found a way to fix the allocation, by decreasing the size to more than the btrfs filesystem allows, but curiosly the allocation is getting reset during the failed attempt and the issue is fixed. This is of course, a _HACK_, and can at any time produce unwanted behaviours. Note that the issue cannot be reliably reproduced. See Flatcar issue: https://github.com/flatcar/Flatcar/issues/1473 See issue upstream: https://bugzilla.kernel.org/show_bug.cgi?id=219167 Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
This commit is contained in:
parent
a2598effed
commit
51d5509c83
@ -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
|
||||
|
||||
@ -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.
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user