@@ -13,19 +13,18 @@ REBOOT_METHOD="/sbin/kexec -e"
13
13
ASSISTANT_IP_LIST=" "
14
14
ASSISTANT_SCRIPT=" /usr/bin/neighbor_advertiser"
15
15
16
+ # Require 100M available on the hard drive for warm reboot temp files,
17
+ # Size is in 1K blocks:
18
+ MIN_HD_SPACE_NEEDED=100000
19
+
16
20
EXIT_SUCCESS=0
17
21
EXIT_FAILURE=1
18
22
EXIT_NOT_SUPPORTED=2
23
+ EXIT_FILE_SYSTEM_FULL=3
24
+ EXIT_NEXT_IMAGE_NOT_EXISTS=4
19
25
EXIT_ORCHAGENT_SHUTDOWN=10
20
26
EXIT_SYNCD_SHUTDOWN=11
21
27
22
- # Check root privileges
23
- if [[ " $EUID " -ne 0 ]]
24
- then
25
- echo " This command must be run as root" >&2
26
- exit " ${EXIT_FAILURE} "
27
- fi
28
-
29
28
function error()
30
29
{
31
30
echo $@ >&2
@@ -82,8 +81,6 @@ function parseOptions()
82
81
done
83
82
}
84
83
85
- sonic_asic_type=$( sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
86
-
87
84
function clear_fast_boot()
88
85
{
89
86
debug " ${REBOOT_TYPE} failure ($? ) cleanup ..."
@@ -212,8 +209,60 @@ function teardown_control_plane_assistant()
212
209
fi
213
210
}
214
211
212
+ function setup_reboot_variables()
213
+ {
214
+ # Kernel and initrd image
215
+ NEXT_SONIC_IMAGE=$( sonic_installer list | grep " Next: " | cut -d ' ' -f 2)
216
+ IMAGE_PATH=" /host/image-${NEXT_SONIC_IMAGE# SONiC-OS-} "
217
+ if grep -q aboot_platform= /host/machine.conf; then
218
+ KERNEL_IMAGE=" $( ls $IMAGE_PATH /boot/vmlinuz-* ) "
219
+ BOOT_OPTIONS=" $( cat " $IMAGE_PATH /kernel-cmdline" | tr ' \n' ' ' ) SONIC_BOOT_TYPE=${BOOT_TYPE_ARG} "
220
+ elif grep -q onie_platform= /host/machine.conf; then
221
+ KERNEL_OPTIONS=$( cat /host/grub/grub.cfg | sed " /$NEXT_SONIC_IMAGE '/,/}/" ' !' " g" | grep linux)
222
+ KERNEL_IMAGE=" /host$( echo $KERNEL_OPTIONS | cut -d ' ' -f 2) "
223
+ BOOT_OPTIONS=" $( echo $KERNEL_OPTIONS | sed -e ' s/\s*linux\s*/BOOT_IMAGE=/' ) SONIC_BOOT_TYPE=${BOOT_TYPE_ARG} "
224
+ else
225
+ error " Unknown bootloader. ${REBOOT_TYPE} is not supported."
226
+ exit " ${EXIT_NOT_SUPPORTED} "
227
+ fi
228
+ INITRD=$( echo $KERNEL_IMAGE | sed ' s/vmlinuz/initrd.img/g' )
229
+ }
230
+
231
+ function reboot_pre_check()
232
+ {
233
+ # Make sure that the file system is normal: read-write able
234
+ filename=" /host/test-` date +%Y%m%d-%H%M%S` "
235
+ if [[ ! -f ${filename} ]]; then
236
+ touch ${filename}
237
+ fi
238
+ rm ${filename}
239
+
240
+ # Make sure /host has enough space for warm reboot temp files
241
+ avail=$( df -k /host | tail -1 | awk ' { print $4 }' )
242
+ if [[ ${avail} -lt ${MIN_HD_SPACE_NEEDED} ]]; then
243
+ debug " /host has ${avail} K bytes available, not enough for warm reboot."
244
+ exit ${EXIT_FILE_SYSTEM_FULL}
245
+ fi
246
+
247
+ # Make sure that the next image exists
248
+ if [[ ! -d ${IMAGE_PATH} ]]; then
249
+ debug " Next image ${NEXT_SONIC_IMAGE} doesn't exist ..."
250
+ exit ${EXIT_NEXT_IMAGE_NOT_EXISTS}
251
+ fi
252
+ }
253
+
254
+ # main starts here
215
255
parseOptions $@
216
256
257
+ # Check root privileges
258
+ if [[ " $EUID " -ne 0 ]]
259
+ then
260
+ echo " This command must be run as root" >&2
261
+ exit " ${EXIT_FAILURE} "
262
+ fi
263
+
264
+ sonic_asic_type=$( sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
265
+
217
266
# Check reboot type supported
218
267
BOOT_TYPE_ARG=" cold"
219
268
case " $REBOOT_TYPE " in
@@ -249,21 +298,9 @@ then
249
298
/sbin/kexec -u
250
299
fi
251
300
252
- # Kernel and initrd image
253
- NEXT_SONIC_IMAGE=$( sonic_installer list | grep " Next: " | cut -d ' ' -f 2)
254
- if grep -q aboot_platform= /host/machine.conf; then
255
- IMAGE_PATH=" /host/image-${NEXT_SONIC_IMAGE# SONiC-OS-} "
256
- KERNEL_IMAGE=" $( ls $IMAGE_PATH /boot/vmlinuz-* ) "
257
- BOOT_OPTIONS=" $( cat " $IMAGE_PATH /kernel-cmdline" | tr ' \n' ' ' ) SONIC_BOOT_TYPE=${BOOT_TYPE_ARG} "
258
- elif grep -q onie_platform= /host/machine.conf; then
259
- KERNEL_OPTIONS=$( cat /host/grub/grub.cfg | sed " /$NEXT_SONIC_IMAGE '/,/}/" ' !' " g" | grep linux)
260
- KERNEL_IMAGE=" /host$( echo $KERNEL_OPTIONS | cut -d ' ' -f 2) "
261
- BOOT_OPTIONS=" $( echo $KERNEL_OPTIONS | sed -e ' s/\s*linux\s*/BOOT_IMAGE=/' ) SONIC_BOOT_TYPE=${BOOT_TYPE_ARG} "
262
- else
263
- error " Unknown bootloader. ${REBOOT_TYPE} is not supported."
264
- exit " ${EXIT_NOT_SUPPORTED} "
265
- fi
266
- INITRD=$( echo $KERNEL_IMAGE | sed ' s/vmlinuz/initrd.img/g' )
301
+ setup_reboot_variables
302
+
303
+ reboot_pre_check
267
304
268
305
# Install new FW for mellanox platforms before control plane goes down
269
306
# So on boot switch will not spend time to upgrade FW increasing the CP downtime
0 commit comments