forked from szepeviktor/debian-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian-convert-ext3-ext4.sh
executable file
·74 lines (54 loc) · 1.4 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
#!/bin/bash
#
# Convert root filesystem to ext4 during boot.
#
# Check current filesystem type
ROOT_FS_TYPE="$(sed -n -e 's|^/dev/[a-z]\+[1-9]\+ / \(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