main/postmarketos-mkinitfs: resize: unallocated space check, even if forced (MR 1428)
In resize_root_partition(), put the unallocated space check into an extra function has_unallocated_space(). Run it even if PMOS_FORCE_PARTITION_RESIZE is used, so we don't attempt to resize the partition if there is no free space. While at it, change "sed 's/p?2$//'" to "sed 's/2$//' in an already modified line, because it means the same thing and is less confusing (? in regex means: 0 or 1 time).
This commit is contained in:
parent
dea5488d93
commit
9d86f6fe92
2 changed files with 16 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
pkgname=postmarketos-mkinitfs
|
pkgname=postmarketos-mkinitfs
|
||||||
pkgver=0.13.0
|
pkgver=0.13.1
|
||||||
pkgrel=0
|
pkgrel=0
|
||||||
pkgdesc="Tool to generate initramfs images for postmarketOS"
|
pkgdesc="Tool to generate initramfs images for postmarketOS"
|
||||||
url="https://postmarketos.org"
|
url="https://postmarketos.org"
|
||||||
|
@ -40,7 +40,7 @@ check() {
|
||||||
|
|
||||||
sha512sums="5037cb7285bb7c0c40ca9e6df332d882ef9a8b379756c785f921e062dab1b7e7f3139d00897f69323a916d709ced4297fea8cbd3a13ebae575b873ec9e2cbfae 00-default.modules
|
sha512sums="5037cb7285bb7c0c40ca9e6df332d882ef9a8b379756c785f921e062dab1b7e7f3139d00897f69323a916d709ced4297fea8cbd3a13ebae575b873ec9e2cbfae 00-default.modules
|
||||||
995b4d15e6b248d55d53221ec52674e62d74f0be539ac2ab26d4279544e2bece7aa58810dd831e1b2f08f0520fc9a8dff3ad4df52a46ef73f61e462f74f68c48 init.sh.in
|
995b4d15e6b248d55d53221ec52674e62d74f0be539ac2ab26d4279544e2bece7aa58810dd831e1b2f08f0520fc9a8dff3ad4df52a46ef73f61e462f74f68c48 init.sh.in
|
||||||
683b1784cc6572717dd805caabea38fac1780b03ff3540b888aab4fd91ccae404634874e6c9fa39f723186821a849844c6df1235bdcbf47b2de6b7f483c42178 init_functions.sh
|
40c48c0b6d499dbe316cbb41dc2c02bdc188444c549f1545135479cd6ead5c318496b5c03a11ff81fdaeddef5f8fa473264a380afc6109a3d54790a489f16c1c init_functions.sh
|
||||||
7201d4640a3e9ead8a47ffd9916b068476b7d950760a84c37e02268c942d49896bc986da6bdee27e832639c90775354d68046a6475205d8d1da995b068120d8f mkinitfs.sh
|
7201d4640a3e9ead8a47ffd9916b068476b7d950760a84c37e02268c942d49896bc986da6bdee27e832639c90775354d68046a6475205d8d1da995b068120d8f mkinitfs.sh
|
||||||
d593b921bd6c0204af874266060667d78a232c0131ce7f0ad4124f9b240fcbb6ac2a8a2b8ee30d27d78bed8c1a506c4e6cb13b57c33cee3a00a7d96eca45a7f3 mkinitfs_functions.sh
|
d593b921bd6c0204af874266060667d78a232c0131ce7f0ad4124f9b240fcbb6ac2a8a2b8ee30d27d78bed8c1a506c4e6cb13b57c33cee3a00a7d96eca45a7f3 mkinitfs_functions.sh
|
||||||
c7a3c33daeb12b33ac72207191941c4d634f15c22958273b52af381a70ebaba1d3a9299483f0c447d9e66c560151fe7b9588bb4bbef2c8914f83185984ee4622 mkinitfs_test.sh"
|
c7a3c33daeb12b33ac72207191941c4d634f15c22958273b52af381a70ebaba1d3a9299483f0c447d9e66c560151fe7b9588bb4bbef2c8914f83185984ee4622 mkinitfs_test.sh"
|
||||||
|
|
|
@ -211,6 +211,13 @@ wait_root_partition() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# $1: path to device
|
||||||
|
has_unallocated_space() {
|
||||||
|
# Check if there is unallocated space at the end of the device
|
||||||
|
parted -s "$1" print free | tail -n2 | \
|
||||||
|
head -n1 | grep -qi "free space"
|
||||||
|
}
|
||||||
|
|
||||||
resize_root_partition() {
|
resize_root_partition() {
|
||||||
partition=$(find_root_partition)
|
partition=$(find_root_partition)
|
||||||
|
|
||||||
|
@ -228,9 +235,7 @@ resize_root_partition() {
|
||||||
# Get physical device
|
# Get physical device
|
||||||
partition_dev=$(dmsetup deps -o devname "$partition" | \
|
partition_dev=$(dmsetup deps -o devname "$partition" | \
|
||||||
awk -F "[()]" '{print "/dev/"$2}')
|
awk -F "[()]" '{print "/dev/"$2}')
|
||||||
# Check if there is unallocated space at the end of the device
|
if has_unallocated_space "$partition_dev"; then
|
||||||
if parted -s "$partition_dev" print free | tail -n2 | \
|
|
||||||
head -n1 | grep -qi "free space"; then
|
|
||||||
echo "Resize root partition ($partition)"
|
echo "Resize root partition ($partition)"
|
||||||
# unmount subpartition, resize and remount it
|
# unmount subpartition, resize and remount it
|
||||||
kpartx -d "$partition"
|
kpartx -d "$partition"
|
||||||
|
@ -242,10 +247,13 @@ resize_root_partition() {
|
||||||
# except for QEMU devices (where PMOS_FORCE_PARTITION_RESIZE gets passed as
|
# except for QEMU devices (where PMOS_FORCE_PARTITION_RESIZE gets passed as
|
||||||
# kernel parameter).
|
# kernel parameter).
|
||||||
if grep -q PMOS_FORCE_PARTITION_RESIZE /proc/cmdline; then
|
if grep -q PMOS_FORCE_PARTITION_RESIZE /proc/cmdline; then
|
||||||
|
partition_dev="$(echo "$partition" | sed -E 's/2$//')"
|
||||||
|
if has_unallocated_space "$partition_dev"; then
|
||||||
echo "Resize root partition ($partition)"
|
echo "Resize root partition ($partition)"
|
||||||
parted -s "$(echo "$partition" | sed -E 's/p?2$//')" resizepart 2 100%
|
parted -s "$partition_dev" resizepart 2 100%
|
||||||
partprobe
|
partprobe
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_root_partition() {
|
unlock_root_partition() {
|
||||||
|
|
Loading…
Reference in a new issue