forked from szepeviktor/debian-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian-resizefs.sh
executable file
·67 lines (52 loc) · 1.28 KB
/
debian-resizefs.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
#!/bin/bash
#
# Resize root filesystem during boot.
#
# Check current filesystem type
ROOT_FS_TYPE="$(sed -n -e 's|^/dev/[a-z]\+[1-9]\+ / \(ext4\) .*$|\1|p' /proc/mounts)"
test "$ROOT_FS_TYPE" == ext4 || exit 100
# Copy resize2fs to initrd
cat > /etc/initramfs-tools/hooks/resize2fs <<"EOF"
#!/bin/sh
PREREQ=""
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
copy_exec /sbin/e2fsck /sbin
copy_exec /sbin/resize2fs /sbin
EOF
chmod +x /etc/initramfs-tools/hooks/resize2fs
# Execute resize2fs before mounting root filesystem
cat > /etc/initramfs-tools/scripts/init-premount/resize <<"EOF"
#!/bin/sh
PREREQ=""
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
/sbin/e2fsck -f "$ROOT" || echo "e2fsck: $?"
# Size in filesystem blocks, usually 4 KB
# tune2fs -l /dev/vda1
# 1310720 blocks = 5 GB
/sbin/resize2fs -d 8 "$ROOT" 1310720 || echo "resize2fs: $?"
EOF
chmod +x /etc/initramfs-tools/scripts/init-premount/resize
# Regenerate initrd
update-initramfs -v -u
# Remove files
rm -f /etc/initramfs-tools/hooks/resize2fs /etc/initramfs-tools/scripts/init-premount/resize
reboot
# Remove files from initrd after reboot
# update-initramfs -u