##// END OF EJS Templates
a
Unknown -
r543:3cf60ec7aa7c
parent child
Show More
@@ -1,113 +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" >> "${ETC_DIR}/crypttab"
29
29
30 if [ "$ENABLE_USBBOOT" = true ] ; then
31 # Add usb/sda2 disk to crypttab
32 sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/crypttab"
33 fi
34
30 if [ "$ENABLE_SPLITFS" = true ] ; then
35 if [ "$ENABLE_SPLITFS" = true ] ; then
31 # Add usb/sda disk to crypttab
36 # Add usb/sda1 disk to crypttab
32 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
37 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
33 fi
38 fi
34 fi
39 fi
35
40
36 # Generate initramfs file
41 # Generate initramfs file
37 if [ "$ENABLE_INITRAMFS" = true ] ; then
42 if [ "$ENABLE_INITRAMFS" = true ] ; then
38 if [ "$ENABLE_CRYPTFS" = true ] ; then
43 if [ "$ENABLE_CRYPTFS" = true ] ; then
39 # Include initramfs scripts to auto expand encrypted root partition
44 # Include initramfs scripts to auto expand encrypted root partition
40 if [ "$EXPANDROOT" = true ] ; then
45 if [ "$EXPANDROOT" = true ] ; then
41 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"
42 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"
43 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"
44 fi
49 fi
45
50
46 if [ "$ENABLE_DHCP" = false ] ; then
51 if [ "$ENABLE_DHCP" = false ] ; then
47 # Get cdir from NET_ADDRESS e.g. 24
52 # Get cdir from NET_ADDRESS e.g. 24
48 cdir=$(${NET_ADDRESS} | cut -d '/' -f2)
53 cdir=$(${NET_ADDRESS} | cut -d '/' -f2)
49
54
50 # 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
51 NET_MASK=$(cdr2mask "$cdir")
56 NET_MASK=$(cdr2mask "$cdir")
52
57
53 # Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf
58 # Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf
54 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
55
60
56 # Regenerate initramfs
61 # Regenerate initramfs
57 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
62 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
58 fi
63 fi
59
64
60 if [ "$CRYPTFS_DROPBEAR" = true ]; then
65 if [ "$CRYPTFS_DROPBEAR" = true ]; then
61 if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then
66 if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then
62 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
63 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
64 else
69 else
65 # Create key
70 # Create key
66 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
67
72
68 # Convert dropbear key to openssh key
73 # Convert dropbear key to openssh key
69 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
70
75
71 # Get Public Key Part
76 # Get Public Key Part
72 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
73
78
74 # Delete unwanted lines
79 # Delete unwanted lines
75 sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
80 sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
76 sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
81 sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
77
82
78 # Trust the new key
83 # Trust the new key
79 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
80
85
81 # Save Keys - convert with putty from rsa/openssh to puttkey
86 # Save Keys - convert with putty from rsa/openssh to puttkey
82 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
83
88
84 # Get unlock script
89 # Get unlock script
85 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
86
91
87 # Enable Dropbear inside initramfs
92 # Enable Dropbear inside initramfs
88 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"
89
94
90 # Enable Dropbear inside initramfs
95 # Enable Dropbear inside initramfs
91 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
92 fi
97 fi
93 else
98 else
94 # Disable SSHD inside initramfs
99 # Disable SSHD inside initramfs
95 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"
96 fi
101 fi
97
102
98 # Add cryptsetup modules to initramfs
103 # Add cryptsetup modules to initramfs
99 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"
100
105
101 # Dummy mapping required by mkinitramfs
106 # Dummy mapping required by mkinitramfs
102 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}"
103
108
104 # Generate initramfs with encrypted root partition support
109 # Generate initramfs with encrypted root partition support
105 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
110 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
106
111
107 # Remove dummy mapping
112 # Remove dummy mapping
108 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
113 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
109 else
114 else
110 # Generate initramfs without encrypted root partition support
115 # Generate initramfs without encrypted root partition support
111 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
116 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
112 fi
117 fi
113 fi
118 fi
@@ -1,289 +1,289
1 #
1 #
2 # Setup RPi2/3 config and cmdline
2 # Setup RPi2/3 config and cmdline
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then
8 if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then
9 # Install boot binaries from local directory
9 # Install boot binaries from local directory
10 cp "${RPI_FIRMWARE_DIR}"/boot/bootcode.bin "${BOOT_DIR}"/bootcode.bin
10 cp "${RPI_FIRMWARE_DIR}"/boot/bootcode.bin "${BOOT_DIR}"/bootcode.bin
11 cp "${RPI_FIRMWARE_DIR}"/boot/fixup.dat "${BOOT_DIR}"/fixup.dat
11 cp "${RPI_FIRMWARE_DIR}"/boot/fixup.dat "${BOOT_DIR}"/fixup.dat
12 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_cd.dat "${BOOT_DIR}"/fixup_cd.dat
12 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_cd.dat "${BOOT_DIR}"/fixup_cd.dat
13 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_x.dat "${BOOT_DIR}"/fixup_x.dat
13 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_x.dat "${BOOT_DIR}"/fixup_x.dat
14 cp "${RPI_FIRMWARE_DIR}"/boot/start.elf "${BOOT_DIR}"/start.elf
14 cp "${RPI_FIRMWARE_DIR}"/boot/start.elf "${BOOT_DIR}"/start.elf
15 cp "${RPI_FIRMWARE_DIR}"/boot/start_cd.elf "${BOOT_DIR}"/start_cd.elf
15 cp "${RPI_FIRMWARE_DIR}"/boot/start_cd.elf "${BOOT_DIR}"/start_cd.elf
16 cp "${RPI_FIRMWARE_DIR}"/boot/start_x.elf "${BOOT_DIR}"/start_x.elf
16 cp "${RPI_FIRMWARE_DIR}"/boot/start_x.elf "${BOOT_DIR}"/start_x.elf
17 else
17 else
18 # Create temporary directory for boot binaries
18 # Create temporary directory for boot binaries
19 temp_dir=$(as_nobody mktemp -d)
19 temp_dir=$(as_nobody mktemp -d)
20
20
21 # Install latest boot binaries from raspberry/firmware github
21 # Install latest boot binaries from raspberry/firmware github
22 as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin"
22 as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin"
23 as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat"
23 as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat"
24 as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat"
24 as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat"
25 as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat"
25 as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat"
26 as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf"
26 as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf"
27 as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf"
27 as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf"
28 as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf"
28 as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf"
29
29
30 # Move downloaded boot binaries
30 # Move downloaded boot binaries
31 mv "${temp_dir}/"* "${BOOT_DIR}/"
31 mv "${temp_dir}/"* "${BOOT_DIR}/"
32
32
33 # Remove temporary directory for boot binaries
33 # Remove temporary directory for boot binaries
34 rm -fr "${temp_dir}"
34 rm -fr "${temp_dir}"
35
35
36 # Set permissions of the boot binaries
36 # Set permissions of the boot binaries
37 chown -R root:root "${BOOT_DIR}"
37 chown -R root:root "${BOOT_DIR}"
38 chmod -R 600 "${BOOT_DIR}"
38 chmod -R 600 "${BOOT_DIR}"
39 fi
39 fi
40
40
41 if [ "$ENABLE_KEYGEN" = true] ; then
41 if [ "$ENABLE_KEYGEN" = true] ; then
42
42
43 # go to chroot/boot/
43 # go to chroot/boot/
44 cd "${BOOT_DIR}/" || exit
44 cd "${BOOT_DIR}/" || exit
45
45
46 # Make a copy of start.elf
46 # Make a copy of start.elf
47 cp start.elf start.elf_backup
47 cp start.elf start.elf_backup
48
48
49 # Remove codec licence checks - thx go to https://github.com/nucular/raspi-keygen - if ENABLE_VIDEOCORE is true, you can check codec status https://elinux.org/RPI_vcgencmd_usage
49 # Remove codec licence checks - thx go to https://github.com/nucular/raspi-keygen - if ENABLE_VIDEOCORE is true, you can check codec status https://elinux.org/RPI_vcgencmd_usage
50 perl -pne 's/\x47\xE9362H\x3C\x18/\x47\xE9362H\x3C\x1F/g' < start.elf_backup > start.elf
50 perl -pne 's/\x47\xE9362H\x3C\x18/\x47\xE9362H\x3C\x1F/g' < start.elf_backup > start.elf
51
51
52 # Back to base dir
52 # Back to base dir
53 cd "${WORKDIR}" || exit
53 cd "${WORKDIR}" || exit
54 fi
54 fi
55
55
56 # Setup firmware boot cmdline
56 # Setup firmware boot cmdline
57 if [ "$ENABLE_USBBOOT" = true ] ; then
57 if [ "$ENABLE_USBBOOT" = true ] ; then
58 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait init=/bin/systemd"
58 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline console=tty1 rootwait init=/bin/systemd"
59 else
59 else
60 if [ "$ENABLE_SPLITFS" = true ] ; then
60 if [ "$ENABLE_SPLITFS" = true ] ; then
61 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait init=/bin/systemd"
61 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline console=tty1 rootwait init=/bin/systemd"
62 else
62 else
63 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait init=/bin/systemd"
63 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline console=tty1 rootwait init=/bin/systemd"
64 fi
64 fi
65 fi
65 fi
66
66
67 # Add encrypted root partition to cmdline.txt
67 # Add encrypted root partition to cmdline.txt
68 if [ "$ENABLE_CRYPTFS" = true ] ; then
68 if [ "$ENABLE_CRYPTFS" = true ] ; then
69 if [ "$ENABLE_SPLITFS" = true ] ; then
69 if [ "$ENABLE_SPLITFS" = true ] ; then
70 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
70 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
71 else
71 else
72 if [ "$ENABLE_USBBOOT" = true ] ; then
72 if [ "$ENABLE_USBBOOT" = true ] ; then
73 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda2:${CRYPTFS_MAPPING}/")
73 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda2:${CRYPTFS_MAPPING}/")
74 else
74 else
75 CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
75 CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
76 fi
76 fi
77 fi
77 fi
78 fi
78 fi
79
79
80 # Enable Kernel messages on standard output
80 # Enable Kernel messages on standard output
81 if [ "$ENABLE_PRINTK" = true ] ; then
81 if [ "$ENABLE_PRINTK" = true ] ; then
82 install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf"
82 install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf"
83 fi
83 fi
84
84
85 # Enable Kernel messages on standard output
85 # Enable Kernel messages on standard output
86 if [ "$KERNEL_SECURITY" = true ] ; then
86 if [ "$KERNEL_SECURITY" = true ] ; then
87 install_readonly files/sysctl.d/84-rpi-ASLR.conf "${ETC_DIR}/sysctl.d/84-rpi-ASLR.conf"
87 install_readonly files/sysctl.d/84-rpi-ASLR.conf "${ETC_DIR}/sysctl.d/84-rpi-ASLR.conf"
88 fi
88 fi
89
89
90 # Install udev rule for serial alias - serial0 = console serial1=bluetooth
90 # Install udev rule for serial alias - serial0 = console serial1=bluetooth
91 install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules"
91 install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules"
92
92
93 # Remove IPv6 networking support
93 # Remove IPv6 networking support
94 if [ "$ENABLE_IPV6" = false ] ; then
94 if [ "$ENABLE_IPV6" = false ] ; then
95 CMDLINE="${CMDLINE} ipv6.disable=1"
95 CMDLINE="${CMDLINE} ipv6.disable=1"
96 fi
96 fi
97
97
98 # Automatically assign predictable network interface names
98 # Automatically assign predictable network interface names
99 if [ "$ENABLE_IFNAMES" = false ] ; then
99 if [ "$ENABLE_IFNAMES" = false ] ; then
100 CMDLINE="${CMDLINE} net.ifnames=0"
100 CMDLINE="${CMDLINE} net.ifnames=0"
101 else
101 else
102 CMDLINE="${CMDLINE} net.ifnames=1"
102 CMDLINE="${CMDLINE} net.ifnames=1"
103 fi
103 fi
104
104
105 # Install firmware config
105 # Install firmware config
106 install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt"
106 install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt"
107
107
108 # Locks CPU frequency at maximum
108 # Locks CPU frequency at maximum
109 if [ "$ENABLE_TURBO" = true ] ; then
109 if [ "$ENABLE_TURBO" = true ] ; then
110 echo "force_turbo=1" >> "${BOOT_DIR}/config.txt"
110 echo "force_turbo=1" >> "${BOOT_DIR}/config.txt"
111 # helps to avoid sdcard corruption when force_turbo is enabled.
111 # helps to avoid sdcard corruption when force_turbo is enabled.
112 echo "boot_delay=1" >> "${BOOT_DIR}/config.txt"
112 echo "boot_delay=1" >> "${BOOT_DIR}/config.txt"
113 fi
113 fi
114
114
115 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
115 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
116
116
117 # Bluetooth enabled
117 # Bluetooth enabled
118 if [ "$ENABLE_BLUETOOTH" = true ] ; then
118 if [ "$ENABLE_BLUETOOTH" = true ] ; then
119 # Create temporary directory for Bluetooth sources
119 # Create temporary directory for Bluetooth sources
120 temp_dir=$(as_nobody mktemp -d)
120 temp_dir=$(as_nobody mktemp -d)
121
121
122 # Fetch Bluetooth sources
122 # Fetch Bluetooth sources
123 as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}"
123 as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}"
124
124
125 # Copy downloaded sources
125 # Copy downloaded sources
126 mv "${temp_dir}/pi-bluetooth" "${R}/tmp/"
126 mv "${temp_dir}/pi-bluetooth" "${R}/tmp/"
127
127
128 # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/
128 # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/
129 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth
129 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth
130 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth
130 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth
131
131
132 # Set permissions
132 # Set permissions
133 chown -R root:root "${R}/tmp/pi-bluetooth"
133 chown -R root:root "${R}/tmp/pi-bluetooth"
134
134
135 # Install tools
135 # Install tools
136 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart"
136 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart"
137 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper"
137 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper"
138
138
139 # make scripts executable
139 # make scripts executable
140 chmod +x "${R}/usr/bin/bthelper"
140 chmod +x "${R}/usr/bin/bthelper"
141 chmod +x "${R}/usr/bin/btuart"
141 chmod +x "${R}/usr/bin/btuart"
142
142
143 # Install bluetooth udev rule
143 # Install bluetooth udev rule
144 install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules"
144 install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules"
145
145
146 # Install Firmware Flash file and apropiate licence
146 # Install Firmware Flash file and apropiate licence
147 mkdir -p "$BLUETOOTH_FIRMWARE_DIR"
147 mkdir -p "$BLUETOOTH_FIRMWARE_DIR"
148 install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
148 install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
149 install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
149 install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
150 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service"
150 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service"
151 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service"
151 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service"
152
152
153 # Remove temporary directories
153 # Remove temporary directories
154 rm -fr "${temp_dir}"
154 rm -fr "${temp_dir}"
155 rm -fr "${R}"/tmp/pi-bluetooth
155 rm -fr "${R}"/tmp/pi-bluetooth
156
156
157 # Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore UART0/ttyAMA0 over GPIOs 14 & 15. Slow Bluetooth and slow cpu. Use /dev/ttyS0 instead of /dev/ttyAMA0
157 # Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore UART0/ttyAMA0 over GPIOs 14 & 15. Slow Bluetooth and slow cpu. Use /dev/ttyS0 instead of /dev/ttyAMA0
158 if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then
158 if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then
159
159
160 # set overlay to swap ttyAMA0 and ttyS0
160 # set overlay to swap ttyAMA0 and ttyS0
161 echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt"
161 echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt"
162
162
163 # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken
163 # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken
164 if [ "$ENABLE_TURBO" = false ] ; then
164 if [ "$ENABLE_TURBO" = false ] ; then
165 echo "core_freq=250" >> "${BOOT_DIR}/config.txt"
165 echo "core_freq=250" >> "${BOOT_DIR}/config.txt"
166 fi
166 fi
167 fi
167 fi
168
168
169 # Activate services
169 # Activate services
170 chroot_exec systemctl enable pi-bluetooth.hciuart.service
170 chroot_exec systemctl enable pi-bluetooth.hciuart.service
171
171
172 else # if ENABLE_BLUETOOTH = false
172 else # if ENABLE_BLUETOOTH = false
173 # set overlay to disable bluetooth
173 # set overlay to disable bluetooth
174 echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt"
174 echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt"
175 fi # ENABLE_BLUETOOTH end
175 fi # ENABLE_BLUETOOTH end
176 fi
176 fi
177
177
178 # may need sudo systemctl disable hciuart
178 # may need sudo systemctl disable hciuart
179 if [ "$ENABLE_CONSOLE" = true ] ; then
179 if [ "$ENABLE_CONSOLE" = true ] ; then
180 echo "enable_uart=1" >> "${BOOT_DIR}/config.txt"
180 echo "enable_uart=1" >> "${BOOT_DIR}/config.txt"
181 # add string to cmdline
181 # add string to cmdline
182 CMDLINE="${CMDLINE} console=serial0,115200"
182 CMDLINE="${CMDLINE} console=serial0,115200"
183
183
184 # Enable serial console systemd style
184 # Enable serial console systemd style
185 chroot_exec systemctl enable serial-getty\@serial0.service
185 chroot_exec systemctl enable serial-getty\@serial0.service
186 else
186 else
187 echo "enable_uart=0" >> "${BOOT_DIR}/config.txt"
187 echo "enable_uart=0" >> "${BOOT_DIR}/config.txt"
188 fi
188 fi
189
189
190 if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then
190 if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then
191 # Create temporary directory for systemd-swap sources
191 # Create temporary directory for systemd-swap sources
192 temp_dir=$(as_nobody mktemp -d)
192 temp_dir=$(as_nobody mktemp -d)
193
193
194 # Fetch systemd-swap sources
194 # Fetch systemd-swap sources
195 as_nobody git -C "${temp_dir}" clone "${SYSTEMDSWAP_URL}"
195 as_nobody git -C "${temp_dir}" clone "${SYSTEMDSWAP_URL}"
196
196
197 # Copy downloaded systemd-swap sources
197 # Copy downloaded systemd-swap sources
198 mv "${temp_dir}/systemd-swap" "${R}/tmp/"
198 mv "${temp_dir}/systemd-swap" "${R}/tmp/"
199
199
200 # Change into downloaded src dir
200 # Change into downloaded src dir
201 cd "${R}/tmp/systemd-swap" || exit
201 cd "${R}/tmp/systemd-swap" || exit
202
202
203 # Build package
203 # Build package
204 bash ./package.sh debian
204 bash ./package.sh debian
205
205
206 # Change back into script root dir
206 # Change back into script root dir
207 cd "${WORKDIR}" || exit
207 cd "${WORKDIR}" || exit
208
208
209 # Set permissions of the systemd-swap sources
209 # Set permissions of the systemd-swap sources
210 chown -R root:root "${R}/tmp/systemd-swap"
210 chown -R root:root "${R}/tmp/systemd-swap"
211
211
212 # Install package - IMPROVE AND MAKE IT POSSIBLE WITHOUT VERSION NR.
212 # Install package - IMPROVE AND MAKE IT POSSIBLE WITHOUT VERSION NR.
213 chroot_exec dpkg -i /tmp/systemd-swap/systemd-swap_4.0.1_any.deb
213 chroot_exec dpkg -i /tmp/systemd-swap/systemd-swap_4.0.1_any.deb
214
214
215 # Enable service
215 # Enable service
216 chroot_exec systemctl enable systemd-swap
216 chroot_exec systemctl enable systemd-swap
217
217
218 # Remove temporary directory for systemd-swap sources
218 # Remove temporary directory for systemd-swap sources
219 rm -fr "${temp_dir}"
219 rm -fr "${temp_dir}"
220 else
220 else
221 # Enable ZSWAP in cmdline if systemd-swap is not used
221 # Enable ZSWAP in cmdline if systemd-swap is not used
222 if [ "$KERNEL_ZSWAP" = true ] ; then
222 if [ "$KERNEL_ZSWAP" = true ] ; then
223 CMDLINE="${CMDLINE} zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4"
223 CMDLINE="${CMDLINE} zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4"
224 fi
224 fi
225 fi
225 fi
226 if [ "$KERNEL_SECURITY" = true ] ; then
226 if [ "$KERNEL_SECURITY" = true ] ; then
227 CMDLINE="${CMDLINE} apparmor=1 security=apparmor"
227 CMDLINE="${CMDLINE} apparmor=1 security=apparmor"
228 fi
228 fi
229
229
230 # Install firmware boot cmdline
230 # Install firmware boot cmdline
231 echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt"
231 echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt"
232
232
233 # Setup minimal GPU memory allocation size: 16MB (no X)
233 # Setup minimal GPU memory allocation size: 16MB (no X)
234 if [ "$ENABLE_MINGPU" = true ] ; then
234 if [ "$ENABLE_MINGPU" = true ] ; then
235 echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt"
235 echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt"
236 fi
236 fi
237
237
238 # Setup boot with initramfs
238 # Setup boot with initramfs
239 if [ "$ENABLE_INITRAMFS" = true ] ; then
239 if [ "$ENABLE_INITRAMFS" = true ] ; then
240 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt"
240 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt"
241 fi
241 fi
242
242
243 # Create firmware configuration and cmdline symlinks
243 # Create firmware configuration and cmdline symlinks
244 ln -sf firmware/config.txt "${R}/boot/config.txt"
244 ln -sf firmware/config.txt "${R}/boot/config.txt"
245 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
245 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
246
246
247 # Install and setup kernel modules to load at boot
247 # Install and setup kernel modules to load at boot
248 mkdir -p "${LIB_DIR}/modules-load.d/"
248 mkdir -p "${LIB_DIR}/modules-load.d/"
249 install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf"
249 install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf"
250
250
251 # Load hardware random module at boot
251 # Load hardware random module at boot
252 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
252 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
253 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf"
253 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf"
254 fi
254 fi
255
255
256 # Load sound module at boot
256 # Load sound module at boot
257 if [ "$ENABLE_SOUND" = true ] ; then
257 if [ "$ENABLE_SOUND" = true ] ; then
258 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
258 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
259 else
259 else
260 echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt"
260 echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt"
261 fi
261 fi
262
262
263 # Enable I2C interface
263 # Enable I2C interface
264 if [ "$ENABLE_I2C" = true ] ; then
264 if [ "$ENABLE_I2C" = true ] ; then
265 echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt"
265 echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt"
266 sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf"
266 sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf"
267 sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf"
267 sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf"
268 fi
268 fi
269
269
270 # Enable SPI interface
270 # Enable SPI interface
271 if [ "$ENABLE_SPI" = true ] ; then
271 if [ "$ENABLE_SPI" = true ] ; then
272 echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt"
272 echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt"
273 echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf"
273 echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf"
274 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then
274 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then
275 sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
275 sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
276 fi
276 fi
277 fi
277 fi
278
278
279 # Disable RPi2/3 under-voltage warnings
279 # Disable RPi2/3 under-voltage warnings
280 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
280 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
281 echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt"
281 echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt"
282 fi
282 fi
283
283
284 # Install kernel modules blacklist
284 # Install kernel modules blacklist
285 mkdir -p "${ETC_DIR}/modprobe.d/"
285 mkdir -p "${ETC_DIR}/modprobe.d/"
286 install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf"
286 install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf"
287
287
288 # Install sysctl.d configuration files
288 # Install sysctl.d configuration files
289 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf"
289 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf"
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant