##// END OF EJS Templates
Reordered firstboot script...
Yannick Schinko -
r576:291657012c0e
parent child
Show More
@@ -1,54 +1,54
1 #
1 #
2 # First boot actions
2 # First boot actions
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Prepare rc.firstboot script
8 # Prepare rc.firstboot script
9 cat files/firstboot/10-begin.sh > "${ETC_DIR}/rc.firstboot"
9 cat files/firstboot/10-begin.sh > "${ETC_DIR}/rc.firstboot"
10
10
11 # Ensure openssh server host keys are regenerated on first boot
12 if [ "$ENABLE_SSHD" = true ] ; then
13 cat files/firstboot/20-generate-ssh-keys.sh >> "${ETC_DIR}/rc.firstboot"
14 fi
15
16 # Prepare filesystem auto expand
11 # Prepare filesystem auto expand
17 if [ "$EXPANDROOT" = true ] ; then
12 if [ "$EXPANDROOT" = true ] ; then
18 if [ "$ENABLE_CRYPTFS" = false ] ; then
13 if [ "$ENABLE_CRYPTFS" = false ] ; then
19 cat files/firstboot/30-expandroot.sh >> "${ETC_DIR}/rc.firstboot"
14 cat files/firstboot/20-expandroot.sh >> "${ETC_DIR}/rc.firstboot"
20
21 # Restart dphys-swapfile so the size of the swap file is relative to the resized root partition
22 if [ "$ENABLE_DPHYSSWAP" = true ] ; then
23 cat files/firstboot/31-restart-dphys-swapfile.sh >> "${ETC_DIR}/rc.firstboot"
24 fi
25 else
15 else
26 # Regenerate initramfs to remove encrypted root partition auto expand
16 # Regenerate initramfs to remove encrypted root partition auto expand
27 cat files/firstboot/33-regenerate-initramfs.sh >> "${ETC_DIR}/rc.firstboot"
17 cat files/firstboot/21-regenerate-initramfs.sh >> "${ETC_DIR}/rc.firstboot"
28 fi
18 fi
19
20 # Restart dphys-swapfile so the size of the swap file is relative to the resized root partition
21 if [ "$ENABLE_DPHYSSWAP" = true ] ; then
22 cat files/firstboot/23-restart-dphys-swapfile.sh >> "${ETC_DIR}/rc.firstboot"
23 fi
24 fi
25
26 # Ensure openssh server host keys are regenerated on first boot
27 if [ "$ENABLE_SSHD" = true ] ; then
28 cat files/firstboot/30-generate-ssh-keys.sh >> "${ETC_DIR}/rc.firstboot"
29 fi
29 fi
30
30
31 # Ensure that dbus machine-id exists
31 # Ensure that dbus machine-id exists
32 cat files/firstboot/40-generate-machineid.sh >> "${ETC_DIR}/rc.firstboot"
32 cat files/firstboot/40-generate-machineid.sh >> "${ETC_DIR}/rc.firstboot"
33
33
34 # Create /etc/resolv.conf symlink
34 # Create /etc/resolv.conf symlink
35 cat files/firstboot/41-create-resolv-symlink.sh >> "${ETC_DIR}/rc.firstboot"
35 cat files/firstboot/41-create-resolv-symlink.sh >> "${ETC_DIR}/rc.firstboot"
36
36
37 # Configure automatic network interface names
37 # Configure automatic network interface names
38 if [ "$ENABLE_IFNAMES" = true ] ; then
38 if [ "$ENABLE_IFNAMES" = true ] ; then
39 cat files/firstboot/42-config-ifnames.sh >> "${ETC_DIR}/rc.firstboot"
39 cat files/firstboot/42-config-ifnames.sh >> "${ETC_DIR}/rc.firstboot"
40 fi
40 fi
41
41
42 # Finalize rc.firstboot script
42 # Finalize rc.firstboot script
43 cat files/firstboot/99-finish.sh >> "${ETC_DIR}/rc.firstboot"
43 cat files/firstboot/99-finish.sh >> "${ETC_DIR}/rc.firstboot"
44 chmod +x "${ETC_DIR}/rc.firstboot"
44 chmod +x "${ETC_DIR}/rc.firstboot"
45
45
46 # Install default rc.local if it does not exist
46 # Install default rc.local if it does not exist
47 if [ ! -f "${ETC_DIR}/rc.local" ] ; then
47 if [ ! -f "${ETC_DIR}/rc.local" ] ; then
48 install_exec files/etc/rc.local "${ETC_DIR}/rc.local"
48 install_exec files/etc/rc.local "${ETC_DIR}/rc.local"
49 fi
49 fi
50
50
51 # Add rc.firstboot script to rc.local
51 # Add rc.firstboot script to rc.local
52 sed -i '/exit 0/d' "${ETC_DIR}/rc.local"
52 sed -i '/exit 0/d' "${ETC_DIR}/rc.local"
53 echo /etc/rc.firstboot >> "${ETC_DIR}/rc.local"
53 echo /etc/rc.firstboot >> "${ETC_DIR}/rc.local"
54 echo exit 0 >> "${ETC_DIR}/rc.local"
54 echo exit 0 >> "${ETC_DIR}/rc.local"
@@ -1,76 +1,68
1 logger -t "rc.firstboot" "Expanding root partition"
1 logger -t "rc.firstboot" "Expanding root partition"
2
2
3 # Detect root partition device
3 # Detect root partition device
4 ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
4 ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
5 if [ -z "$ROOT_PART" ] ; then
5 if [ -z "$ROOT_PART" ] ; then
6 log_warning_msg "unable to detect root partition device"
6 log_warning_msg "unable to detect root partition device"
7 return 1
7 return 1
8 fi
8 fi
9
9
10 # Extract root device name
10 # Extract root device name
11 case "${ROOT_PART}" in
11 case "${ROOT_PART}" in
12 mmcblk0*) ROOT_DEV=mmcblk0 ;;
12 mmcblk0*) ROOT_DEV=mmcblk0 ;;
13 sda*) ROOT_DEV=sda ;;
13 sda*) ROOT_DEV=sda ;;
14 esac
14 esac
15
15
16 # Check detected root partition name
16 # Check detected root partition name
17 PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
17 PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
18 if [ "$PART_NUM" = "$ROOT_PART" ] ; then
18 if [ "$PART_NUM" = "$ROOT_PART" ] ; then
19 logger -t "rc.firstboot" "$ROOT_PART is not an SD card. Don't know how to expand"
19 logger -t "rc.firstboot" "$ROOT_PART is not an SD card. Don't know how to expand"
20 return 0
20 return 0
21 fi
21 fi
22
22
23 # NOTE: the NOOBS partition layout confuses parted. For now, let's only
23 # NOTE: the NOOBS partition layout confuses parted. For now, let's only
24 # agree to work with a sufficiently simple partition layout
24 # agree to work with a sufficiently simple partition layout
25 if [ "$PART_NUM" -gt 2 ] ; then
25 if [ "$PART_NUM" -gt 2 ] ; then
26 logger -t "rc.firstboot" "Your partition layout is not currently supported by this tool."
26 logger -t "rc.firstboot" "Your partition layout is not currently supported by this tool."
27 return 0
27 return 0
28 fi
28 fi
29
29
30 # Check if last partition number
30 # Check if last partition number
31 LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
31 LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
32 if [ $LAST_PART_NUM -ne $PART_NUM ]; then
32 if [ $LAST_PART_NUM -ne $PART_NUM ]; then
33 logger -t "rc.firstboot" "$ROOT_PART is not the last partition. Don't know how to expand"
33 logger -t "rc.firstboot" "$ROOT_PART is not the last partition. Don't know how to expand"
34 return 0
34 return 0
35 fi
35 fi
36
36
37 # Get the starting offset of the root partition
37 # Get the starting offset of the root partition
38 PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
38 PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
39 if [ -z "$PART_START" ] ; then
39 if [ -z "$PART_START" ] ; then
40 logger -t "rc.firstboot" "${ROOT_DEV} unable to get starting sector of the partition"
40 logger -t "rc.firstboot" "${ROOT_DEV} unable to get starting sector of the partition"
41 return 1
41 return 1
42 fi
42 fi
43
43
44 # Get the possible last sector for the root partition
44 # Get the possible last sector for the root partition
45 PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
45 PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
46 if [ -z "$PART_LAST" ] ; then
46 if [ -z "$PART_LAST" ] ; then
47 logger -t "rc.firstboot" "${ROOT_DEV} unable to get last sector of the partition"
47 logger -t "rc.firstboot" "${ROOT_DEV} unable to get last sector of the partition"
48 return 1
48 return 1
49 fi
49 fi
50
50
51 ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
51 ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
52 fdisk /dev/${ROOT_DEV} <<EOF2 || true
52 fdisk /dev/${ROOT_DEV} <<EOF2 || true
53 p
53 p
54 d
54 d
55 $PART_NUM
55 $PART_NUM
56 n
56 n
57 p
57 p
58 $PART_NUM
58 $PART_NUM
59 $PART_START
59 $PART_START
60 $PART_LAST
60 $PART_LAST
61 p
61 p
62 w
62 w
63 EOF2
63 EOF2
64
64
65 # Reload the partition table, resize root filesystem then remove resizing code from this file
65 # Reload the partition table, resize root filesystem then remove resizing code from this file
66 partprobe &&
66 partprobe &&
67 resize2fs /dev/${ROOT_PART} &&
67 resize2fs /dev/${ROOT_PART} &&
68 logger -t "rc.firstboot" "Root partition successfully resized."
68 logger -t "rc.firstboot" "Root partition successfully resized."
69
70 # Restart dphys-swapfile service if it exists
71 if systemctl list-units | grep -q dphys-swapfile ; then
72 if systemctl is-enabled dphys-swapfile ; then
73 logger -t "rc.firstboot" "Restarting dphys-swapfile"
74 systemctl restart dphys-swapfile
75 fi
76 fi
1 NO CONTENT: file renamed from files/firstboot/33-regenerate-initramfs.sh to files/firstboot/21-regenerate-initramfs.sh
NO CONTENT: file renamed from files/firstboot/33-regenerate-initramfs.sh to files/firstboot/21-regenerate-initramfs.sh
@@ -1,5 +1,7
1 logger -t "rc.firstboot" "Restarting dphys-swapfile"
1 # Restart dphys-swapfile service if it exists
2 if systemctl list-units | grep -q dphys-swapfile ; then
3 logger -t "rc.firstboot" "Restarting dphys-swapfile"
2
4
3 if systemctl is-enabled dphys-swapfile ; then
5 systemctl enable dphys-swapfile
4 systemctl restart dphys-swapfile
6 systemctl restart dphys-swapfile
5 fi
7 fi
1 NO CONTENT: file renamed from files/firstboot/20-generate-ssh-keys.sh to files/firstboot/30-generate-ssh-keys.sh
NO CONTENT: file renamed from files/firstboot/20-generate-ssh-keys.sh to files/firstboot/30-generate-ssh-keys.sh
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant