forked from mingxiaoyu/R1-Plus-LTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0002-resize-rootfs.patch
105 lines (102 loc) · 3.96 KB
/
0002-resize-rootfs.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From b218c6deb5c2be2e5529efb44d55df15d55a9c85 Mon Sep 17 00:00:00 2001
From: mingxiaoyu <[email protected]>
Date: Tue, 14 Mar 2023 13:31:56 +0800
Subject: resize-rootfs
---
.../armv8/base-files/etc/init.d/resize-rootfs | 9 +++
.../base-files/etc/rc.d/S22resize-rootfs | 1 +
.../armv8/base-files/usr/bin/resize-rootfs.sh | 60 +++++++++++++++++++
3 files changed, 70 insertions(+)
create mode 100755 target/linux/rockchip/armv8/base-files/etc/init.d/resize-rootfs
create mode 100755 target/linux/rockchip/armv8/base-files/etc/rc.d/S22resize-rootfs
create mode 100755 target/linux/rockchip/armv8/base-files/usr/bin/resize-rootfs.sh
diff --git a/target/linux/rockchip/armv8/base-files/etc/init.d/resize-rootfs b/target/linux/rockchip/armv8/base-files/etc/init.d/resize-rootfs
new file mode 100755
index 0000000000..740b751499
--- /dev/null
+++ b/target/linux/rockchip/armv8/base-files/etc/init.d/resize-rootfs
@@ -0,0 +1,9 @@
+#!/bin/sh /etc/rc.common
+
+START=22
+start() {
+ rm -rf /etc/rc.d/S22resize-rootfs
+ #service resize-rootfs disable
+ /usr/bin/resize-rootfs.sh
+}
+
diff --git a/target/linux/rockchip/armv8/base-files/etc/rc.d/S22resize-rootfs b/target/linux/rockchip/armv8/base-files/etc/rc.d/S22resize-rootfs
new file mode 100755
index 0000000000..051d001b6c
--- /dev/null
+++ b/target/linux/rockchip/armv8/base-files/etc/rc.d/S22resize-rootfs
@@ -0,0 +1 @@
+../init.d/resize-rootfs
diff --git a/target/linux/rockchip/armv8/base-files/usr/bin/resize-rootfs.sh b/target/linux/rockchip/armv8/base-files/usr/bin/resize-rootfs.sh
new file mode 100755
index 0000000000..2b1cd8baaf
--- /dev/null
+++ b/target/linux/rockchip/armv8/base-files/usr/bin/resize-rootfs.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+FDISK=$(which fdisk) || { echo "E: You must have fdisk" && exit 1; }
+LOSETUP=$(which losetup) || { echo "E: You must have losetup" && exit 1; }
+roottype=$(findmnt -n -o SOURCE / -o FSTYPE)
+case ${roottype} in
+ overlay)
+ FSCKF2FS=$(which fsck.f2fs) || { echo "E: You must have fsck.f2fs" && exit 1; }
+ rootsource=$(findmnt -n -o SOURCE /rom) # i.e. /dev/mmcblk0p2
+ rootdevice=${rootsource%p*} # i.e. /dev/mmcblk0
+ partitions=${rootsource##*p}
+
+ # Resizing partitions
+ lastsector=$(${FDISK} -l ${rootdevice} |grep "Disk ${rootdevice}" |awk '{print $7}')
+ lastsector=$(( $lastsector - 1 ))
+ startfrom=$(${FDISK} -l ${rootdevice} |grep ${rootsource} |awk '{print $2}')
+ partend=$(${FDISK} -l ${rootdevice} |grep ${rootsource} |awk '{print $3}')
+ [[ $lastsector -eq $partend ]] && exit 0
+ (echo d; echo $partitions; echo n; echo p; echo ; echo $startfrom; echo $lastsector ; echo w;) | fdisk $rootdevice
+ sync
+
+ # Start resizing filesystem
+ LOOP="$(losetup -n -O NAME | sort | sed -n -e "1p")"
+ ROOT="$(losetup -n -O BACK-FILE ${LOOP} | sed -e "s|^|/dev|")"
+ OFFS="$(losetup -n -O OFFSET ${LOOP})"
+ LOOP="$(losetup -f)"
+ ${LOSETUP} -o ${OFFS} ${LOOP} ${ROOT}
+ ${FSCKF2FS} -f ${LOOP}
+ mount ${LOOP} /mnt
+ umount ${LOOP}
+ resize.f2fs ${LOOP}
+ sync && reboot
+ ;;
+ ext4)
+ FSCKEXT4=$(which fsck.ext4) || { echo "E: You must have fsck.ext4" && exit 1; }
+ RESIZE2FS=$(which resize2fs) || { echo "E: You must have resize2fs" && exit 1; }
+ rootsource=$(findmnt -n -o SOURCE / | sed 's~\[.*\]~~') # i.e. /dev/mmcblk0p2
+ rootdevice=${rootsource%p*} # i.e. /dev/mmcblk0
+ partitions=${rootsource##*p}
+
+ # Resizing partitions
+ lastsector=$(${FDISK} -l ${rootdevice} |grep "Disk ${rootdevice}" |awk '{print $7}')
+ lastsector=$(( $lastsector - 1 ))
+ startfrom=$(${FDISK} -l ${rootdevice} |grep ${rootsource} |awk '{print $2}')
+ partend=$(${FDISK} -l ${rootdevice} |grep ${rootsource} |awk '{print $3}')
+ [[ $lastsector -eq $partend ]] && exit 0
+ (echo d; echo $partitions; echo n; echo p; echo ; echo $startfrom; echo $lastsector ; echo w;) | fdisk $rootdevice
+ sync
+
+ # Start resizing filesystem
+ LOOP="$(losetup -f)"
+ ${LOSETUP} ${LOOP} ${rootsource}
+ ${FSCKEXT4} -y ${LOOP}
+ ${RESIZE2FS} ${LOOP}
+ sync && reboot
+ ;;
+esac
+
+exit 0
+
--
2.34.1