##// END OF EJS Templates
echt
Unknown -
r544:ffdcbaa524c3
parent child
Show More
@@ -1,118 +1,118
1 #
1 #
2 # Setup fstab and initramfs
2 # Setup fstab and initramfs
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Install and setup fstab
8 # Install and setup fstab
9 install_readonly files/mount/fstab "${ETC_DIR}/fstab"
9 install_readonly files/mount/fstab "${ETC_DIR}/fstab"
10
10
11 if [ "$ENABLE_USBBOOT" = true ] ; then
11 if [ "$ENABLE_USBBOOT" = true ] ; then
12 sed -i "s/mmcblk0p1/sda1/" "${ETC_DIR}/fstab"
12 sed -i "s/mmcblk0p1/sda1/" "${ETC_DIR}/fstab"
13 sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/fstab"
13 sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/fstab"
14 fi
14 fi
15
15
16 # Add usb/sda disk root partition to fstab
16 # Add usb/sda disk root partition to fstab
17 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
17 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
18 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab"
18 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab"
19 fi
19 fi
20
20
21 # Add encrypted root partition to fstab and crypttab
21 # Add encrypted root partition to fstab and crypttab
22 if [ "$ENABLE_CRYPTFS" = true ] ; then
22 if [ "$ENABLE_CRYPTFS" = true ] ; then
23 # Replace fstab root partition with encrypted partition mapping
23 # Replace fstab root partition with encrypted partition mapping
24 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab"
24 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab"
25
25
26 # Add encrypted partition to crypttab and fstab
26 # Add encrypted partition to crypttab and fstab
27 install_readonly files/mount/crypttab "${ETC_DIR}/crypttab"
27 install_readonly files/mount/crypttab "${ETC_DIR}/crypttab"
28 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks" >> "${ETC_DIR}/crypttab"
28 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab"
29
29
30 if [ "$ENABLE_USBBOOT" = true ] ; then
30 if [ "$ENABLE_USBBOOT" = true ] ; then
31 # Add usb/sda2 disk to crypttab
31 # Add usb/sda2 disk to crypttab
32 sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/crypttab"
32 sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/crypttab"
33 fi
33 fi
34
34
35 if [ "$ENABLE_SPLITFS" = true ] ; then
35 if [ "$ENABLE_SPLITFS" = true ] ; then
36 # Add usb/sda1 disk to crypttab
36 # Add usb/sda1 disk to crypttab
37 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
37 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
38 fi
38 fi
39 fi
39 fi
40
40
41 # Generate initramfs file
41 # Generate initramfs file
42 if [ "$ENABLE_INITRAMFS" = true ] ; then
42 if [ "$ENABLE_INITRAMFS" = true ] ; then
43 if [ "$ENABLE_CRYPTFS" = true ] ; then
43 if [ "$ENABLE_CRYPTFS" = true ] ; then
44 # Include initramfs scripts to auto expand encrypted root partition
44 # Include initramfs scripts to auto expand encrypted root partition
45 if [ "$EXPANDROOT" = true ] ; then
45 if [ "$EXPANDROOT" = true ] ; then
46 install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
46 install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
47 install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount"
47 install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount"
48 install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools"
48 install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools"
49 fi
49 fi
50
50
51 if [ "$ENABLE_DHCP" = false ] ; then
51 if [ "$ENABLE_DHCP" = false ] ; then
52 # Get cdir from NET_ADDRESS e.g. 24
52 # Get cdir from NET_ADDRESS e.g. 24
53 cdir=$(${NET_ADDRESS} | cut -d '/' -f2)
53 cdir=$(${NET_ADDRESS} | cut -d '/' -f2)
54
54
55 # Convert cdir ro netmask e.g. 24 to 255.255.255.0
55 # Convert cdir ro netmask e.g. 24 to 255.255.255.0
56 NET_MASK=$(cdr2mask "$cdir")
56 NET_MASK=$(cdr2mask "$cdir")
57
57
58 # Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf
58 # Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf
59 sed -i "\$aIP=${NET_ADDRESS}::${NET_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf
59 sed -i "\$aIP=${NET_ADDRESS}::${NET_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf
60
60
61 # Regenerate initramfs
61 # Regenerate initramfs
62 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
62 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
63 fi
63 fi
64
64
65 if [ "$CRYPTFS_DROPBEAR" = true ]; then
65 if [ "$CRYPTFS_DROPBEAR" = true ]; then
66 if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then
66 if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then
67 install_readonly "${CRYPTFS_DROPBEAR_PUBKEY}" "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
67 install_readonly "${CRYPTFS_DROPBEAR_PUBKEY}" "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
68 cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub >> "${ETC_DIR}"/dropbear-initramfs/authorized_keys
68 cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub >> "${ETC_DIR}"/dropbear-initramfs/authorized_keys
69 else
69 else
70 # Create key
70 # Create key
71 chroot_exec /usr/bin/dropbearkey -t rsa -f /etc/dropbear-initramfs/id_rsa.dropbear
71 chroot_exec /usr/bin/dropbearkey -t rsa -f /etc/dropbear-initramfs/id_rsa.dropbear
72
72
73 # Convert dropbear key to openssh key
73 # Convert dropbear key to openssh key
74 chroot_exec /usr/lib/dropbear/dropbearconvert dropbear openssh /etc/dropbear-initramfs/id_rsa.dropbear /etc/dropbear-initramfs/id_rsa
74 chroot_exec /usr/lib/dropbear/dropbearconvert dropbear openssh /etc/dropbear-initramfs/id_rsa.dropbear /etc/dropbear-initramfs/id_rsa
75
75
76 # Get Public Key Part
76 # Get Public Key Part
77 chroot_exec /usr/bin/dropbearkey -y -f /etc/dropbear-initramfs/id_rsa.dropbear | chroot_exec tee /etc/dropbear-initramfs/id_rsa.pub
77 chroot_exec /usr/bin/dropbearkey -y -f /etc/dropbear-initramfs/id_rsa.dropbear | chroot_exec tee /etc/dropbear-initramfs/id_rsa.pub
78
78
79 # Delete unwanted lines
79 # Delete unwanted lines
80 sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
80 sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
81 sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
81 sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
82
82
83 # Trust the new key
83 # Trust the new key
84 cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub > "${ETC_DIR}"/dropbear-initramfs/authorized_keys
84 cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub > "${ETC_DIR}"/dropbear-initramfs/authorized_keys
85
85
86 # Save Keys - convert with putty from rsa/openssh to puttkey
86 # Save Keys - convert with putty from rsa/openssh to puttkey
87 cp -f "${ETC_DIR}"/dropbear-initramfs/id_rsa "${BASEDIR}"/dropbear_initramfs_key.rsa
87 cp -f "${ETC_DIR}"/dropbear-initramfs/id_rsa "${BASEDIR}"/dropbear_initramfs_key.rsa
88
88
89 # Get unlock script
89 # Get unlock script
90 install_exec files/initramfs/crypt_unlock.sh "${ETC_DIR}"/initramfs-tools/hooks/crypt_unlock.sh
90 install_exec files/initramfs/crypt_unlock.sh "${ETC_DIR}"/initramfs-tools/hooks/crypt_unlock.sh
91
91
92 # Enable Dropbear inside initramfs
92 # Enable Dropbear inside initramfs
93 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=y\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
93 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=y\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
94
94
95 # Enable Dropbear inside initramfs
95 # Enable Dropbear inside initramfs
96 sed -i "54 i sleep 5" "${R}"/usr/share/initramfs-tools/scripts/init-premount/dropbear
96 sed -i "54 i sleep 5" "${R}"/usr/share/initramfs-tools/scripts/init-premount/dropbear
97 fi
97 fi
98 else
98 else
99 # Disable SSHD inside initramfs
99 # Disable SSHD inside initramfs
100 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
100 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
101 fi
101 fi
102
102
103 # Add cryptsetup modules to initramfs
103 # Add cryptsetup modules to initramfs
104 printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook"
104 printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook"
105
105
106 # Dummy mapping required by mkinitramfs
106 # Dummy mapping required by mkinitramfs
107 echo "0 1 crypt $(echo "${CRYPTFS_CIPHER}" | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
107 echo "0 1 crypt $(echo "${CRYPTFS_CIPHER}" | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
108
108
109 # Generate initramfs with encrypted root partition support
109 # Generate initramfs with encrypted root partition support
110 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
110 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
111
111
112 # Remove dummy mapping
112 # Remove dummy mapping
113 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
113 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
114 else
114 else
115 # Generate initramfs without encrypted root partition support
115 # Generate initramfs without encrypted root partition support
116 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
116 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
117 fi
117 fi
118 fi
118 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant