@@ -24,8 +24,25 @@ _trap_push true
24
24
set -e
25
25
cd $( dirname $0 )
26
26
27
+ if [ -d " /etc/sonic" ]; then
28
+ echo " Installing SONiC in SONiC"
29
+ install_env=" sonic"
30
+ elif grep -Fxqs " DISTRIB_ID=onie" /etc/lsb-release > /dev/null
31
+ then
32
+ echo " Installing SONiC in ONIE"
33
+ install_env=" onie"
34
+ else
35
+ echo " Installing SONiC in BUILD"
36
+ install_env=" build"
37
+ fi
38
+
39
+ if [ -r ./machine.conf ]; then
27
40
. ./machine.conf
41
+ fi
42
+
43
+ if [ -r ./onie-image.conf ]; then
28
44
. ./onie-image.conf
45
+ fi
29
46
30
47
echo " ONIE Installer: platform: $platform "
31
48
@@ -40,7 +57,7 @@ if [ -r /etc/machine.conf ]; then
40
57
. /etc/machine.conf
41
58
elif [ -r /host/machine.conf ]; then
42
59
. /host/machine.conf
43
- else
60
+ elif [ " $install_env " != " build " ] ; then
44
61
echo " cannot find machine.conf"
45
62
exit 1
46
63
fi
@@ -58,26 +75,20 @@ ONIE_PLATFORM_EXTRA_CMDLINE_LINUX=""
58
75
# Default var/log device size in MB
59
76
VAR_LOG_SIZE=4096
60
77
61
- if [ -d " /etc/sonic" ]; then
62
- echo " Installing SONiC in SONiC"
63
- install_env=" sonic"
64
- else
65
- echo " Installing SONiC in ONIE"
66
- install_env=" onie"
67
- fi
68
-
69
78
[ -r platforms/$onie_platform ] && . platforms/$onie_platform
70
79
71
80
# Install demo on same block device as ONIE
72
- onie_dev=$( blkid | grep ONIE-BOOT | head -n 1 | awk ' {print $1}' | sed -e ' s/:.*$//' )
73
- blk_dev=$( echo $onie_dev | sed -e ' s/[1-9][0-9]*$//' | sed -e ' s/\([0-9]\)\(p\)/\1/' )
74
- # Note: ONIE has no mount setting for / with device node, so below will be empty string
75
- cur_part=$( cat /proc/mounts | awk " { if(\$ 2==\" /\" ) print \$ 1 }" | grep $blk_dev || true)
76
-
77
- [ -b " $blk_dev " ] || {
78
- echo " Error: Unable to determine block device of ONIE install"
79
- exit 1
80
- }
81
+ if [ " $install_env " != " build" ]; then
82
+ onie_dev=$( blkid | grep ONIE-BOOT | head -n 1 | awk ' {print $1}' | sed -e ' s/:.*$//' )
83
+ blk_dev=$( echo $onie_dev | sed -e ' s/[1-9][0-9]*$//' | sed -e ' s/\([0-9]\)\(p\)/\1/' )
84
+ # Note: ONIE has no mount setting for / with device node, so below will be empty string
85
+ cur_part=$( cat /proc/mounts | awk " { if(\$ 2==\" /\" ) print \$ 1 }" | grep $blk_dev || true)
86
+
87
+ [ -b " $blk_dev " ] || {
88
+ echo " Error: Unable to determine block device of ONIE install"
89
+ exit 1
90
+ }
91
+ fi
81
92
82
93
# If running in ONIE
83
94
if [ " $install_env " = " onie" ]; then
108
119
firmware=" bios"
109
120
fi
110
121
111
- if [ " $install_env " ! = " sonic " ]; then
122
+ if [ " $install_env " = " onie " ]; then
112
123
# determine ONIE partition type
113
124
onie_partition_type=$( ${onie_bin} onie-sysinfo -t)
114
125
# demo partition size in MB
@@ -310,6 +321,7 @@ demo_install_grub()
310
321
cat $grub_install_log && rm -f $grub_install_log
311
322
exit 1
312
323
}
324
+
313
325
rm -f $grub_install_log
314
326
315
327
# restore immutable flag on the core.img file as discussed
@@ -374,7 +386,7 @@ demo_install_uefi_grub()
374
386
375
387
image_dir=" image-$image_version "
376
388
377
- if [ " $install_env " ! = " sonic " ]; then
389
+ if [ " $install_env " = " onie " ]; then
378
390
eval $create_demo_partition $blk_dev
379
391
demo_dev=$( echo $blk_dev | sed -e ' s/\(mmcblk[0-9]\)/\1p/' ) $demo_part
380
392
@@ -391,7 +403,8 @@ if [ "$install_env" != "sonic" ]; then
391
403
echo " Error: Unable to mount $demo_dev on $demo_mnt "
392
404
exit 1
393
405
}
394
- else
406
+
407
+ elif [ " $install_env " = " sonic" ]; then
395
408
demo_mnt=" /host"
396
409
running_sonic_revision=$( cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" " )
397
410
# Prevent installing existing SONiC if it is running
@@ -406,6 +419,15 @@ else
406
419
rm -rf $f
407
420
fi
408
421
done
422
+ else
423
+ demo_mnt=" build_raw_image_mnt"
424
+ demo_dev=$cur_wd /" %%OUTPUT_RAW_IMAGE%%"
425
+
426
+ mkfs.ext4 $demo_dev
427
+
428
+ echo " Mounting $demo_dev on $demo_mnt ..."
429
+ mkdir $demo_mnt
430
+ mount -t auto -o loop $demo_dev $demo_mnt
409
431
fi
410
432
411
433
echo " Installing SONiC to $demo_mnt /$image_dir "
@@ -446,7 +468,7 @@ if [ "$VAR_LOG_SIZE" != "0" ]; then
446
468
mkfs.ext4 -q $demo_mnt /disk-img/var-log.ext4 -F
447
469
fi
448
470
449
- if [ " $install_env " ! = " sonic " ]; then
471
+ if [ " $install_env " = " onie " ]; then
450
472
# Store machine description in target file system
451
473
cp /etc/machine.conf $demo_mnt
452
474
@@ -547,7 +569,7 @@ menuentry '$demo_grub_entry' {
547
569
}
548
570
EOF
549
571
550
- if [ " $install_env " ! = " sonic " ]; then
572
+ if [ " $install_env " = " onie " ]; then
551
573
# Add menu entries for ONIE -- use the grub fragment provided by the
552
574
# ONIE distribution.
553
575
$onie_root_dir /grub.d/50_onie_grub >> $grub_cfg
@@ -559,7 +581,11 @@ $onie_menuentry
559
581
EOF
560
582
fi
561
583
562
- cp $grub_cfg $onie_initrd_tmp /$demo_mnt /grub/grub.cfg
584
+ if [ " $install_env " = " build" ]; then
585
+ umount $demo_mnt
586
+ else
587
+ cp $grub_cfg $onie_initrd_tmp /$demo_mnt /grub/grub.cfg
588
+ fi
563
589
564
590
cd /
565
591
0 commit comments