@@ -1,116 +1,121 | |||
|
1 | # | |
|
1 | #!/bin/sh | |
|
2 | 2 | # Setup fstab and initramfs |
|
3 | 3 | # |
|
4 | 4 | |
|
5 | 5 | # Load utility functions |
|
6 | 6 | . ./functions.sh |
|
7 | 7 | |
|
8 | 8 | # Install and setup fstab |
|
9 | 9 | install_readonly files/mount/fstab "${ETC_DIR}/fstab" |
|
10 | 10 | |
|
11 | 11 | # Add usb/sda disk root partition to fstab |
|
12 | 12 | if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then |
|
13 | 13 | sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab" |
|
14 | 14 | fi |
|
15 | 15 | |
|
16 | # Add encrypted root partition to fstab and crypttab | |
|
17 | if [ "$ENABLE_CRYPTFS" = true ] ; then | |
|
18 | # Replace fstab root partition with encrypted partition mapping | |
|
19 | sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab" | |
|
20 | ||
|
21 | # Add encrypted partition to crypttab and fstab | |
|
22 | install_readonly files/mount/crypttab "${ETC_DIR}/crypttab" | |
|
23 | echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab" | |
|
24 | ||
|
25 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
|
26 | # Add usb/sda1 disk to crypttab | |
|
27 | sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab" | |
|
28 | fi | |
|
29 | fi | |
|
30 | ||
|
31 | 16 | if [ "$ENABLE_USBBOOT" = true ] ; then |
|
32 | 17 | sed -i "s/mmcblk0p1/sda1/" "${ETC_DIR}/fstab" |
|
33 | 18 | sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/fstab" |
|
34 | 19 | |
|
35 | 20 | # Add usb/sda2 disk to crypttab |
|
36 | 21 | sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/crypttab" |
|
37 | 22 | fi |
|
38 | 23 | |
|
39 | 24 | # Generate initramfs file |
|
40 | 25 | if [ "$ENABLE_INITRAMFS" = true ] ; then |
|
41 | 26 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
27 | if [ "$ENABLE_USBBOOT" = true ] ; then | |
|
28 | # Add usb/sda2 disk to crypttab | |
|
29 | sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/crypttab" | |
|
30 | fi | |
|
31 | ||
|
42 | 32 | # Include initramfs scripts to auto expand encrypted root partition |
|
43 | 33 | if [ "$EXPANDROOT" = true ] ; then |
|
44 | 34 | install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs" |
|
45 | 35 | install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount" |
|
46 | 36 | install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools" |
|
47 | 37 | fi |
|
48 | 38 | |
|
39 | # Replace fstab root partition with encrypted partition mapping | |
|
40 | sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab" | |
|
41 | ||
|
42 | # Add encrypted partition to crypttab and fstab | |
|
43 | install_readonly files/mount/crypttab "${ETC_DIR}/crypttab" | |
|
44 | echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab" | |
|
45 | ||
|
46 | # Add encrypted root partition to fstab and crypttab | |
|
47 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
|
48 | # Add usb/sda1 disk to crypttab | |
|
49 | sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab" | |
|
50 | fi | |
|
51 | ||
|
52 | if [ "$CRYPTFS_DROPBEAR" = true ]; then | |
|
49 | 53 |
|
|
50 | 54 | # Get cdir from NET_ADDRESS e.g. 24 |
|
51 | cdir=$(printf ${NET_ADDRESS} | cut -d '/' -f2) | |
|
55 | cdir=$(printf "%s" "${NET_ADDRESS}" | cut -d '/' -f2) | |
|
52 | 56 | |
|
53 | 57 | # Convert cdir ro netmask e.g. 24 to 255.255.255.0 |
|
54 | 58 | NET_MASK=$(cdr2mask "$cdir") |
|
55 | 59 | |
|
56 | 60 |
|
|
57 | 61 | sed -i "\$aIP=${NET_ADDRESS}::${NET_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf |
|
58 | 62 | |
|
59 | 63 |
|
|
60 |
|
|
|
64 | #chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" | |
|
61 | 65 | fi |
|
62 | 66 | |
|
63 | if [ "$CRYPTFS_DROPBEAR" = true ]; then | |
|
64 | 67 |
|
|
65 | 68 |
|
|
66 | 69 |
|
|
67 | 70 |
|
|
68 | 71 |
|
|
69 | 72 |
|
|
70 | 73 | |
|
71 | 74 |
|
|
72 | 75 |
|
|
73 | 76 | |
|
74 | 77 |
|
|
75 | 78 |
|
|
76 | 79 | |
|
77 | 80 |
|
|
78 | 81 |
|
|
79 | 82 |
|
|
80 | 83 | |
|
81 | 84 |
|
|
82 | 85 |
|
|
83 | 86 | |
|
84 | 87 |
|
|
85 | 88 |
|
|
86 | 89 | |
|
87 | 90 |
|
|
88 | 91 |
|
|
89 | 92 | |
|
90 | 93 |
|
|
91 | 94 |
|
|
92 | 95 | |
|
93 | 96 |
|
|
94 | 97 |
|
|
95 | 98 |
|
|
99 | # CRYPTFSDROPBEAR=false | |
|
96 | 100 |
|
|
97 | 101 |
|
|
98 | 102 |
|
|
99 | 103 | fi |
|
100 | 104 | |
|
101 | 105 | # Add cryptsetup modules to initramfs |
|
102 | 106 | printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook" |
|
103 | 107 | |
|
104 | 108 | # Dummy mapping required by mkinitramfs |
|
105 | 109 | echo "0 1 crypt $(echo "${CRYPTFS_CIPHER}" | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}" |
|
106 | 110 | |
|
107 | 111 | # Generate initramfs with encrypted root partition support |
|
108 | 112 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" |
|
109 | 113 | |
|
110 | 114 | # Remove dummy mapping |
|
111 | 115 | chroot_exec cryptsetup close "${CRYPTFS_MAPPING}" |
|
116 | # CRYPTFS=false | |
|
112 | 117 | else |
|
113 | 118 | # Generate initramfs without encrypted root partition support |
|
114 | 119 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" |
|
115 | 120 | fi |
|
116 | 121 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant