Skip to content

Commit 3863fe4

Browse files
committed
Merge branch 'github-pull-41' into for-master
This adds filesystem resize when the partition is resized. This functionality is not available for all filesystems, but only for ext2/ext3/ext4, xfs, f2fs. Link: #41 Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2 parents e8170d0 + 5529711 commit 3863fe4

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

features/kickstart/config.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ $(call feature-requires,devmapper luks lvm mdadm modules-filesystem system-glibc
33

44
KICKSTART_PROGS = sfdisk wipefs blkid findmnt mkswap mount mountpoint chroot \
55
rsync wget tar unzip cpio env sha256sum eject halt reboot \
6-
btrfs mkfs.btrfs mkfs.ext4 numfmt
6+
btrfs mkfs.btrfs mkfs.ext4 numfmt e2fsck resize2fs \
7+
xfs_growfs resize.f2fs
78

89
KICKSTART_PROGS_PATTERNS = \
910
*/lz4 \

features/kickstart/data/bin/kickstart-sh-storage

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ ks_devname()
1212
{
1313
local devname=''
1414
case "$1" in
15+
/dev/root)
16+
[ -n "$ROOT" ] || fatal "/dev/root is not defined"
17+
ks_devname "$ROOT"
18+
return
19+
;;
1520
LABEL=*)
1621
devname="$(blkid -o device -L "${1#LABEL=}")"
1722
;;
@@ -539,6 +544,60 @@ ks_get_dev_id()
539544
printf '%s\n' "$1"
540545
}
541546

547+
ks_requires_ext4=("e2fsck resize2fs")
548+
ks_requires_xfs=("xfs_growfs")
549+
ks_requires_f2fs=("resize.f2fs")
550+
ks_growfs()
551+
{
552+
local PROG
553+
local fs="" requires="" ret=0
554+
555+
PROG="kickstart"
556+
message "command: ${FUNCNAME[0]} $*"
557+
558+
fs="$(blkid --output value --match-tag TYPE -c /dev/null "$1")" ||
559+
return 0
560+
561+
case "$fs" in
562+
ext*) requires="ks_growfs_ext4" ;;
563+
xfs) requires="ks_growfs_xfs" ;;
564+
f2fs) requires="ks_growfs_f2fs" ;;
565+
*)
566+
# resize unsupported.
567+
return 0
568+
;;
569+
esac
570+
571+
ks_check_requires "$requires" ||
572+
return 1
573+
574+
verbose "Increase filesystem to partition size: $1"
575+
576+
case "$fs" in
577+
ext*)
578+
e2fsck -f "$1" && resize2fs "$1" ||
579+
ret=1
580+
;;
581+
xfs)
582+
mount -n -o rw,X-mount.mkdir \
583+
"$1" \
584+
"$ks_datadir/xfs.dir"
585+
xfs_growfs \
586+
"$ks_datadir/xfs.dir" ||
587+
ret=1
588+
umount -f \
589+
"$ks_datadir/xfs.dir"
590+
;;
591+
f2fs)
592+
resize.f2fs "$1" ||
593+
ret=1
594+
;;
595+
esac
596+
597+
return $ret
598+
}
599+
600+
542601
ks_requires_part=("numfmt" "sfdisk")
543602
part()
544603
{
@@ -820,14 +879,15 @@ part()
820879
local partnum
821880
read -r partnum < "/sys/class/block/$partdev/partition"
822881

823-
dev="$(readlink -ev "/sys/class/block/$partdev")"
882+
dev="$(readlink-e "/sys/class/block/$partdev")"
824883
dev="${dev%/*}"
825884
dev="${dev##*/}"
826885

827886
verbose "increasing partition /dev/$dev$partnum"
828887

829888
printf ', %s\n' "$size" |
830889
sfdisk -q -N "$partnum" "/dev/$dev"
890+
ks_growfs "/dev/$dev$partnum"
831891
fi
832892

833893
if [ -n "$encrypted" ]; then

0 commit comments

Comments
 (0)