-
Notifications
You must be signed in to change notification settings - Fork 36
/
fs_resize.sh
115 lines (93 loc) · 2.24 KB
/
fs_resize.sh
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
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
fs_resize() {
AC=$(whiptail --backtitle "Hardkernel ODROID Utility v$_REV" --yesno "Before running this, you must be sure that /dev/mmcblk0p2 is your root partition.
To do this make sure you are booting the eMMC or the microSD ALONE!.
DO YOU WANT TO CONTINUE?" 0 0 3>&1 1>&2 2>&3)
rets=$?
if [ $rets -eq 0 ]; then
do_resize
elif [ $rets -eq 1 ]; then
return 0
fi
return 0
}
do_resize() {
case "$DISTRO" in
"ubuntu")
resize_p2 ;;
"debian")
resize_p2 ;;
"ubuntu-server")
resize_p2 ;;
*)
msgbox "FS_RESIZE: Sorry your distro $DISTRO isn't supported yet. Please report on the forums"
;;
esac
}
resize_p2() {
# this takes in consideration /dev/mmcblk0p2 as the rootfs!
rsflog=/root/resize-$DATE-log.txt
echo "Saving the log to $rsflog"
sleep 4
p2_start=`fdisk -l /dev/mmcblk0 | grep mmcblk0p2 | awk '{print $2}'`
if [ "$DISTRO_VERSION" = "15.04" ] || [ "$DISTRO_VERSION" = "15.10" ]; then
p2_finish=$((`fdisk -l /dev/mmcblk0 | grep Disk | grep sectors | awk '{printf $7}'` - 1024))
else
p2_finish=$((`fdisk -l /dev/mmcblk0 | grep total | grep sectors | awk '{printf $8}'` - 1024))
fi
fdisk /dev/mmcblk0 <<EOF &>> $rsflog
p
d
2
n
p
2
$p2_start
$p2_finish
p
w
EOF
if [ "$DISTRO_VERSION" = "15.04" ] || [ "$DISTRO_VERSION" = "15.10" ]; then
cat <<\EOF > /lib/systemd/system/fsresize.service
[Unit]
Description=Resize FS
[Service]
Type=simple
ExecStart=/etc/init.d/resize2fs_once start
[Install]
WantedBy=multi-user.target
EOF
systemctl enable fsresize
fi
cat <<\EOF > /etc/init.d/resize2fs_once
#!/bin/sh
### BEGIN INIT INFO
# Provides: resize2fs_once
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5 S
# Default-Stop:
# Short-Description: Resize the root filesystem to fill partition
# Description:
### END INIT INFO
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting resize2fs_once" &&
resize2fs /dev/mmcblk0p2 &&
rm /etc/init.d/resize2fs_once &&
update-rc.d resize2fs_once remove &&
log_end_msg $?
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac
EOF
chmod +x /etc/init.d/resize2fs_once
update-rc.d resize2fs_once defaults
REBOOT=1
msgbox "Rootfs Extended. Please reboot to take effect"
return 0
}