@@ -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)
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
+ fi
76
87
77
- [ -b " $blk_dev " ] || {
88
+ if [ " $install_env " != " build " ] && [ ! -b " $blk_dev " ]; then
78
89
echo " Error: Unable to determine block device of ONIE install"
79
90
exit 1
80
- }
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,20 @@ else
406
419
rm -rf $f
407
420
fi
408
421
done
422
+ else
423
+ TARGET_MACHINE=` grep machine ./machine.conf | cut -d ' =' -f 2`
424
+ demo_mnt=" build_dd_image_mnt"
425
+
426
+ # remove older partition dump
427
+ rm -f /tmp/sonic-${TARGET_MACHINE} _8GB_dd.img.gz
428
+
429
+ echo " Creating sonic-${TARGET_MACHINE} _8GB_dd.img..."
430
+ fallocate -l 8G /tmp/sonic-${TARGET_MACHINE} _8GB_dd.img
431
+ mkfs.ext4 /tmp/sonic-${TARGET_MACHINE} _8GB_dd.img
432
+
433
+ echo " Mounting /tmp/sonic-${TARGET_MACHINE} _8GB_dd.img on $demo_mnt ..."
434
+ mkdir $demo_mnt
435
+ mount -t auto -o loop /tmp/sonic-${TARGET_MACHINE} _8GB_dd.img $demo_mnt
409
436
fi
410
437
411
438
echo " Installing SONiC to $demo_mnt /$image_dir "
424
451
# Decompress the file for the file system directly to the partition
425
452
unzip -o $ONIE_INSTALLER_PAYLOAD -x " $FILESYSTEM_DOCKERFS " -d $demo_mnt /$image_dir
426
453
454
+ # Indicate that this filesystem is being generated using the installer on the build server
455
+ # to facilitate migration from a 3rd party OS into SONiC
456
+ if [ " $install_env " = " build" ]; then
457
+ touch $demo_mnt /$image_dir /platform/migration
458
+ fi
459
+
427
460
TAR_EXTRA_OPTION=" --numeric-owner"
428
461
mkdir -p $demo_mnt /$image_dir /$DOCKERFS_DIR
429
462
unzip -op $ONIE_INSTALLER_PAYLOAD " $FILESYSTEM_DOCKERFS " | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt /$image_dir /$DOCKERFS_DIR
@@ -446,7 +479,7 @@ if [ "$VAR_LOG_SIZE" != "0" ]; then
446
479
mkfs.ext4 -q $demo_mnt /disk-img/var-log.ext4 -F
447
480
fi
448
481
449
- if [ " $install_env " ! = " sonic " ]; then
482
+ if [ " $install_env " = " onie " ]; then
450
483
# Store machine description in target file system
451
484
cp /etc/machine.conf $demo_mnt
452
485
471
504
grub_cfg=$( mktemp)
472
505
trap_push " rm $grub_cfg || true"
473
506
507
+ # These parameters will be initialized post migration
508
+ if [ " $install_env " = " build" ]; then
509
+ CONSOLE_PORT=" CONSOLE_PORT"
510
+ CONSOLE_DEV=" CONSOLE_DEV"
511
+ CONSOLE_SPEED=" CONSOLE_SPEED"
512
+ demo_dev=" ROOT_DEV"
513
+ fi
514
+
474
515
# Set a few GRUB_xxx environment variables that will be picked up and
475
516
# used by the 50_onie_grub script. This is similiar to what an OS
476
517
# would specify in /etc/default/grub.
@@ -547,7 +588,7 @@ menuentry '$demo_grub_entry' {
547
588
}
548
589
EOF
549
590
550
- if [ " $install_env " ! = " sonic " ]; then
591
+ if [ " $install_env " = " onie " ]; then
551
592
# Add menu entries for ONIE -- use the grub fragment provided by the
552
593
# ONIE distribution.
553
594
$onie_root_dir /grub.d/50_onie_grub >> $grub_cfg
@@ -559,7 +600,13 @@ $onie_menuentry
559
600
EOF
560
601
fi
561
602
562
- cp $grub_cfg $onie_initrd_tmp /$demo_mnt /grub/grub.cfg
603
+ if [ " $install_env " = " build" ]; then
604
+ cp $grub_cfg $demo_mnt /$image_dir /platform/grub.cfg.migration
605
+ gzip /tmp/sonic-${TARGET_MACHINE} _8GB_dd.img
606
+ umount $demo_mnt
607
+ else
608
+ cp $grub_cfg $onie_initrd_tmp /$demo_mnt /grub/grub.cfg
609
+ fi
563
610
564
611
cd /
565
612
0 commit comments