Merge ~adrien/ubiquity:lp-1991083-add-margin-to-partition-minsize into ubiquity:main

Proposed by Adrien Nader
Status: Superseded
Proposed branch: ~adrien/ubiquity:lp-1991083-add-margin-to-partition-minsize
Merge into: ubiquity:main
Diff against target: 88 lines (+53/-2)
2 files modified
d-i/source/partman-partitioning/lib/resize.sh (+46/-2)
debian/changelog (+7/-0)
Reviewer Review Type Date Requested Status
Adrien Nader (community) Approve
Sergio Costas (community) Needs Fixing
Ubuntu Installer Team Pending
Review via email: mp+431418@code.launchpad.net

This proposal has been superseded by a proposal from 2022-10-14.

To post a comment you must log in.
513cfb4... by Adrien Nader

Add changelog entry for minimal partition size margin.

Revision history for this message
Sergio Costas (rastersoft-gmail) wrote :

     minsize=$size
+ minsize="$(add_margin_to_minsize "$minsize" "$cursize")"

What about changing this to:

- minsize=$size
+ minsize="$(add_margin_to_minsize "$size" "$cursize")"

And the same in the other change?

review: Needs Fixing
Revision history for this message
Adrien Nader (adrien) wrote :

> minsize=$size
> + minsize="$(add_margin_to_minsize "$minsize"
> "$cursize")"
>
> What about changing this to:
>
> - minsize=$size
> + minsize="$(add_margin_to_minsize "$size"
> "$cursize")"
>
> And the same in the other change?

Yeah, absolutely. I've pushed an updated change.

review: Approve

Unmerged commits

513cfb4... by Adrien Nader

Add changelog entry for minimal partition size margin.

3e4225d... by Adrien Nader

partman/resize: add a margin to the minimal size for partition shrinking

The current estimation of the minimal size of a filesystem is used as-is
without any margin. However these are only estimations and filesystems
shrunk to their minimum are not usable anymore. This is especially the
case for ext4 since the estimation does not take into account the
numerous filesystem features.

For ext4 we could improve the estimation too but this is a difficult
task with shell scripting and probably not worth considering the issue
has probably existed for a long time and no user seems to have
complained so far (maybe they worked around the issue by not trying to
shrink as much as possible).

Therefore, add the same margin as in subiquity: max(minsize*0.25, 2GiB).

LP: #1991083

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/d-i/source/partman-partitioning/lib/resize.sh b/d-i/source/partman-partitioning/lib/resize.sh
2index fb7419d..b93b401 100644
3--- a/d-i/source/partman-partitioning/lib/resize.sh
4+++ b/d-i/source/partman-partitioning/lib/resize.sh
5@@ -45,6 +45,50 @@ do_ntfsresize () {
6 return $RET
7 }
8
9+# add_margin_to_minsize: add a max(minsize*0.25, 2GiB) margin to the minimal
10+# size of a filesystem but also cap the result to its current size.
11+#
12+# When minsize is first computed, it is only an estimation and it doesn't leave
13+# any margin to continue actually using the filesystem that is about to be
14+# shrunk. Below is an excerpt from ntfsresize(1) which is applicable to every
15+# filesystem and operating system:
16+# Practically the smallest shrunken size generally is at around
17+# "used space" + (20-200 MB). Please also take into account that
18+# Windows might need about 50-100 MB free space left to boot
19+# safely.
20+#
21+# The margin is max(minsize*0.25, 2GiB). This is the same as in subiquity.
22+# Expect the same accuracy as you would expect from any arithmetic done in
23+# shell scripts.
24+#
25+# I /think/ there is no issue with filesystem alignment because we don't change
26+# the beginning of the filesystem and tools are supposed to properly align the
27+# beginning of partitions/filesystems no matter their input.
28+add_margin_to_minsize()
29+{
30+ local minsize cursize plus_25_percents plus_2G
31+ minsize="$1"
32+ cursize="$2"
33+
34+ plus_25_percents="$(expr 125 \* "$minsize" / 100)"
35+ plus_2G="$(expr "$minsize" + 2 \* 1024 \* 1024 \* 1024)"
36+
37+ if longint_le "$plus_25_percents" "$plus_2G"; then
38+ plus_25_percents_or_2G="$plus_2G"
39+ else
40+ plus_25_percents_or_2G="$plus_25_percents"
41+ fi
42+
43+ if longint_le "$cursize" "$plus_25_percents_or_2G"; then
44+ logger -t partman "Filesystem is already as small as it can reasonably be"
45+ minsize="$cursize"
46+ else
47+ minsize="$plus_25_percents_or_2G"
48+ fi
49+
50+ echo $minsize
51+}
52+
53 get_ntfs_resize_range () {
54 local bdev size
55 open_dialog GET_VIRTUAL_RESIZE_RANGE $oldid
56@@ -71,7 +115,7 @@ get_ntfs_resize_range () {
57 unset minsize cursize maxsize prefsize
58 return 1
59 else
60- minsize=$size
61+ minsize="$(add_margin_to_minsize "$size" "$cursize")"
62 fi
63 fi
64 fi
65@@ -108,7 +152,7 @@ get_ext2_resize_range () {
66 unset minsize cursize maxsize prefsize
67 return 1
68 else
69- minsize="$real_minsize"
70+ minsize="$(add_margin_to_minsize "$real_minsize" "$cursize")"
71 fi
72 fi
73 fi
74diff --git a/debian/changelog b/debian/changelog
75index a9ed647..f1ab086 100644
76--- a/debian/changelog
77+++ b/debian/changelog
78@@ -1,3 +1,10 @@
79+ubiquity (22.10.8ubuntu1) UNRELEASED; urgency=medium
80+
81+ * partman/resize: add a margin to the minimal size for partition shrinking
82+ (LP: #1991083)
83+
84+ -- Adrien Nader <adrien.nader@canonical.com> Wed, 12 Oct 2022 10:14:27 +0000
85+
86 ubiquity (22.10.8) kinetic; urgency=medium
87
88 * Increase the window size in the QT/KDE version of the installer dailog so

Subscribers

People subscribed via source and target branches