2016-03-08 13:42:20 -06:00
|
|
|
#!/bin/bash
|
|
|
|
## This script is to automate the preparation for a debian file system, which will be used for
|
|
|
|
## an ONIE installer image.
|
|
|
|
##
|
|
|
|
## USAGE:
|
|
|
|
## ./build_debian USERNAME PASSWORD_ENCRYPTED
|
|
|
|
## PARAMETERS:
|
|
|
|
## USERNAME
|
|
|
|
## The name of the default admin user
|
|
|
|
## PASSWORD_ENCRYPTED
|
|
|
|
## The encrypted password, expected by chpasswd command
|
|
|
|
|
|
|
|
## Default user
|
|
|
|
USERNAME=$1
|
|
|
|
[ -n "$USERNAME" ] || {
|
|
|
|
echo "Error: no or empty USERNAME argument"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
## Password for the default user, customizable by environment variable
|
|
|
|
## By default it is an empty password
|
|
|
|
## You may get a crypted password by: perl -e 'print crypt("YourPaSsWoRd", "salt"),"\n"'
|
|
|
|
PASSWORD_ENCRYPTED=$2
|
|
|
|
[ -n "$PASSWORD_ENCRYPTED" ] || {
|
|
|
|
echo "Error: no or empty PASSWORD_ENCRYPTED argument"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
## Include common functions
|
|
|
|
. functions.sh
|
|
|
|
|
|
|
|
## Enable debug output for script
|
|
|
|
set -x -e
|
|
|
|
|
2016-07-26 14:01:58 -05:00
|
|
|
## docker engine version (with platform)
|
|
|
|
DOCKER_VERSION=1.11.1-0~jessie_amd64
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Working directory to prepare the file system
|
|
|
|
FILESYSTEM_ROOT=./fsroot
|
2017-02-27 15:08:41 -06:00
|
|
|
PLATFORM_DIR=platform
|
2016-03-08 13:42:20 -06:00
|
|
|
## Hostname for the linux image
|
2016-09-15 17:22:29 -05:00
|
|
|
HOSTNAME=sonic
|
2016-03-08 13:42:20 -06:00
|
|
|
DEFAULT_USERINFO="Default admin user,,,"
|
|
|
|
|
|
|
|
## Read ONIE image related config file
|
|
|
|
. ./onie-image.conf
|
|
|
|
[ -n "$ONIE_IMAGE_PART_SIZE" ] || {
|
|
|
|
echo "Error: Invalid ONIE_IMAGE_PART_SIZE in onie image config file"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
[ -n "$ONIE_INSTALLER_PAYLOAD" ] || {
|
|
|
|
echo "Error: Invalid ONIE_INSTALLER_PAYLOAD in onie image config file"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
[ -n "$FILESYSTEM_SQUASHFS" ] || {
|
|
|
|
echo "Error: Invalid FILESYSTEM_SQUASHFS in onie image config file"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
## Prepare the file system directory
|
|
|
|
if [[ -d $FILESYSTEM_ROOT ]]; then
|
2017-02-10 09:39:05 -06:00
|
|
|
sudo rm -rf $FILESYSTEM_ROOT || die "Failed to clean chroot directory"
|
2016-03-08 13:42:20 -06:00
|
|
|
fi
|
|
|
|
mkdir -p $FILESYSTEM_ROOT
|
2017-02-27 15:08:41 -06:00
|
|
|
mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR
|
2017-09-17 13:41:30 -05:00
|
|
|
mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/x86_64-grub
|
2017-02-27 15:08:41 -06:00
|
|
|
touch $FILESYSTEM_ROOT/$PLATFORM_DIR/firsttime
|
2016-03-08 13:42:20 -06:00
|
|
|
|
|
|
|
## Build a basic Debian system by debootstrap
|
|
|
|
echo '[INFO] Debootstrap...'
|
2018-01-04 00:22:58 -06:00
|
|
|
sudo http_proxy=$http_proxy debootstrap --variant=minbase --arch amd64 jessie $FILESYSTEM_ROOT http://debian-archive.trafficmanager.net/debian
|
2016-03-08 13:42:20 -06:00
|
|
|
|
|
|
|
## Config hostname and hosts, otherwise 'sudo ...' will complain 'sudo: unable to resolve host ...'
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "echo '$HOSTNAME' > /etc/hostname"
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "echo '127.0.0.1 $HOSTNAME' >> /etc/hosts"
|
2016-09-25 23:48:25 -05:00
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "echo '127.0.0.1 localhost' >> /etc/hosts"
|
2016-03-08 13:42:20 -06:00
|
|
|
|
|
|
|
## Config basic fstab
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c 'echo "proc /proc proc defaults 0 0" >> /etc/fstab'
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c 'echo "sysfs /sys sysfs defaults 0 0" >> /etc/fstab'
|
|
|
|
|
2017-12-24 01:34:15 -06:00
|
|
|
## Setup proxy
|
|
|
|
[ -n "$http_proxy" ] && sudo /bin/bash -c "echo 'Acquire::http::Proxy \"$http_proxy\";' > $FILESYSTEM_ROOT/etc/apt/apt.conf.d/01proxy"
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Note: mounting is necessary to makedev and install linux image
|
|
|
|
echo '[INFO] Mount all'
|
|
|
|
## Output all the mounted device for troubleshooting
|
|
|
|
mount
|
|
|
|
trap_push 'sudo umount $FILESYSTEM_ROOT/proc || true'
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT mount proc /proc -t proc
|
|
|
|
|
|
|
|
## Pointing apt to public apt mirrors and getting latest packages, needed for latest security updates
|
2016-11-08 05:04:52 -06:00
|
|
|
sudo cp files/apt/sources.list $FILESYSTEM_ROOT/etc/apt/
|
2016-11-16 14:46:15 -06:00
|
|
|
sudo cp files/apt/apt.conf.d/{81norecommends,apt-{clean,gzip-indexes,no-languages}} $FILESYSTEM_ROOT/etc/apt/apt.conf.d/
|
2016-05-27 15:30:13 -05:00
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT bash -c 'apt-mark auto `apt-mark showmanual`'
|
2016-03-08 13:42:20 -06:00
|
|
|
|
|
|
|
## Note: set lang to prevent locale warnings in your chroot
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y update
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y upgrade
|
|
|
|
echo '[INFO] Install packages for building image'
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install makedev psmisc
|
|
|
|
|
|
|
|
## Create device files
|
|
|
|
echo '[INFO] MAKEDEV'
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c 'cd /dev && MAKEDEV generic'
|
|
|
|
## Install initramfs-tools and linux kernel
|
|
|
|
## Note: initramfs-tools recommends depending on busybox, and we really want busybox for
|
|
|
|
## 1. commands such as touch
|
|
|
|
## 2. mount supports squashfs
|
|
|
|
## However, 'dpkg -i' plus 'apt-get install -f' will ignore the recommended dependency. So
|
|
|
|
## we install busybox explicitly
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install busybox
|
2016-09-06 15:15:10 -05:00
|
|
|
echo '[INFO] Install SONiC linux kernel image'
|
2016-03-08 13:42:20 -06:00
|
|
|
## Note: duplicate apt-get command to ensure every line return zero
|
2016-12-05 13:12:19 -06:00
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/initramfs-tools_*.deb || \
|
2016-03-08 13:42:20 -06:00
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
|
2018-01-31 13:39:48 -06:00
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/linux-image-3.16.0-5-amd64_*.deb || \
|
2016-03-08 13:42:20 -06:00
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
|
2016-05-27 15:30:13 -05:00
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Update initramfs for booting with squashfs+aufs
|
|
|
|
cat files/initramfs-tools/modules | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-tools/modules > /dev/null
|
|
|
|
|
2017-01-24 00:25:47 -06:00
|
|
|
## Hook into initramfs: change fs type from vfat to ext4 on arista switches
|
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/
|
|
|
|
sudo cp files/initramfs-tools/arista-convertfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs
|
|
|
|
sudo cp files/initramfs-tools/mke2fs $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs
|
2017-11-24 19:30:11 -06:00
|
|
|
sudo cp files/initramfs-tools/setfacl $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/setfacl
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/setfacl
|
2017-01-24 00:25:47 -06:00
|
|
|
|
2017-08-19 23:32:10 -05:00
|
|
|
# Hook into initramfs: rename the management interfaces on arista switches
|
|
|
|
sudo cp files/initramfs-tools/arista-net $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-net
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-net
|
|
|
|
|
2018-02-07 08:07:01 -06:00
|
|
|
# Hook into initramfs: resize root partition after migration from another NOS to SONiC on Dell switches
|
|
|
|
sudo cp files/initramfs-tools/resize-rootfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/resize-rootfs
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/resize-rootfs
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Hook into initramfs: after partition mount and loop file mount
|
|
|
|
## 1. Prepare layered file system
|
|
|
|
## 2. Bind-mount docker working directory (docker aufs cannot work over aufs rootfs)
|
|
|
|
sudo cp files/initramfs-tools/union-mount $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount
|
2017-09-06 22:07:32 -05:00
|
|
|
sudo cp files/initramfs-tools/varlog $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/varlog
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/varlog
|
2018-03-08 18:42:41 -06:00
|
|
|
# Management interface (eth0) dhcp can be optionally turned off (during a migration from another NOS to SONiC)
|
|
|
|
sudo cp files/initramfs-tools/mgmt-intf-dhcp $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/mgmt-intf-dhcp
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/mgmt-intf-dhcp
|
2016-03-08 13:42:20 -06:00
|
|
|
sudo cp files/initramfs-tools/union-fsck $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck
|
|
|
|
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck
|
|
|
|
sudo chroot $FILESYSTEM_ROOT update-initramfs -u
|
|
|
|
|
2016-12-28 21:05:09 -06:00
|
|
|
## Install latest intel igb driver
|
2018-01-31 13:39:48 -06:00
|
|
|
sudo cp target/debs/igb.ko $FILESYSTEM_ROOT/lib/modules/3.16.0-5-amd64/kernel/drivers/net/ethernet/intel/igb/igb.ko
|
2016-12-28 21:05:09 -06:00
|
|
|
|
2017-12-22 12:04:29 -06:00
|
|
|
## Install latest intel ixgbe driver
|
2018-01-31 13:39:48 -06:00
|
|
|
sudo cp target/debs/ixgbe.ko $FILESYSTEM_ROOT/lib/modules/3.16.0-5-amd64/kernel/drivers/net/ethernet/intel/ixgbe/ixgbe.ko
|
2017-12-22 12:04:29 -06:00
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Install docker
|
|
|
|
echo '[INFO] Install docker'
|
2016-07-26 14:01:58 -05:00
|
|
|
## Install apparmor utils since they're missing and apparmor is enabled in the kernel
|
|
|
|
## Otherwise Docker will fail to start
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install apparmor
|
|
|
|
docker_deb_url=https://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_${DOCKER_VERSION}.deb
|
|
|
|
docker_deb_temp=`mktemp`
|
|
|
|
trap_push "rm -f $docker_deb_temp"
|
|
|
|
wget $docker_deb_url -qO $docker_deb_temp && { \
|
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i $docker_deb_temp || \
|
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f; \
|
|
|
|
}
|
2016-08-04 12:39:33 -05:00
|
|
|
## Add docker config drop-in to select aufs, otherwise it may select other storage driver
|
2016-03-08 13:42:20 -06:00
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/
|
2016-07-26 14:01:58 -05:00
|
|
|
## Note: $_ means last argument of last command
|
2016-03-08 13:42:20 -06:00
|
|
|
sudo cp files/docker/docker.service.conf $_
|
|
|
|
|
|
|
|
## Create default user
|
|
|
|
## Note: user should be in the group with the same name, and also in sudo/docker group
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT useradd -G sudo,docker $USERNAME -c "$DEFAULT_USERINFO" -m -s /bin/bash
|
|
|
|
## Create password for the default user
|
|
|
|
echo $USERNAME:$PASSWORD_ENCRYPTED | sudo LANG=C chroot $FILESYSTEM_ROOT chpasswd -e
|
|
|
|
|
2016-03-16 01:38:26 -05:00
|
|
|
## Pre-install hardware drivers
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install \
|
|
|
|
firmware-linux-nonfree
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Pre-install the fundamental packages
|
|
|
|
## Note: gdisk is needed for sgdisk in install.sh
|
|
|
|
## Note: parted is needed for partprobe in install.sh
|
2016-07-26 14:01:58 -05:00
|
|
|
## Note: ca-certificates is needed for easy_install
|
2017-03-02 18:04:18 -06:00
|
|
|
## Note: don't install python-apt by pip, older than Debian repo one
|
2017-01-29 13:33:33 -06:00
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install \
|
2016-05-27 15:30:13 -05:00
|
|
|
file \
|
|
|
|
ifupdown \
|
|
|
|
iproute2 \
|
2017-03-20 23:39:09 -05:00
|
|
|
bridge-utils \
|
2016-05-27 15:30:13 -05:00
|
|
|
isc-dhcp-client \
|
2016-03-08 13:42:20 -06:00
|
|
|
sudo \
|
|
|
|
vim \
|
|
|
|
tcpdump \
|
2017-06-15 12:31:13 -05:00
|
|
|
dbus \
|
2016-03-08 13:42:20 -06:00
|
|
|
ntp \
|
2016-05-27 15:30:13 -05:00
|
|
|
ntpstat \
|
2016-03-08 13:42:20 -06:00
|
|
|
openssh-server \
|
|
|
|
python \
|
|
|
|
python-setuptools \
|
2016-05-27 15:30:13 -05:00
|
|
|
rsyslog \
|
2017-05-18 12:57:19 -05:00
|
|
|
monit \
|
2016-03-08 13:42:20 -06:00
|
|
|
python-apt \
|
2016-05-27 15:30:13 -05:00
|
|
|
traceroute \
|
|
|
|
iputils-ping \
|
|
|
|
net-tools \
|
2016-07-26 14:01:58 -05:00
|
|
|
bsdmainutils \
|
|
|
|
ca-certificates \
|
|
|
|
i2c-tools \
|
2016-10-18 13:22:29 -05:00
|
|
|
efibootmgr \
|
|
|
|
usbutils \
|
2017-01-29 13:33:33 -06:00
|
|
|
pciutils \
|
|
|
|
iptables-persistent \
|
2017-02-17 15:47:01 -06:00
|
|
|
logrotate \
|
2017-03-15 20:38:55 -05:00
|
|
|
curl \
|
2017-04-21 19:23:36 -05:00
|
|
|
kexec-tools \
|
2017-05-11 20:46:11 -05:00
|
|
|
less \
|
2017-09-17 13:41:30 -05:00
|
|
|
unzip \
|
2017-10-05 23:43:25 -05:00
|
|
|
gdisk \
|
2018-01-10 05:04:32 -06:00
|
|
|
sysfsutils \
|
2018-03-08 18:42:41 -06:00
|
|
|
grub2-common \
|
|
|
|
ethtool
|
2017-09-17 13:41:30 -05:00
|
|
|
|
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y download \
|
|
|
|
grub-pc-bin
|
|
|
|
|
|
|
|
sudo mv $FILESYSTEM_ROOT/grub-pc-bin*.deb $FILESYSTEM_ROOT/$PLATFORM_DIR/x86_64-grub
|
2017-03-15 20:38:55 -05:00
|
|
|
|
2018-02-08 19:43:52 -06:00
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/libwrap0_*.deb || \
|
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
|
|
|
|
|
2017-03-15 20:38:55 -05:00
|
|
|
## Disable kexec supported reboot which was installed by default
|
|
|
|
sudo sed -i 's/LOAD_KEXEC=true/LOAD_KEXEC=false/' $FILESYSTEM_ROOT/etc/default/kexec
|
2016-03-08 13:42:20 -06:00
|
|
|
|
2016-07-26 14:01:58 -05:00
|
|
|
## Remove sshd host keys, and will regenerate on first sshd start
|
|
|
|
sudo rm -f $FILESYSTEM_ROOT/etc/ssh/ssh_host_*_key*
|
|
|
|
sudo cp files/sshd/host-ssh-keygen.sh $FILESYSTEM_ROOT/usr/local/bin/
|
|
|
|
sudo cp -f files/sshd/sshd.service $FILESYSTEM_ROOT/lib/systemd/system/ssh.service
|
|
|
|
## Config sshd
|
|
|
|
sudo augtool --autosave "set /files/etc/ssh/sshd_config/UseDNS no" -r $FILESYSTEM_ROOT
|
2018-01-09 19:55:10 -06:00
|
|
|
sudo sed -i 's/^ListenAddress ::/#ListenAddress ::/' $FILESYSTEM_ROOT/etc/ssh/sshd_config
|
|
|
|
sudo sed -i 's/^#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' $FILESYSTEM_ROOT/etc/ssh/sshd_config
|
2016-07-26 14:01:58 -05:00
|
|
|
|
2018-03-15 15:16:00 -05:00
|
|
|
## Copy fstrim service
|
|
|
|
sudo cp $FILESYSTEM_ROOT/usr/share/doc/util-linux/examples/fstrim.{service,timer} $FILESYSTEM_ROOT/etc/systemd/system
|
|
|
|
|
2017-05-18 12:57:19 -05:00
|
|
|
## Config monit
|
|
|
|
sudo sed -i '
|
|
|
|
s/^# set logfile syslog/set logfile syslog/;
|
|
|
|
s/^\s*set logfile \/var/# set logfile \/var/;
|
|
|
|
s/^# set httpd port/set httpd port/;
|
|
|
|
s/^# use address localhost/ use address localhost/;
|
|
|
|
s/^# allow localhost/ allow localhost/;
|
|
|
|
s/^# allow admin:monit/ allow admin:monit/;
|
|
|
|
s/^# allow @monit/ allow @monit/;
|
|
|
|
s/^# allow @users readonly/ allow @users readonly/
|
|
|
|
' $FILESYSTEM_ROOT/etc/monit/monitrc
|
|
|
|
|
|
|
|
sudo tee -a $FILESYSTEM_ROOT/etc/monit/monitrc > /dev/null <<'EOF'
|
|
|
|
check filesystem root-aufs with path /
|
|
|
|
if space usage > 90% for 5 times within 10 cycles then alert
|
|
|
|
check system $HOST
|
|
|
|
if memory usage > 90% for 5 times within 10 cycles then alert
|
|
|
|
if cpu usage (user) > 90% for 5 times within 10 cycles then alert
|
|
|
|
if cpu usage (system) > 90% for 5 times within 10 cycles then alert
|
|
|
|
EOF
|
|
|
|
|
2016-07-26 14:01:58 -05:00
|
|
|
## Config sysctl
|
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/var/core
|
|
|
|
sudo augtool --autosave "
|
2017-08-30 11:41:47 -05:00
|
|
|
set /files/etc/sysctl.conf/kernel.core_pattern '|/usr/bin/coredump-compress %e %t %p'
|
2016-11-04 21:47:36 -05:00
|
|
|
|
2017-05-11 20:57:00 -05:00
|
|
|
set /files/etc/sysctl.conf/kernel.softlockup_panic 1
|
|
|
|
set /files/etc/sysctl.conf/kernel.panic 10
|
2017-08-30 11:41:47 -05:00
|
|
|
set /files/etc/sysctl.conf/fs.suid_dumpable 2
|
2017-05-11 20:57:00 -05:00
|
|
|
|
2016-11-04 21:47:36 -05:00
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.default.forwarding 1
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.all.forwarding 1
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.eth0.forwarding 0
|
|
|
|
|
2016-07-26 14:01:58 -05:00
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.default.arp_accept 0
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.default.arp_announce 0
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.default.arp_filter 0
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.default.arp_notify 0
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.default.arp_ignore 0
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.all.arp_accept 0
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.all.arp_announce 1
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.all.arp_filter 0
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.all.arp_notify 1
|
|
|
|
set /files/etc/sysctl.conf/net.ipv4.conf.all.arp_ignore 2
|
2016-11-04 21:47:36 -05:00
|
|
|
|
2017-05-15 19:06:19 -05:00
|
|
|
set /files/etc/sysctl.conf/net.ipv4.neigh.default.base_reachable_time_ms 1800000
|
|
|
|
|
2016-11-04 21:47:36 -05:00
|
|
|
set /files/etc/sysctl.conf/net.ipv6.conf.default.forwarding 1
|
|
|
|
set /files/etc/sysctl.conf/net.ipv6.conf.all.forwarding 1
|
|
|
|
set /files/etc/sysctl.conf/net.ipv6.conf.eth0.forwarding 0
|
|
|
|
|
|
|
|
set /files/etc/sysctl.conf/net.ipv6.conf.default.accept_dad 0
|
2016-11-03 14:15:00 -05:00
|
|
|
set /files/etc/sysctl.conf/net.ipv6.conf.all.accept_dad 0
|
2017-05-10 19:39:51 -05:00
|
|
|
|
|
|
|
set /files/etc/sysctl.conf/net.ipv6.conf.eth0.accept_ra_defrtr 0
|
2017-06-29 03:40:22 -05:00
|
|
|
|
|
|
|
set /files/etc/sysctl.conf/net.core.rmem_max 2097152
|
2018-03-14 11:20:47 -05:00
|
|
|
set /files/etc/sysctl.conf/net.core.wmem_max 2097152
|
2016-07-26 14:01:58 -05:00
|
|
|
" -r $FILESYSTEM_ROOT
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## docker-py is needed by Ansible docker module
|
2017-12-24 01:34:15 -06:00
|
|
|
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT easy_install pip
|
|
|
|
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install 'docker-py==1.6.0'
|
2017-03-02 18:04:18 -06:00
|
|
|
## Note: keep pip installed for maintainance purpose
|
2016-03-08 13:42:20 -06:00
|
|
|
|
2017-03-23 14:18:52 -05:00
|
|
|
## Create /var/run/redis folder for docker-database to mount
|
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/var/run/redis
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Config DHCP for eth0
|
|
|
|
sudo tee -a $FILESYSTEM_ROOT/etc/network/interfaces > /dev/null <<EOF
|
|
|
|
|
|
|
|
auto eth0
|
|
|
|
allow-hotplug eth0
|
|
|
|
iface eth0 inet dhcp
|
|
|
|
EOF
|
|
|
|
|
2016-05-27 15:30:13 -05:00
|
|
|
sudo cp files/dhcp/rfc3442-classless-routes $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d
|
2017-02-02 13:19:48 -06:00
|
|
|
sudo cp files/dhcp/sethostname $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
|
2017-02-17 15:47:01 -06:00
|
|
|
sudo cp files/dhcp/graphserviceurl $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
|
|
|
|
sudo cp files/dhcp/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
|
|
|
|
sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/
|
2016-05-27 15:30:13 -05:00
|
|
|
|
2017-04-05 18:14:41 -05:00
|
|
|
## Version file
|
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic
|
|
|
|
sudo tee $FILESYSTEM_ROOT/etc/sonic/sonic_version.yml > /dev/null <<EOF
|
2018-03-16 03:09:33 -05:00
|
|
|
build_version: '$(sonic_get_version)'
|
2018-01-03 23:43:06 -06:00
|
|
|
debian_version: '$(cat $FILESYSTEM_ROOT/etc/debian_version)'
|
2018-03-16 03:09:33 -05:00
|
|
|
kernel_version: '$kversion'
|
2017-04-05 18:14:41 -05:00
|
|
|
asic_type: $sonic_asic_platform
|
2018-03-16 03:09:33 -05:00
|
|
|
commit_id: '$(git rev-parse --short HEAD)'
|
2017-04-05 18:14:41 -05:00
|
|
|
build_date: $(date -u)
|
2017-04-16 03:17:22 -05:00
|
|
|
build_number: ${BUILD_NUMBER:-0}
|
2017-04-05 18:14:41 -05:00
|
|
|
built_by: $USER@$BUILD_HOSTNAME
|
|
|
|
EOF
|
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
if [ -f sonic_debian_extension.sh ]; then
|
2017-02-27 15:08:41 -06:00
|
|
|
./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR
|
2017-01-29 13:33:33 -06:00
|
|
|
fi
|
|
|
|
|
2017-09-19 18:23:31 -05:00
|
|
|
## Organization specific extensions such as Configuration & Scripts for features like AAA, ZTP...
|
|
|
|
if [ "${enable_organization_extensions}" = "y" ]; then
|
|
|
|
if [ -f files/build_templates/organization_extensions.sh ]; then
|
|
|
|
sudo chmod 755 files/build_templates/organization_extensions.sh
|
|
|
|
./files/build_templates/organization_extensions.sh -f $FILESYSTEM_ROOT -h $HOSTNAME
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Clean up apt
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get autoremove
|
2016-05-27 15:30:13 -05:00
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get autoclean
|
2016-03-08 13:42:20 -06:00
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get clean
|
2016-05-27 15:30:13 -05:00
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT bash -c 'rm -rf /usr/share/doc/* /usr/share/locale/* /var/lib/apt/lists/* /tmp/*'
|
2016-03-08 13:42:20 -06:00
|
|
|
|
2017-12-24 01:34:15 -06:00
|
|
|
## Clean up proxy
|
|
|
|
[ -n "$http_proxy" ] && sudo rm -f $FILESYSTEM_ROOT/etc/apt/apt.conf.d/01proxy
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Umount all
|
|
|
|
echo '[INFO] Umount all'
|
2017-07-12 03:28:36 -05:00
|
|
|
## Display all process details access /proc
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT fuser -vm /proc
|
|
|
|
## Kill the processes
|
2016-03-08 13:42:20 -06:00
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /proc || true
|
2017-07-12 03:28:36 -05:00
|
|
|
## Wait fuser fully kill the processes
|
|
|
|
sleep 15
|
|
|
|
sudo umount $FILESYSTEM_ROOT/proc || true
|
2016-03-08 13:42:20 -06:00
|
|
|
|
|
|
|
## Prepare empty directory to trigger mount move in initramfs-tools/mount_loop_root, implemented by patching
|
|
|
|
sudo mkdir $FILESYSTEM_ROOT/host
|
|
|
|
|
|
|
|
## Compress most file system into squashfs file
|
|
|
|
sudo rm -f $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS
|
2016-05-27 15:30:13 -05:00
|
|
|
## Output the file system total size for diag purpose
|
2017-07-12 03:28:36 -05:00
|
|
|
## Note: -x to skip directories on different file systems, such as /proc
|
|
|
|
sudo du -hsx $FILESYSTEM_ROOT
|
2017-02-27 15:08:41 -06:00
|
|
|
sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -e boot -e var/lib/docker -e $PLATFORM_DIR
|
2016-03-08 13:42:20 -06:00
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
## Compress docker files
|
2017-02-06 10:17:16 -06:00
|
|
|
pushd $FILESYSTEM_ROOT && sudo tar czf $OLDPWD/$FILESYSTEM_DOCKERFS -C var/lib/docker .; popd
|
2017-01-29 13:33:33 -06:00
|
|
|
|
2017-02-27 15:08:41 -06:00
|
|
|
## Compress together with /boot, /var/lib/docker and $PLATFORM_DIR as an installer payload zip file
|
|
|
|
pushd $FILESYSTEM_ROOT && sudo zip $OLDPWD/$ONIE_INSTALLER_PAYLOAD -r boot/ $PLATFORM_DIR/; popd
|
2017-01-29 13:33:33 -06:00
|
|
|
sudo zip -g $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS $FILESYSTEM_DOCKERFS
|