-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathdebian-convert-ext3-ext4.sh
executable file
·80 lines (60 loc) · 1.61 KB
/
debian-convert-ext3-ext4.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
#!/bin/bash
#
# Convert root filesystem to ext4 during boot.
#
# VERSION :1.0.1
# DATE :2018-04-01
# URL :https://github.com/szepeviktor/debian-server-tools
# AUTHOR :Viktor Szépe <[email protected]>
# LICENSE :The MIT License (MIT)
# BASH-VERSION :4.2+
# Check current filesystem type
ROOT_FS_TYPE="$(sed -n -e 's|^/dev/\S\+ / \(ext3\) .*$|\1|p' /proc/mounts)"
test "$ROOT_FS_TYPE" == ext3 || exit 100
# Copy tune2fs to initrd
cat > /etc/initramfs-tools/hooks/tune2fs <<"EOF"
#!/bin/sh
PREREQ=""
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
copy_exec /sbin/tune2fs /sbin
EOF
chmod +x /etc/initramfs-tools/hooks/tune2fs
# Execute tune2fs before mounting root filesystem
cat > /etc/initramfs-tools/scripts/init-premount/ext4 <<"EOF"
#!/bin/sh
PREREQ=""
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
echo "Starting ${ROOT} conversion"
/sbin/tune2fs -O extent,uninit_bg,dir_index -f "$ROOT" || echo "tune2fs: $?"
EOF
chmod +x /etc/initramfs-tools/scripts/init-premount/ext4
# Change specified filesystem
sed -i -e 's|\sext3\s| ext4 |' /etc/fstab
# Regenerate initrd
update-initramfs -v -u
# Remove files
rm -f /etc/initramfs-tools/hooks/tune2fs /etc/initramfs-tools/scripts/init-premount/ext4
reboot
# List files in initrd
# lsinitramfs /boot/initrd.img-*-amd64
# List filesystem features
# tune2fs -l "$DEVICE" | sed -ne 's|^Filesystem features:\s\+\(.*\)$|\1|p'
# Remove files from initrd after reboot
# update-initramfs -u