@@ -29,13 +29,34 @@ if [ ! -e /host/machine.conf ]; then
29
29
done
30
30
fi
31
31
32
+ migration=" TRUE"
32
33
umount /mnt/onie-boot
33
34
fi
34
35
35
36
. /host/machine.conf
36
37
37
38
echo " install platform dependent packages at the first boot time"
38
39
40
+ firsttime_exit ()
41
+ {
42
+ rm /host/image-$sonic_version /platform/firsttime
43
+ exit 0
44
+ }
45
+
46
+ # Given a string of tuples of the form field=value, extract the value for a field
47
+ # In : $string, $field
48
+ # Out: $value
49
+ value_extract ()
50
+ {
51
+ set -- $string
52
+ for x in " $@ " ; do
53
+ case " $x " in
54
+ $field =* )
55
+ value=" ${x# $field =} "
56
+ esac
57
+ done
58
+ }
59
+
39
60
sonic_version=$( cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" " )
40
61
41
62
if [ -f /host/image-$sonic_version /platform/firsttime ]; then
@@ -46,8 +67,7 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then
46
67
platform=$onie_platform
47
68
else
48
69
echo " Unknown sonic platform"
49
- rm /host/image-$sonic_version /platform/firsttime
50
- exit 0
70
+ firsttime_exit
51
71
fi
52
72
53
73
# Try to take old configuration saved during installation
@@ -76,6 +96,88 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then
76
96
dpkg -i /host/image-$sonic_version /platform/$platform /* .deb
77
97
fi
78
98
99
+ # If the unit booted into SONiC from another NOS's grub,
100
+ # we now install a grub for SONiC.
101
+ if [ -n " $onie_platform " ] && [ -n " $migration " ]; then
102
+
103
+ grub_bin=$( ls /host/image-$sonic_version /platform/x86_64-grub/grub-pc-bin* .deb 2> /dev/null)
104
+ if [ -z " $grub_bin " ]; then
105
+ echo " Unable to locate grub package !" >> /etc/migration.log
106
+ firsttime_exit
107
+ fi
108
+
109
+ dpkg -i $grub_bin > /dev/null 2>&1
110
+ if [ $? != 0 ]; then
111
+ echo " Unable to install grub package !" >> /etc/migration.log
112
+ firsttime_exit
113
+ fi
114
+
115
+ # Determine the block device to install grub
116
+ sonic_dev=$( blkid | grep SONiC-OS | head -n 1 | awk ' {print $1}' | sed -e ' s/[0-9]:.*$//' )
117
+ if [ -z " $sonic_dev " ]; then
118
+ echo " Unable to determine sonic partition !" >> /etc/migration.log
119
+ firsttime_exit
120
+ fi
121
+
122
+ grub-install --boot-directory=/host --recheck $sonic_dev 2> /dev/null
123
+ if [ $? != 0 ]; then
124
+ echo " grub install failed !" >> /etc/migration.log
125
+ firsttime_exit
126
+ fi
127
+
128
+ # The SONiC "raw" build mode has already generated a proto grub.cfg
129
+ # as part of the migration. Platform specific constants need to be
130
+ # retrieved from installer.conf (if present) and assigned.
131
+ . /usr/share/sonic/device/$platform /installer.conf
132
+
133
+ if [ ! -z " $CONSOLE_PORT " ]; then
134
+ field=" \-\-port"
135
+ string=$( grep $field /host/grub.cfg)
136
+ value_extract $string $field
137
+ console_port=$value
138
+ if [ ! -z " $console_port " ] && [ " $console_port " != " $CONSOLE_PORT " ]; then
139
+ sed -i -e " s/\-\-port=$console_port /\-\-port=$CONSOLE_PORT /g" /host/grub.cfg
140
+ fi
141
+ echo " grub.cfg console port=$console_port & installer.conf CONSOLE_PORT=$CONSOLE_PORT " >> /etc/migration.log
142
+ fi
143
+
144
+ if [ ! -z " $CONSOLE_DEV " ]; then
145
+ field=" console"
146
+ string=$( grep $field /host/grub.cfg)
147
+ value_extract $string $field
148
+ console_dev_name=$( echo $value | sed -e " s/^.*=//" -e " s/,.*//" )
149
+ console_dev=" ${console_dev_name# ttyS} "
150
+ if [ " $console_dev " != " $CONSOLE_DEV " ]; then
151
+ sed -i -e " s/console=ttyS$console_dev /console=ttyS$CONSOLE_DEV /g" /host/grub.cfg
152
+ fi
153
+ echo " grub.cfg console dev=$console_dev & installer.conf CONSOLE_DEV=$CONSOLE_DEV " >> /etc/migration.log
154
+ fi
155
+
156
+ if [ ! -z " $VAR_LOG_SIZE " ]; then
157
+ field=" var_log_size"
158
+ string=$( grep $field /host/grub.cfg)
159
+ value_extract $string $field
160
+ var_log_size=$value
161
+ if [ ! -z " $var_log_size " ] && [ " $var_log_size " != " $VAR_LOG_SIZE " ]; then
162
+ sed -i -e " s/var_log_size=$var_log_size /var_log_size=$VAR_LOG_SIZE /g" /host/grub.cfg
163
+ fi
164
+ echo " grub.cfg var_log_size=$var_log_size & installer.conf VAR_LOG_SIZE=$VAR_LOG_SIZE " >> /etc/migration.log
165
+ fi
166
+
167
+ # Set the root based on the label
168
+ sonic_root=$( blkid | grep SONiC-OS | head -n 1 | awk ' {print $1}' | sed -e ' s/:.*$//' )
169
+ sonic_root=$( echo " $sonic_root " | sed ' s/\//\\\//g' )
170
+ sed -i -e " s/%%SONIC_ROOT%%/$sonic_root /g" /host/grub.cfg
171
+
172
+ # Add the Diag and ONIE entries
173
+ mount $onie_dev /mnt/onie-boot
174
+ . /mnt/onie-boot/onie/grub.d/50_onie_grub >> /host/grub.cfg
175
+ umount /mnt/onie-boot
176
+
177
+ # Initialize the SONiC's grub config
178
+ mv /host/grub.cfg /host/grub/grub.cfg
179
+ fi
180
+
79
181
rm /host/image-$sonic_version /platform/firsttime
80
182
fi
81
183
0 commit comments