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