e069c520ac
#### Why I did it Fix the build failure caused by the installer image size too small. The installer image is only used during the build, not impact the final images. See https://dev.azure.com/mssonic/build/_build/results?buildId=139926&view=logs&j=cef3d8a9-152e-5193-620b-567dc18af272&t=359769c4-8b5e-5976-a793-85da132e0a6f ``` + fallocate -l 2048M ./sonic-installer.img + mkfs.vfat ./sonic-installer.img mkfs.fat 4.2 (2021-01-31) ++ mktemp -d + tmpdir=/tmp/tmp.TqdDSc00Cn + mount -o loop ./sonic-installer.img /tmp/tmp.TqdDSc00Cn + cp target/sonic-vs.bin /tmp/tmp.TqdDSc00Cn/onie-installer.bin cp: error writing '/tmp/tmp.TqdDSc00Cn/onie-installer.bin': No space left on device [ FAIL LOG END ] [ target/sonic-vs.img.gz ] ``` #### How I did it Increase the size from 2048M to 4096M. Why not increase to 16G like qcow2 image? The qcow2 supports the sparse disk, although a big disk size allocated, but it will not consume the real disk size. The falocate does not support the sparse disk. We do not want to allocate a very big disk, but no use at all. It will require more space to build.
132 lines
2.5 KiB
Bash
Executable File
132 lines
2.5 KiB
Bash
Executable File
#!/bin/bash -ex
|
|
|
|
# Copyright (C) 2014 Curt Brune <curt@cumulusnetworks.com>
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
MEM=8192
|
|
DISK=$1
|
|
ONIE_RECOVERY_ISO=$2
|
|
INSTALLER=$3
|
|
DISK_SIZE=$4
|
|
|
|
INSTALLER_DISK="./sonic-installer.img"
|
|
|
|
# VM will listen on telnet port $KVM_PORT
|
|
KVM_PORT=9000
|
|
|
|
on_exit()
|
|
{
|
|
rm -f $kvm_log
|
|
}
|
|
|
|
on_error()
|
|
{
|
|
netstat -antp
|
|
ps aux
|
|
echo "============= kvm_log =============="
|
|
cat $kvm_log
|
|
}
|
|
|
|
create_disk()
|
|
{
|
|
echo "Creating SONiC kvm disk : $DISK of size $DISK_SIZE GB"
|
|
qemu-img create -f qcow2 $DISK ${DISK_SIZE}G
|
|
}
|
|
|
|
prepare_installer_disk()
|
|
{
|
|
fallocate -l 4096M $INSTALLER_DISK
|
|
|
|
mkfs.vfat $INSTALLER_DISK
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
mount -o loop $INSTALLER_DISK $tmpdir
|
|
|
|
cp $INSTALLER $tmpdir/onie-installer.bin
|
|
|
|
umount $tmpdir
|
|
}
|
|
|
|
apt-get install -y net-tools
|
|
create_disk
|
|
prepare_installer_disk
|
|
|
|
echo "Prepare memory for KVM build: $vs_build_prepare_mem"
|
|
mount proc /proc -t proc || true
|
|
free -m
|
|
if [[ "$vs_build_prepare_mem" == "yes" ]]; then
|
|
# Force o.s. to drop cache and compact memory so that KVM can get 2G memory
|
|
bash -c 'echo 1 > /proc/sys/vm/drop_caches'
|
|
# Not all kernels support compact_memory
|
|
if [[ -w '/proc/sys/vm/compact_memory' ]]
|
|
then
|
|
bash -c 'echo 1 > /proc/sys/vm/compact_memory'
|
|
fi
|
|
free -m
|
|
fi
|
|
|
|
kvm_log=$(mktemp)
|
|
trap on_exit EXIT
|
|
trap on_error ERR
|
|
|
|
echo "Installing SONiC"
|
|
|
|
/usr/bin/kvm -m $MEM \
|
|
-name "onie" \
|
|
-boot "order=cd,once=d" -cdrom "$ONIE_RECOVERY_ISO" \
|
|
-device e1000,netdev=onienet \
|
|
-netdev user,id=onienet,hostfwd=:0.0.0.0:3041-:22 \
|
|
-vnc 0.0.0.0:0 \
|
|
-vga std \
|
|
-drive file=$DISK,media=disk,if=virtio,index=0 \
|
|
-drive file=$INSTALLER_DISK,if=virtio,index=1 \
|
|
-serial telnet:127.0.0.1:$KVM_PORT,server > $kvm_log 2>&1 &
|
|
|
|
kvm_pid=$!
|
|
|
|
sleep 2.0
|
|
|
|
[ -d "/proc/$kvm_pid" ] || {
|
|
echo "ERROR: kvm died."
|
|
cat $kvm_log
|
|
exit 1
|
|
}
|
|
|
|
echo "to kill kvm: sudo kill $kvm_pid"
|
|
|
|
./install_sonic.py
|
|
|
|
kill $kvm_pid
|
|
|
|
echo "Booting up SONiC"
|
|
|
|
/usr/bin/kvm -m $MEM \
|
|
-name "onie" \
|
|
-device e1000,netdev=onienet \
|
|
-netdev user,id=onienet,hostfwd=:0.0.0.0:3041-:22 \
|
|
-vnc 0.0.0.0:0 \
|
|
-vga std \
|
|
-snapshot \
|
|
-drive file=$DISK,media=disk,if=virtio,index=0 \
|
|
-serial telnet:127.0.0.1:$KVM_PORT,server > $kvm_log 2>&1 &
|
|
|
|
kvm_pid=$!
|
|
|
|
sleep 2.0
|
|
|
|
[ -d "/proc/$kvm_pid" ] || {
|
|
echo "ERROR: kvm died."
|
|
cat $kvm_log
|
|
exit 1
|
|
}
|
|
|
|
echo "to kill kvm: sudo kill $kvm_pid"
|
|
|
|
./check_install.py -u $SONIC_USERNAME -P $PASSWD -p $KVM_PORT
|
|
|
|
kill $kvm_pid
|
|
|
|
exit 0
|