]> git.plutz.net Git - blast/blob - modules/autoresize.mk
bugfixes
[blast] / modules / autoresize.mk
1 export autoresize autoresize_unit
2
3 define autoresize :=
4 #!/bin/sh
5
6 rootfs="$$(mount |grep -w / |cut -d' ' -f1)"
7 roottype="$$(mount |grep -w / |cut -d' ' -f5)"
8
9 case $$rootfs in
10   /dev/mmcblk?p2) rootdev="$${rootfs%p2}";;
11   /dev/[sh]d?2) rootdev="$${rootfs%2}";;
12   *) exit 0;;
13 esac
14
15 before="$$(sfdisk --dump "$$rootdev")"
16
17 sfdisk --dump "$$rootdev" |sed '$$s;, size=.*,;,;;' \
18 | sfdisk --force "$$rootdev"
19
20 after="$$(sfdisk --dump "$$rootdev")"
21
22 if [ "$$before" = "$$after" ]; then
23   # second stage
24   case $$roottype in
25     ext[234]) resize2fs "$$rootfs";;
26     btrfs) btrfs filesystem resize max /;;
27     nilfs2) nilfs-resize -y "$$rootfs";;
28   esac
29   systemctl disable autoresize
30 else
31   # finish first stage
32   shutdown -r now
33 fi
34
35 endef
36
37 define autoresize_unit :=
38 [Unit]
39 Description=Resize root filesystem during first boot
40
41 [Service]
42 ExecStart=/opt/autoresize.sh
43
44 [Install]
45 WantedBy=multi-user.target
46 endef
47
48 .PHONY: _autoresize
49 _config: _autoresize
50
51 _autoresize: ${CFGROOT}
52         mkdir -p "$${CFGROOT}/etc/systemd/system/"
53         printf '%s\n' "$$autoresize" >"$${CFGROOT}/opt/autoresize.sh"
54         chmod 755 "$${CFGROOT}/opt/autoresize.sh"
55         printf '%s\n' "$$autoresize_unit" >"$${CFGROOT}/etc/systemd/system/autoresize.service"
56         chroot "$${CFGROOT}" systemctl enable autoresize