New release v1.0.0

This commit is contained in:
Qi Luo 2016-03-08 11:42:20 -08:00
parent 27b8b067ad
commit 8228558d38
23 changed files with 1605 additions and 0 deletions

63
README.md Normal file
View File

@ -0,0 +1,63 @@
# Build Switch Images - buildimage
### This software repository must be treated as private and is only shared under NDA terms with Microsoft until publicly released.
# Description
Build an [Open Network Install Environment (ONIE)](https://github.com/opencomputeproject/onie) compatiable network operating system (NOS) installer image for network switches, and also build docker images running inside the NOS.
# Usage
## Build NOS installer image
./build_debian USERNAME PASSWORD_ENCRYPTED && ./build_image.sh
For example, the user name is 'acsadmin' and the password is 'YourPaSsWoRd'.
./build_debian.sh "acsadmin" "$(perl -e 'print crypt("YourPaSsWoRd", "salt"),"\n"')" && ./build_image.sh
The root is disabled, but the created user could sudo.
## Build docker images
./build_docker.sh docker-sswsyncd
./build_docker.sh docker-database
./build_docker.sh docker-bgp
./build_docker.sh docker-snmp
./build_docker.sh docker-lldp
# Contribution guide
All contributors must sign a contribution license agreement before contributions can be accepted. Contact kasubra@microsoft.com or daloher@microsoft.com. Later this will be automated.
### GitHub Workflow
We're following basic GitHub Flow. If you have no idea what we're talking about, check out [GitHub's official guide](https://guides.github.com/introduction/flow/). Note that merge is only performed by the repository maintainer.
Guide for performing commits:
* Isolate each commit to one component/bugfix/issue/feature
* Use a standard commit message format:
> [component/folder touched]: Description intent of your changes
>
> [List of changes]
>
> Signed-off-by: Your Name your@email.com
For example:
> swss-common: Stabilize the ConsumerTable
>
> * Fixing autoreconf
> * Fixing unit-tests by adding checkers and initialize the DB before start
> * Adding the ability to select from multiple channels
> * Health-Monitor - The idea of the patch is that if something went wrong with the notification channel,
> we will have the option to know about it (Query the LLEN table length).
>
> Signed-off-by: user@dev.null
* Each developer should fork this repository and [add the team as a Contributor](https://help.github.com/articles/adding-collaborators-to-a-personal-repository)
* Push your changes to your private fork and do "pull-request" to this repository
* Use a pull request to do code review
* Use issues to keep track of what is going on

300
ThirdPartyLicenses.txt Normal file
View File

@ -0,0 +1,300 @@
THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
Do Not Translate or Localize
This file provides information regarding components that are being relicensed to you by Microsoft under Microsoft's software licensing terms. Microsoft reserves all rights not expressly granted herein.
Microsoft is offering you a license to use the following components, to the extent they are included within the Microsoft Azure Cross-Platform Command-Line Interface (the "Microsoft Program"), subject to the terms of your license to use the Microsoft Product. Insofar as a component is dual licensed under the GPL and a license that permits relicensing under proprietary terms, Microsoft neither took the code under the GPL nor distributes it thereunder but under the terms of the license that permits relicensing under proprietary terms, as set out below. All notices and licenses set forth below are for informational purposes only.
1. onie-mk-demo.sh, sharch_body.sh, install.sh imported and modified from ONIE versions 2014.11 and 2015.8 using GNU GENERAL PUBLIC LICENSE Version 2
/*
* ONIE is Free Software. You can redistribute ONIE and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* =======================================================================
*
* GNU GENERAL PUBLIC LICENSE
* Version 2, June 1991
*
* Copyright (C) 1989, 1991 Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*
* Preamble
*
* The licenses for most software are designed to take away your
* freedom to share and change it. By contrast, the GNU General Public
* License is intended to guarantee your freedom to share and change free
* software--to make sure the software is free for all its users. This
* General Public License applies to most of the Free Software
* Foundation's software and to any other program whose authors commit to
* using it. (Some other Free Software Foundation software is covered by
* the GNU Library General Public License instead.) You can apply it to
* your programs, too.
*
* When we speak of free software, we are referring to freedom, not
* price. Our General Public Licenses are designed to make sure that you
* have the freedom to distribute copies of free software (and charge for
* this service if you wish), that you receive source code or can get it
* if you want it, that you can change the software or use pieces of it
* in new free programs; and that you know you can do these things.
*
* To protect your rights, we need to make restrictions that forbid
* anyone to deny you these rights or to ask you to surrender the rights.
* These restrictions translate to certain responsibilities for you if you
* distribute copies of the software, or if you modify it.
*
* For example, if you distribute copies of such a program, whether
* gratis or for a fee, you must give the recipients all the rights that
* you have. You must make sure that they, too, receive or can get the
* source code. And you must show them these terms so they know their
* rights.
*
* We protect your rights with two steps: (1) copyright the software, and
* (2) offer you this license which gives you legal permission to copy,
* distribute and/or modify the software.
*
* Also, for each author's protection and ours, we want to make certain
* that everyone understands that there is no warranty for this free
* software. If the software is modified by someone else and passed on, we
* want its recipients to know that what they have is not the original, so
* that any problems introduced by others will not reflect on the original
* authors' reputations.
*
* Finally, any free program is threatened constantly by software
* patents. We wish to avoid the danger that redistributors of a free
* program will individually obtain patent licenses, in effect making the
* program proprietary. To prevent this, we have made it clear that any
* patent must be licensed for everyone's free use or not licensed at all.
*
* The precise terms and conditions for copying, distribution and
* modification follow.
*
* GNU GENERAL PUBLIC LICENSE
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
*
* 0. This License applies to any program or other work which contains
* a notice placed by the copyright holder saying it may be distributed
* under the terms of this General Public License. The "Program", below,
* refers to any such program or work, and a "work based on the Program"
* means either the Program or any derivative work under copyright law:
* that is to say, a work containing the Program or a portion of it,
* either verbatim or with modifications and/or translated into another
* language. (Hereinafter, translation is included without limitation in
* the term "modification".) Each licensee is addressed as "you".
*
* Activities other than copying, distribution and modification are not
* covered by this License; they are outside its scope. The act of
* running the Program is not restricted, and the output from the Program
* is covered only if its contents constitute a work based on the
* Program (independent of having been made by running the Program).
* Whether that is true depends on what the Program does.
*
* 1. You may copy and distribute verbatim copies of the Program's
* source code as you receive it, in any medium, provided that you
* conspicuously and appropriately publish on each copy an appropriate
* copyright notice and disclaimer of warranty; keep intact all the
* notices that refer to this License and to the absence of any warranty;
* and give any other recipients of the Program a copy of this License
* along with the Program.
*
* You may charge a fee for the physical act of transferring a copy, and
* you may at your option offer warranty protection in exchange for a fee.
*
* 2. You may modify your copy or copies of the Program or any portion
* of it, thus forming a work based on the Program, and copy and
* distribute such modifications or work under the terms of Section 1
* above, provided that you also meet all of these conditions:
*
* a) You must cause the modified files to carry prominent notices
* stating that you changed the files and the date of any change.
*
* b) You must cause any work that you distribute or publish, that in
* whole or in part contains or is derived from the Program or any
* part thereof, to be licensed as a whole at no charge to all third
* parties under the terms of this License.
*
* c) If the modified program normally reads commands interactively
* when run, you must cause it, when started running for such
* interactive use in the most ordinary way, to print or display an
* announcement including an appropriate copyright notice and a
* notice that there is no warranty (or else, saying that you provide
* a warranty) and that users may redistribute the program under
* these conditions, and telling the user how to view a copy of this
* License. (Exception: if the Program itself is interactive but
* does not normally print such an announcement, your work based on
* the Program is not required to print an announcement.)
*
* These requirements apply to the modified work as a whole. If
* identifiable sections of that work are not derived from the Program,
* and can be reasonably considered independent and separate works in
* themselves, then this License, and its terms, do not apply to those
* sections when you distribute them as separate works. But when you
* distribute the same sections as part of a whole which is a work based
* on the Program, the distribution of the whole must be on the terms of
* this License, whose permissions for other licensees extend to the
* entire whole, and thus to each and every part regardless of who wrote it.
*
* Thus, it is not the intent of this section to claim rights or contest
* your rights to work written entirely by you; rather, the intent is to
* exercise the right to control the distribution of derivative or
* collective works based on the Program.
*
* In addition, mere aggregation of another work not based on the Program
* with the Program (or with a work based on the Program) on a volume of
* a storage or distribution medium does not bring the other work under
* the scope of this License.
*
* 3. You may copy and distribute the Program (or a work based on it,
* under Section 2) in object code or executable form under the terms of
* Sections 1 and 2 above provided that you also do one of the following:
*
* a) Accompany it with the complete corresponding machine-readable
* source code, which must be distributed under the terms of Sections
* 1 and 2 above on a medium customarily used for software interchange; or,
*
* b) Accompany it with a written offer, valid for at least three
* years, to give any third party, for a charge no more than your
* cost of physically performing source distribution, a complete
* machine-readable copy of the corresponding source code, to be
* distributed under the terms of Sections 1 and 2 above on a medium
* customarily used for software interchange; or,
*
* c) Accompany it with the information you received as to the offer
* to distribute corresponding source code. (This alternative is
* allowed only for noncommercial distribution and only if you
* received the program in object code or executable form with such
* an offer, in accord with Subsection b above.)
*
* The source code for a work means the preferred form of the work for
* making modifications to it. For an executable work, complete source
* code means all the source code for all modules it contains, plus any
* associated interface definition files, plus the scripts used to
* control compilation and installation of the executable. However, as a
* special exception, the source code distributed need not include
* anything that is normally distributed (in either source or binary
* form) with the major components (compiler, kernel, and so on) of the
* operating system on which the executable runs, unless that component
* itself accompanies the executable.
*
* If distribution of executable or object code is made by offering
* access to copy from a designated place, then offering equivalent
* access to copy the source code from the same place counts as
* distribution of the source code, even though third parties are not
* compelled to copy the source along with the object code.
*
* 4. You may not copy, modify, sublicense, or distribute the Program
* except as expressly provided under this License. Any attempt
* otherwise to copy, modify, sublicense or distribute the Program is
* void, and will automatically terminate your rights under this License.
* However, parties who have received copies, or rights, from you under
* this License will not have their licenses terminated so long as such
* parties remain in full compliance.
*
* 5. You are not required to accept this License, since you have not
* signed it. However, nothing else grants you permission to modify or
* distribute the Program or its derivative works. These actions are
* prohibited by law if you do not accept this License. Therefore, by
* modifying or distributing the Program (or any work based on the
* Program), you indicate your acceptance of this License to do so, and
* all its terms and conditions for copying, distributing or modifying
* the Program or works based on it.
*
* 6. Each time you redistribute the Program (or any work based on the
* Program), the recipient automatically receives a license from the
* original licensor to copy, distribute or modify the Program subject to
* these terms and conditions. You may not impose any further
* restrictions on the recipients' exercise of the rights granted herein.
* You are not responsible for enforcing compliance by third parties to
* this License.
*
* 7. If, as a consequence of a court judgment or allegation of patent
* infringement or for any other reason (not limited to patent issues),
* conditions are imposed on you (whether by court order, agreement or
* otherwise) that contradict the conditions of this License, they do not
* excuse you from the conditions of this License. If you cannot
* distribute so as to satisfy simultaneously your obligations under this
* License and any other pertinent obligations, then as a consequence you
* may not distribute the Program at all. For example, if a patent
* license would not permit royalty-free redistribution of the Program by
* all those who receive copies directly or indirectly through you, then
* the only way you could satisfy both it and this License would be to
* refrain entirely from distribution of the Program.
*
* If any portion of this section is held invalid or unenforceable under
* any particular circumstance, the balance of the section is intended to
* apply and the section as a whole is intended to apply in other
* circumstances.
*
* It is not the purpose of this section to induce you to infringe any
* patents or other property right claims or to contest validity of any
* such claims; this section has the sole purpose of protecting the
* integrity of the free software distribution system, which is
* implemented by public license practices. Many people have made
* generous contributions to the wide range of software distributed
* through that system in reliance on consistent application of that
* system; it is up to the author/donor to decide if he or she is willing
* to distribute software through any other system and a licensee cannot
* impose that choice.
*
* This section is intended to make thoroughly clear what is believed to
* be a consequence of the rest of this License.
*
* 8. If the distribution and/or use of the Program is restricted in
* certain countries either by patents or by copyrighted interfaces, the
* original copyright holder who places the Program under this License
* may add an explicit geographical distribution limitation excluding
* those countries, so that distribution is permitted only in or among
* countries not thus excluded. In such case, this License incorporates
* the limitation as if written in the body of this License.
*
* 9. The Free Software Foundation may publish revised and/or new versions
* of the General Public License from time to time. Such new versions will
* be similar in spirit to the present version, but may differ in detail to
* address new problems or concerns.
*
* Each version is given a distinguishing version number. If the Program
* specifies a version number of this License which applies to it and "any
* later version", you have the option of following the terms and conditions
* either of that version or of any later version published by the Free
* Software Foundation. If the Program does not specify a version number of
* this License, you may choose any version ever published by the Free Software
* Foundation.
*
* 10. If you wish to incorporate parts of the Program into other free
* programs whose distribution conditions are different, write to the author
* to ask for permission. For software which is copyrighted by the Free
* Software Foundation, write to the Free Software Foundation; we sometimes
* make exceptions for this. Our decision will be guided by the two goals
* of preserving the free status of all derivatives of our free software and
* of promoting the sharing and reuse of software generally.
*
* NO WARRANTY
*
* 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
* FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
* OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
* PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
* OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
* TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
* PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
* REPAIR OR CORRECTION.
*
* 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
* WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
* REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
* INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
* TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
* YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
* PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* END OF TERMS AND CONDITIONS
*/
2. union-fsck imported and modified from initramfs-tools version 0.91e using GPL v2 or any later version

199
build_debian.sh Executable file
View File

@ -0,0 +1,199 @@
#!/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
## Working directory to prepare the file system
FILESYSTEM_ROOT=./fsroot
## Hostname for the linux image
HOSTNAME=acs
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
sudo rm -r $FILESYSTEM_ROOT || die "Failed to clean chroot directory"
fi
mkdir -p $FILESYSTEM_ROOT
## Build a basic Debian system by debootstrap
echo '[INFO] Debootstrap...'
sudo debootstrap --arch amd64 jessie $FILESYSTEM_ROOT http://ftp.us.debian.org/debian
## 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"
## 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'
## 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
clean_sys() {
sudo umount $FILESYSTEM_ROOT/sys/fs/cgroup/* \
$FILESYSTEM_ROOT/sys/fs/cgroup \
$FILESYSTEM_ROOT/sys || true
}
trap_push 'sudo umount $FILESYSTEM_ROOT/sys || true'
sudo LANG=C chroot $FILESYSTEM_ROOT mount sysfs /sys -t sysfs
## Pointing apt to public apt mirrors and getting latest packages, needed for latest security updates
sudo cp files/sources.list $FILESYSTEM_ROOT/etc/apt/
## 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
echo '[INFO] Install ACS linux kernel image'
## Note: duplicate apt-get command to ensure every line return zero
sudo dpkg --root=$FILESYSTEM_ROOT -i deps/initramfs-tools_*.deb || \
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
sudo dpkg --root=$FILESYSTEM_ROOT -i deps/linux-image-3.16.0-4-amd64_*.deb || \
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
## Update initramfs for booting with squashfs+aufs
cat files/initramfs-tools/modules | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-tools/modules > /dev/null
## 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
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
## Install docker
echo '[INFO] Install docker'
curl -sSL https://get.docker.com/ | sudo LANG=C chroot $FILESYSTEM_ROOT sh
## Remove garbage left by docker installation script
sudo rm $FILESYSTEM_ROOT/etc/apt/sources.list.d/docker.list
sudo chroot $FILESYSTEM_ROOT service docker stop
sudo chroot $FILESYSTEM_ROOT service dbus stop
## Add docker config drop-in to select aufs, otherwise it may other storage driver
## Note: $_ means last argument of last command
sudo mkdir -p $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/
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
## Pre-install the fundamental packages
## Note: gdisk is needed for sgdisk in install.sh
## Note: parted is needed for partprobe in install.sh
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install \
sudo \
vim \
tcpdump \
ntp \
openssh-server \
python \
python-setuptools \
python-apt \
gdisk \
parted \
efibootmgr
## docker-py is needed by Ansible docker module
sudo LANG=C chroot $FILESYSTEM_ROOT easy_install pip
sudo LANG=C chroot $FILESYSTEM_ROOT pip install 'docker-py==1.6.0'
## Remove pip which is unnecessary in the base image
sudo LANG=C chroot $FILESYSTEM_ROOT pip uninstall -y pip
echo '[INFO] Install apt-transport-sftp package from deps directory'
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install libssh2-1
sudo dpkg --root=$FILESYSTEM_ROOT -i deps/apt-transport-sftp_*.deb
## 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
## Clean up apt
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get autoremove
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get clean
sudo LANG=C chroot $FILESYSTEM_ROOT rm -rf /tmp/*
## Umount all
echo '[INFO] Umount all'
sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /sys || true
sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys
sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /proc || true
sudo LANG=C chroot $FILESYSTEM_ROOT umount /proc
## 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
sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -e boot -e var/lib/docker
## Compress together with /boot and /var/lib/docker as an installer payload zip file
pushd $FILESYSTEM_ROOT && sudo zip $OLDPWD/$ONIE_INSTALLER_PAYLOAD -r boot/ -r var/lib/docker; popd
sudo zip -g $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS

61
build_docker.sh Executable file
View File

@ -0,0 +1,61 @@
#!/bin/bash
## This script is to automate the preparation for docker images for ACS.
## If registry server and port provided, the images will be pushed there.
## Usage:
## sudo ./build_docker.sh DOCKER_BUILD_DIR [REGISTRY_SERVER REGISTRY_PORT]
set -x -e
## Dockerfile directory
DOCKER_BUILD_DIR=$1
REGISTRY_SERVER=$2
REGISTRY_PORT=$3
REGISTRY_USERNAME=$4
REGISTRY_PASSWD=$5
[ -d "$DOCKER_BUILD_DIR" ] || {
echo "Invalid DOCKER_BUILD_DIR directory" >&2
exit 1
}
## Docker image label, so no need to remember its hash
docker_image_name=$DOCKER_BUILD_DIR
## File name for docker image
docker_image_gz=$docker_image_name.gz
[ -n "$docker_image_gz" ] || {
echo "Error: Output docker image filename is empty"
exit 1
}
function cleanup {
rm -rf $DOCKER_BUILD_DIR/files
rm -rf $DOCKER_BUILD_DIR/deps
docker rmi -f $docker_image_name || true
}
trap cleanup exit
## Copy dependencies
## Note: Dockerfile ADD doesn't support reference files outside the folder, so copy it locally
mkdir -p $DOCKER_BUILD_DIR/deps
cp deps/*.deb $DOCKER_BUILD_DIR/deps
## Copy the suggested Debian sources
## ref: https://wiki.debian.org/SourcesList
mkdir -p $DOCKER_BUILD_DIR/files
cp files/sources.list $DOCKER_BUILD_DIR/files
docker build -t $docker_image_name $DOCKER_BUILD_DIR
if [ -n "$REGISTRY_SERVER" ] && [ -n "$REGISTRY_PORT" ]; then
## Add registry information as tag, so will push as latest
## Temporarily add -f option to prevent error message of Docker engine version < 1.10.0
docker tag -f $docker_image_name $REGISTRY_SERVER:$REGISTRY_PORT/$docker_image_name
## Login the docker image registry server
## Note: user name and password are passed from command line, use fake email address to bypass login check
docker login -u $REGISTRY_USERNAME -p "$REGISTRY_PASSWD" -e "@" $REGISTRY_SERVER:$REGISTRY_PORT
docker push $REGISTRY_SERVER:$REGISTRY_PORT/$docker_image_name
fi
docker save $docker_image_name | gzip -c > $docker_image_gz

30
build_image.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
## This script is to generate an ONIE installer image based on a file system overload
## 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
}
## Retrieval short version of Git revision hash for partition metadata
[[ -z $(git status --untracked-files=no -s) ]] || {
echo "Error: There is local changes not committed to git repo. Cannot get a revision hash for partition metadata."
exit 1
}
GIT_REVISION=$(git rev-parse --short HEAD)
## Generate an ONIE installer image
## Note: Don't leave blank between lines. It is single line command.
CONSOLE_SPEED=9600 \
CONSOLE_DEV=0 \
CONSOLE_FLAG=0 \
CONSOLE_PORT=0x3f8 \
./onie-mk-demo.sh $TARGET_PLATFORM $TARGET_MACHINE $TARGET_PLATFORM-$TARGET_MACHINE-$ONIEIMAGE_VERSION \
installer $TARGET_MACHINE/platform.conf $OUTPUT_ONIE_IMAGE OS $GIT_REVISION $ONIE_IMAGE_PART_SIZE \
$ONIE_INSTALLER_PAYLOAD

16
docker-bgp/Dockerfile Executable file
View File

@ -0,0 +1,16 @@
FROM debian:jessie
## Set the apt source
COPY files/sources.list /etc/sources.list
RUN apt-get clean && apt-get update
## Pre-install the fundamental packages
RUN apt-get -y install \
rsyslog
COPY deps /deps
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/quagga_*.deb
ENTRYPOINT service rsyslog start \
&& service quagga start \
&& /bin/bash

14
docker-database/Dockerfile Executable file
View File

@ -0,0 +1,14 @@
FROM debian:jessie
## Set the apt source
COPY files/sources.list /etc/sources.list
RUN apt-get clean && apt-get update
## Pre-install the fundamental packages
RUN apt-get -y install \
rsyslog \
redis-server
ENTRYPOINT service rsyslog start \
&& service redis-server start \
&& /bin/bash

23
docker-lldp/Dockerfile Executable file
View File

@ -0,0 +1,23 @@
FROM debian:jessie
## Set the apt source
COPY files/sources.list /etc/sources.list
RUN apt-get clean && apt-get update
## Pre-install the fundamental packages
RUN apt-get -y install \
rsyslog \
lldpd
COPY deps /deps
## Install Python SSWSDK (lldpsyncd dependancy)
## Note: dpkg_apt function has the benefit to detect missing .deb file
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/python-sswsdk_*.deb
## Install LLDP Sync Daemon
## Note: dpkg_apt function has the benefit to detect missing .deb file
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/lldpsyncd_*.deb
## Specify init as CMD to enable systemd
## Note: don't provide ENTRYPOINT at the same time
CMD ["/sbin/init"]

48
docker-ptf/Dockerfile Normal file
View File

@ -0,0 +1,48 @@
FROM debian:jessie
MAINTAINER Pavel Shirshov
## Copy dependencies
COPY deps /root/deps
## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive
## Set the apt source, update package cache and install necessary packages
RUN echo "deb http://ftp.us.debian.org/debian/ jessie main contrib non-free" > /etc/apt/sources.list \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get dist-upgrade -y \
&& apt-get install -y --no-install-recommends \
openssh-server \
vim-tiny \
python \
python-scapy \
net-tools \
python-setuptools \
supervisor \
traceroute \
lsof \
tcpdump \
&& dpkg -i /root/deps/python-ptf_*.deb \
&& dpkg -i --force-depends /root/deps/libthrift-0.9.2_*.deb \
&& dpkg -i --force-depends /root/deps/python-thrift_*.deb \
&& apt-get -y install -f \
&& rm -rf /root/deps \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*
## Adjust sshd settings
RUN mkdir /var/run/sshd \
&& echo 'root:root' | chpasswd \
&& sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config \
&& sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config \
&& sed -i '$aUseDNS no' /etc/ssh/sshd_config \
&& mkdir /root/deps
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
EXPOSE 22
ENTRYPOINT ["/usr/bin/supervisord"]

View File

@ -0,0 +1,13 @@
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
process_name=sshd
stdout_logfile=/tmp/sshd.out.log
stderr_logfile=/tmp/sshd.err.log
redirect_stderr=false
autostart=true
autorestart=true
startsecs=1
numprocs=1

23
docker-snmp/Dockerfile Executable file
View File

@ -0,0 +1,23 @@
FROM debian:jessie
## Set the apt source
COPY files/sources.list /etc/sources.list
RUN apt-get clean && apt-get update
## Pre-install the fundamental packages
RUN apt-get -y install \
rsyslog \
snmp \
snmpd
COPY deps /deps
## Install Python SSWSDK (SNMP subagent dependancy)
## Note: dpkg_apt function has the benefit to detect missing .deb file
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/python-sswsdk_*.deb
## Install SNMP subagent
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/acs-snmp-subagent_*.deb
## Specify init as CMD to enable systemd
## Note: don't provide ENTRYPOINT at the same time
CMD ["/sbin/init"]

21
docker-sswsyncd/Dockerfile Executable file
View File

@ -0,0 +1,21 @@
FROM debian:jessie
## Set the apt source
COPY files/sources.list /etc/sources.list
RUN apt-get clean && apt-get update
## Pre-install the fundamental packages
## TODO: sswsyncd depends on ifupdown
RUN apt-get -y install \
ifupdown \
rsyslog
COPY deps /deps
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/libopennsl_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/libsaibcm_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/libsswsdk_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/sswsyncd_*.deb
ENTRYPOINT service rsyslog start \
&& service sswsyncd start \
&& /bin/bash

View File

@ -0,0 +1,3 @@
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --storage-driver=aufs

View File

@ -0,0 +1,2 @@
squashfs
aufs

View File

@ -0,0 +1,36 @@
#!/bin/sh
#
# Derived from original /usr/share/initramfs-tools/hooks/fsck
# To correctly handle file system type detection of a physical partition in a union mounting root file system
. /usr/share/initramfs-tools/hooks/fsck $1
# HACK! HACK! HACK!
# Override original fstab_files()
# Use mtab instead of fstab
fstab_files()
{
echo /etc/mtab
}
get_fstypes_boot() {
get_fstype_fstab /host
}
for type in $(get_fstypes_boot | sort | uniq); do
if [ "$type" = 'auto' ] ; then
echo "Warning: couldn't identify filesystem type for (usr) fsck hook, ignoring."
continue
fi
prog="/sbin/fsck.${type}"
if [ -h "$prog" ]; then
link=$(readlink -f "$prog")
copy_exec "$link"
ln -s "$link" "${DESTDIR}/$prog"
elif [ -x "$prog" ] ; then
copy_exec "$prog"
else
echo "Warning: /sbin/fsck.${type} doesn't exist, can't install to initramfs, ignoring."
fi
done

View File

@ -0,0 +1,13 @@
#!/bin/sh -e
case $1 in
prereqs)
exit 0
;;
esac
mkdir -p ${rootmnt}/host/rw
mount -n -o dirs=${rootmnt}/host/rw:${rootmnt}=ro -t aufs root-aufs ${rootmnt}
mount ${ROOT} ${rootmnt}/host
mkdir -p /root/var/lib/docker
mount --bind /root/host/var/lib/docker /root/var/lib/docker
mkdir -p /root/boot
mount --bind /root/host/boot /root/boot

8
files/sources.list Normal file
View File

@ -0,0 +1,8 @@
deb http://httpredir.debian.org/debian jessie main contrib non-free
deb-src http://httpredir.debian.org/debian jessie main contrib non-free
deb http://httpredir.debian.org/debian jessie-updates main contrib non-free
deb-src http://httpredir.debian.org/debian jessie-updates main contrib non-free
deb http://security.debian.org/ jessie/updates main contrib non-free
deb-src http://security.debian.org/ jessie/updates main contrib non-free

38
functions.sh Normal file
View File

@ -0,0 +1,38 @@
#!/bin/bash
## Function Definitions
## Function: trap_push 'COMMAND_STRING'
## Appends a command to a trap, which is needed because default trap behavior is to replace
## previous trap for the same signal
## - 1st arg: code to add
## - ref: http://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
_trap_push() {
local next="$1"
eval "trap_push() {
local oldcmd='$(echo "$next" | sed -e s/\'/\'\\\\\'\'/g)'
local newcmd=\"\$1; \$oldcmd\"
trap -- \"\$newcmd\" EXIT INT TERM HUP
_trap_push \"\$newcmd\"
}"
}
_trap_push true
## Function: warn MESSAGE
## Print message to stderr
warn() {
local message="$1"
echo "$message" >&2
}
## Function: die MESSAGE
## Print message to stderr and exit the whole process
## Note:
## Using () makes the command inside them run in a sub-shell and calling a exit from there
## causes you to exit the sub-shell and not your original shell, hence execution continues in
## your original shell. To overcome this use { }
## ref: http://stackoverflow.com/questions/3822621/how-to-exit-if-a-command-failed
die() {
local message="$1"
warn "$message"
exit 1
}

0
generic/platform.conf Normal file
View File

59
installer/sharch_body.sh Normal file
View File

@ -0,0 +1,59 @@
#!/bin/sh
# Copyright (C) 2013 Curt Brune <curt@cumulusnetworks.com>
#
# SPDX-License-Identifier: GPL-2.0
##
## Shell archive template
##
## Strings of the form %%VAR%% are replaced during construction.
##
echo -n "Verifying image checksum ..."
sha1=$(sed -e '1,/^exit_marker$/d' "$0" | sha1sum | awk '{ print $1 }')
payload_sha1=%%IMAGE_SHA1%%
if [ "$sha1" != "$payload_sha1" ] ; then
echo
echo "ERROR: Unable to verify archive checksum"
echo "Expected: $payload_sha1"
echo "Found : $sha1"
exit 1
fi
echo " OK."
# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
fi
cd $tmp_dir
echo -n "Preparing image archive ..."
sed -e '1,/^exit_marker$/d' $archive_path | tar xf - || exit 1
echo " OK."
cd $cur_wd
if [ -n "$extract" ] ; then
# stop here
echo "Image extracted to: $tmp_dir"
if [ "$(id -u)" = "0" ] && [ ! -d "$extract" ] ; then
echo "To un-mount the tmpfs when finished type: umount $tmp_dir"
fi
exit 0
fi
$tmp_dir/installer/install.sh
rc="$?"
# clean up
if [ "$(id -u)" = "0" ] ; then
umount $tmp_dir
fi
rm -rf $tmp_dir
exit $rc
exit_marker

476
installer/x86_64/install.sh Executable file
View File

@ -0,0 +1,476 @@
#!/bin/sh
# Copyright (C) 2014-2015 Curt Brune <curt@cumulusnetworks.com>
# Copyright (C) 2014-2015 david_yang <david_yang@accton.com>
#
# SPDX-License-Identifier: GPL-2.0
# Function definitions
# wc -l
line_count() { return $(echo $1 | wc -l); }
# Appends a command to a trap, which is needed because default trap behavior is to replace
# previous trap for the same signal
# - 1st arg: code to add
# - ref: http://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
_trap_push() {
local next="$1"
eval "trap_push() {
local oldcmd='$(echo "$next" | sed -e s/\'/\'\\\\\'\'/g)'
local newcmd=\"\$1; \$oldcmd\"
trap -- \"\$newcmd\" EXIT INT TERM HUP
_trap_push \"\$newcmd\"
}"
}
_trap_push true
# Main
set -e
cd $(dirname $0)
. ./machine.conf
. ./onie-image.conf
echo "ONIE Installer: platform: $platform"
# Make sure run as root or under 'sudo'
if [ $(id -u) -ne 0 ]
then echo "Please run as root"
exit 1
fi
# Install demo on same block device as ONIE
onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
blk_dev=$(echo $onie_dev | sed -e 's/[1-9][0-9]*$//' | sed -e 's/\([0-9]\)\(p\)/\1/')
# Note: ONIE has no mount setting for / with device node, so below will be empty string
cur_part=$(cat /proc/mounts | awk "{ if(\$2==\"/\") print \$1 }" | grep $blk_dev || true)
[ -b "$blk_dev" ] || {
echo "Error: Unable to determine block device of ONIE install"
exit 1
}
# If running in ONIE
if [ "$onie_dev" = "$cur_part" ] || [ -z "$cur_part" ]; then
# The onie bin tool prefix
onie_bin=
# The persistent ONIE directory location
onie_root_dir=/mnt/onie-boot/onie
# The onie file system root
onie_initrd_tmp=/
# Else running in normal Linux
else
# Mount ONIE-BOOT partition
onie_mnt=$(mktemp -d) || {
echo "Error: Unable to create file system mount point"
exit 1
}
trap_push "fuser -km $onie_mnt || umount $onie_mnt || rmdir $onie_mnt || true"
mount $onie_dev $onie_mnt
onie_root_dir=$onie_mnt/onie
# Mount initrd inside ONIE-BOOT partition
onie_initrd_tmp=$(mktemp -d) || {
echo "Error: Unable to create file system mount point"
exit 1
}
trap_push "rm -rf $onie_initrd_tmp || true"
cd $onie_initrd_tmp
# Note: use wildcard in filename below to prevent hard-code version
cat $onie_mnt/onie/initrd.img-*-onie | unxz | cpio -id
cd -
onie_bin="chroot $onie_initrd_tmp"
fi
# The build system prepares this script by replacing %%DEMO-TYPE%%
# with "OS" or "DIAG".
demo_type="%%DEMO_TYPE%%"
# The build system prepares this script by replacing %%GIT_REVISION%%
# with git revision hash as a version identifier
git_revision="%%GIT_REVISION%%"
demo_volume_label="ACS-${demo_type}"
demo_volume_revision_label="ACS-${demo_type}-${git_revision}"
# auto-detect whether BIOS or UEFI
if [ -d "/sys/firmware/efi/efivars" ] ; then
firmware="uefi"
else
firmware="bios"
fi
# determine ONIE partition type
onie_partition_type=$(${onie_bin} onie-sysinfo -t)
# demo partition size in MB
demo_part_size="%%ONIE_IMAGE_PART_SIZE%%"
if [ "$firmware" = "uefi" ] ; then
create_demo_partition="create_demo_uefi_partition"
elif [ "$onie_partition_type" = "gpt" ] ; then
create_demo_partition="create_demo_gpt_partition"
elif [ "$onie_partition_type" = "msdos" ] ; then
create_demo_partition="create_demo_msdos_partition"
else
echo "ERROR: Unsupported partition type: $onie_partition_type"
exit 1
fi
# Creates a new partition for the DEMO OS.
#
# arg $1 -- base block device
#
# Returns the created partition number in $demo_part
demo_part=""
create_demo_gpt_partition()
{
blk_dev="$1"
# Create a temp fifo and store string in variable
tmpfifo=$(mktemp -u)
trap_push "rm $tmpfifo || true"
mkfifo -m 600 "$tmpfifo"
# See if demo partition already exists
demo_part=$(sgdisk -p $blk_dev | grep "$demo_volume_label" | awk '{print $1}')
if [ -n "$demo_part" ] ; then
# delete existing partitions
# if there are multiple partitions matched, we should delete each one, except the current OS's
# Note: You can use any character as a separator for sed, not just '/'
echo "$demo_part" > $tmpfifo &
while read -r part_index; do
if [ "$blk_dev$part_index" = "$cur_part" ]; then continue; fi
echo "deleting partition $part_index ..."
sgdisk -d $part_index $blk_dev || {
echo "Error: Unable to delete partition $part_index on $blk_dev"
exit 1
}
partprobe
done < $tmpfifo
fi
# ASSUME: there are no more than 99999 partitions in a block device
all_part=$(sgdisk -p $blk_dev | awk "{if (\$1 > 0 && \$1 <= 99999) print \$1}")
# Get the index of last partition
# Note: the double quotation marks for echo argument are necessary, otherwise the unquoted version replaces each sequence of
# one or more blanks, tabs and newlines with a single space.
# Ref: http://stackoverflow.com/questions/613572/capturing-multiple-line-output-to-a-bash-variable
last_part=$(echo "$all_part" | tail -n 1 | awk '{print $1}')
# Find next available partition
demo_part=1
echo "$all_part" > $tmpfifo &
# Find the first available partition number
while read -r used_part; do
echo "Partition #$used_part is in use."
if [ "$used_part" -ne "$demo_part" ]; then break; fi
demo_part=`expr $demo_part + 1`
done < $tmpfifo
echo "Partition #$demo_part is available"
# Create new partition
echo "Creating new $demo_volume_label partition ${blk_dev}$demo_part ..."
if [ "$demo_type" = "DIAG" ] ; then
# set the GPT 'system partition' attribute bit for the DIAG
# partition.
attr_bitmask="0x1"
else
attr_bitmask="0x0"
fi
sgdisk --new=${demo_part}::+${demo_part_size}MB \
--attributes=${demo_part}:=:$attr_bitmask \
--change-name=${demo_part}:$demo_volume_revision_label $blk_dev \
|| {
begin=$(sgdisk -F $blk_dev)
end=$(sgdisk -E $blk_dev)
sgdisk --new=${demo_part}:$begin:$end \
--attributes=${demo_part}:=:$attr_bitmask \
--change-name=${demo_part}:$demo_volume_revision_label $blk_dev
} || {
echo "Error: Unable to create partition $demo_part on $blk_dev"
exit 1
}
## If running in normal Linux, partprobe will complain as below and return non-zero
## Error: Partition(s) 4 on /dev/sda have been written, but we have been unable to inform the kernel of the change,
## probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now
## before making further changes.
partprobe || true
}
create_demo_msdos_partition()
{
blk_dev="$1"
# See if demo partition already exists -- look for the filesystem
# label.
part_info="$(blkid | grep $demo_volume_label | awk -F: '{print $1}')"
if [ -n "$part_info" ] ; then
# delete existing partition
demo_part="$(echo -n $part_info | sed -e s#${blk_dev}##)"
parted -s $blk_dev rm $demo_part || {
echo "Error: Unable to delete partition $demo_part on $blk_dev"
exit 1
}
partprobe
fi
# Find next available partition
last_part_info="$(parted -s -m $blk_dev unit s print | tail -n 1)"
last_part_num="$(echo -n $last_part_info | awk -F: '{print $1}')"
last_part_end="$(echo -n $last_part_info | awk -F: '{print $3}')"
# Remove trailing 's'
last_part_end=${last_part_end%s}
demo_part=$(( $last_part_num + 1 ))
demo_part_start=$(( $last_part_end + 1 ))
# sectors_per_mb = (1024 * 1024) / 512 = 2048
sectors_per_mb=2048
demo_part_end=$(( $demo_part_start + ( $demo_part_size * $sectors_per_mb ) - 1 ))
# Create new partition
echo "Creating new partition ${blk_dev}$demo_part ..."
parted -s --align optimal $blk_dev unit s \
mkpart primary $demo_part_start $demo_part_end set $demo_part boot on || {
echo "ERROR: Problems creating msdos partition $demo_part on: $blk_dev"
exit 1
}
partprobe
}
# For UEFI systems, create a new partition for the DEMO OS.
#
# arg $1 -- base block device
#
# Returns the created partition number in $demo_part
create_demo_uefi_partition()
{
create_demo_gpt_partition "$1"
# erase any related EFI BootOrder variables from NVRAM.
for b in $(efibootmgr | grep "$demo_volume_label" | awk '{ print $1 }') ; do
local num=${b#Boot}
# Remove trailing '*'
num=${num%\*}
efibootmgr -b $num -B > /dev/null 2>&1
done
}
# Install legacy BIOS GRUB for DEMO OS
demo_install_grub()
{
local demo_mnt="$1"
local blk_dev="$2"
# Pretend we are a major distro and install GRUB into the MBR of
# $blk_dev.
grub-install --boot-directory="$onie_initrd_tmp/$demo_mnt" --recheck "$blk_dev" || {
echo "ERROR: grub-install failed on: $blk_dev"
exit 1
}
if [ "$demo_type" = "DIAG" ] ; then
# Install GRUB in the partition also. This allows for
# chainloading the DIAG image from another OS.
#
# We are installing GRUB in a partition, as opposed to the
# MBR. With this method block lists are used to refer to the
# the core.img file. The sector locations of core.img may
# change whenever the file system in the partition is being
# altered (files copied, deleted etc.). For more info, see
# https://bugzilla.redhat.com/show_bug.cgi?id=728742 and
# https://bugzilla.redhat.com/show_bug.cgi?id=730915.
#
# The workaround for this is to set the immutable flag on
# /boot/grub/i386-pc/core.img using the chattr command so that
# the sector locations of the core.img file in the disk is not
# altered. The immutable flag on /boot/grub/i386-pc/core.img
# needs to be set only if GRUB is installed to a partition
# boot sector or a partitionless disk, not in case of
# installation to MBR.
core_img="$demo_mnt/grub/i386-pc/core.img"
# remove immutable flag if file exists during the update.
[ -f "$core_img" ] && chattr -i $core_img
grub_install_log=$(mktemp)
grub-install --force --boot-directory="$onie_initrd_tmp/$demo_mnt" \
--recheck "$demo_dev" > /$grub_install_log 2>&1 || {
echo "ERROR: grub-install failed on: $demo_dev"
cat $grub_install_log && rm -f $grub_install_log
exit 1
}
rm -f $grub_install_log
# restore immutable flag on the core.img file as discussed
# above.
[ -f "$core_img" ] && chattr +i $core_img
fi
}
# Install UEFI BIOS GRUB for DEMO OS
demo_install_uefi_grub()
{
local demo_mnt="$1"
local blk_dev="$2"
# make sure /boot/efi is mounted
if ! mount | grep -q "/boot/efi"; then
mount /boot/efi
fi
# Look for the EFI system partition UUID on the same block device as
# the ONIE-BOOT partition.
local uefi_part=0
for p in $(seq 8) ; do
if sgdisk -i $p $blk_dev | grep -q C12A7328-F81F-11D2-BA4B-00A0C93EC93B ; then
uefi_part=$p
break
fi
done
[ $uefi_part -eq 0 ] && {
echo "ERROR: Unable to determine UEFI system partition"
exit 1
}
grub_install_log=$(mktemp)
grub-install \
--no-nvram \
--bootloader-id="$onie_initrd_tmp/$demo_volume_label" \
--efi-directory="/boot/efi" \
--boot-directory="$demo_mnt" \
--recheck \
"$blk_dev" > /$grub_install_log 2>&1 || {
echo "ERROR: grub-install failed on: $blk_dev"
cat $grub_install_log && rm -f $grub_install_log
exit 1
}
rm -f $grub_install_log
# Configure EFI NVRAM Boot variables. --create also sets the
# new boot number as active.
efibootmgr --quiet --create \
--label "$demo_volume_label" \
--disk $blk_dev --part $uefi_part \
--loader "/EFI/$demo_volume_label/grubx64.efi" || {
echo "ERROR: efibootmgr failed to create new boot variable on: $blk_dev"
exit 1
}
}
eval $create_demo_partition $blk_dev
demo_dev=$(echo $blk_dev | sed -e 's/\(mmcblk[0-9]\)/\1p/')$demo_part
# Make filesystem
mkfs.ext4 -L $demo_volume_revision_label $demo_dev
# Mount demo filesystem
demo_mnt=$(${onie_bin} mktemp -d) || {
echo "Error: Unable to create file system mount point"
exit 1
}
trap_push "${onie_bin} fuser -km $demo_mnt || ${onie_bin} umount $demo_mnt || ${onie_bin} rmdir $demo_mnt || true"
${onie_bin} mount -t ext4 -o defaults,rw $demo_dev $demo_mnt || {
echo "Error: Unable to mount $demo_dev on $demo_mnt"
exit 1
}
# Decompress the file for the file system directly to the partition
unzip $ONIE_INSTALLER_PAYLOAD -d $demo_mnt
# store installation log in demo file system
rm -f $onie_initrd_tmp/tmp/onie-support.tar.bz2
${onie_bin} onie-support /tmp
mv $onie_initrd_tmp/tmp/onie-support.tar.bz2 $demo_mnt
if [ "$firmware" = "uefi" ] ; then
demo_install_uefi_grub "$demo_mnt" "$blk_dev"
else
demo_install_grub "$demo_mnt" "$blk_dev"
fi
# Create a minimal grub.cfg that allows for:
# - configure the serial console
# - allows for grub-reboot to work
# - a menu entry for the DEMO OS
# - menu entries for ONIE
grub_cfg=$(mktemp)
trap_push "rm $grub_cfg || true"
# Set a few GRUB_xxx environment variables that will be picked up and
# used by the 50_onie_grub script. This is similiar to what an OS
# would specify in /etc/default/grub.
#
# GRUB_SERIAL_COMMAND
# GRUB_CMDLINE_LINUX
[ -r ./platform.conf ] && . ./platform.conf
DEFAULT_GRUB_SERIAL_COMMAND="serial --port=%%CONSOLE_PORT%% --speed=%%CONSOLE_SPEED%% --word=8 --parity=no --stop=1"
DEFAULT_GRUB_CMDLINE_LINUX="console=tty0 console=ttyS%%CONSOLE_DEV%%,%%CONSOLE_SPEED%%n8 quiet"
GRUB_SERIAL_COMMAND=${GRUB_SERIAL_COMMAND:-"$DEFAULT_GRUB_SERIAL_COMMAND"}
GRUB_CMDLINE_LINUX=${GRUB_CMDLINE_LINUX:-"$DEFAULT_GRUB_CMDLINE_LINUX"}
export GRUB_SERIAL_COMMAND
export GRUB_CMDLINE_LINUX
# Add common configuration, like the timeout and serial console.
cat <<EOF > $grub_cfg
$GRUB_SERIAL_COMMAND
terminal_input serial
terminal_output serial
set timeout=5
EOF
# Add the logic to support grub-reboot
cat <<EOF >> $grub_cfg
if [ -s \$prefix/grubenv ]; then
load_env
fi
if [ "\${next_entry}" ] ; then
set default="\${next_entry}"
set next_entry=
save_env next_entry
fi
EOF
if [ "$demo_type" = "DIAG" ] ; then
# Make sure ONIE install mode is the default boot mode for the
# diag partition.
cat <<EOF >> $grub_cfg
set default=ONIE
EOF
$onie_root_dir/tools/bin/onie-boot-mode -q -o install
fi
# Add a menu entry for the DEMO OS
# Note: assume that apparmor is supported in the kernel
demo_grub_entry="$demo_volume_revision_label"
cat <<EOF >> $grub_cfg
menuentry '$demo_grub_entry' {
search --no-floppy --label --set=root $demo_volume_revision_label
echo 'Loading $demo_volume_revision_label $demo_type kernel ...'
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_msdos
insmod ext2
linux /boot/vmlinuz-3.16.0-4-amd64 root=$demo_dev rw $GRUB_CMDLINE_LINUX \
loop=$FILESYSTEM_SQUASHFS loopfstype=squashfs \
apparmor=1 security=apparmor
echo 'Loading $demo_volume_revision_label $demo_type initial ramdisk ...'
initrd /boot/initrd.img-3.16.0-4-amd64
}
EOF
# Add menu entries for ONIE -- use the grub fragment provided by the
# ONIE distribution.
$onie_root_dir/grub.d/50_onie_grub >> $grub_cfg
mkdir -p $onie_initrd_tmp/$demo_mnt/grub
cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg
cd /

22
onie-image.conf Normal file
View File

@ -0,0 +1,22 @@
## DESCRIPTION:
## partition related config
##
## Partition size in MB
## The default size is 32GB
: ${ONIE_IMAGE_PART_SIZE:=32768}
## Target hardware information
: ${TARGET_PLATFORM:=x86_64}
: ${TARGET_MACHINE:=generic}
ONIEIMAGE_VERSION=r0
## Filename for squashfs file system
FILESYSTEM_SQUASHFS=fs.squashfs
## Filename for onie installer payload, will be the main part of onie installer
ONIE_INSTALLER_PAYLOAD=fs.zip
## Output file name for onie installer
OUTPUT_ONIE_IMAGE=acs-$TARGET_MACHINE.bin

137
onie-mk-demo.sh Executable file
View File

@ -0,0 +1,137 @@
#!/bin/sh
# Copyright (C) 2013-2014 Curt Brune <curt@cumulusnetworks.com>
#
# SPDX-License-Identifier: GPL-2.0
set -x
arch=$1
machine=$2
platform=$3
installer_dir=$4
platform_conf=$5
output_file=$6
demo_type=$7
git_revision=$8
onie_image_part_size=$9
shift 9
if [ ! -d $installer_dir ] || \
[ ! -r $installer_dir/sharch_body.sh ] ; then
echo "Error: Invalid installer script directory: $installer_dir"
exit 1
fi
if [ ! -d $installer_dir/$arch ] || \
[ ! -r $installer_dir/$arch/install.sh ] ; then
echo "Error: Invalid arch installer directory: $installer_dir/$arch"
exit 1
fi
[ -n "$git_revision" ] || {
echo "Error: Invalid git revisions"
exit 1
}
[ -n "$onie_image_part_size" ] || {
echo "Error: Invalid onie_image_part_size"
exit 1
}
[ -n "$CONSOLE_SPEED" ] || {
echo "Error: Invalid CONSOLE_SPEED"
exit 1
}
[ -r "$platform_conf" ] || {
echo "Error: Unable to read installer platform configuration file: $platform_conf"
exit 1
}
[ $# -gt 0 ] || {
echo "Error: No OS image files found"
exit 1
}
case $demo_type in
OS|DIAG)
# These are supported
;;
*)
echo "Error: Unsupported demo type: $demo_type"
exit 1
esac
tmp_dir=
clean_up()
{
rm -rf $tmp_dir
exit $1
}
# make the data archive
# contents:
# - kernel and initramfs
# - install.sh
# - $platform_conf
echo -n "Building self-extracting install image ."
tmp_dir=$(mktemp --directory)
tmp_installdir="$tmp_dir/installer"
mkdir $tmp_installdir || clean_up 1
cp $installer_dir/$arch/install.sh $tmp_installdir || clean_up 1
cp onie-image.conf $tmp_installdir
# Escape special chars in the user provide kernel cmdline string for use in
# sed. Special chars are: \ / &
EXTRA_CMDLINE_LINUX=`echo $EXTRA_CMDLINE_LINUX | sed -e 's/[\/&]/\\\&/g'`
# Tailor the demo installer for OS mode or DIAG mode
sed -i -e "s/%%DEMO_TYPE%%/$demo_type/g" \
-e "s/%%GIT_REVISION%%/$git_revision/g" \
-e "s/%%ONIE_IMAGE_PART_SIZE%%/$onie_image_part_size/" \
-e "s/%%CONSOLE_SPEED%%/$CONSOLE_SPEED/g" \
-e "s/%%CONSOLE_DEV%%/$CONSOLE_DEV/g" \
-e "s/%%CONSOLE_FLAG%%/$CONSOLE_FLAG/g" \
-e "s/%%CONSOLE_PORT%%/$CONSOLE_PORT/g" \
-e "s/%%EXTRA_CMDLINE_LINUX%%/$EXTRA_CMDLINE_LINUX/" \
$tmp_installdir/install.sh || clean_up 1
echo -n "."
cp -r $* $tmp_installdir || clean_up 1
echo -n "."
cp $platform_conf $tmp_installdir || clean_up 1
echo "machine=$machine" > $tmp_installdir/machine.conf
echo "platform=$platform" >> $tmp_installdir/machine.conf
echo -n "."
sharch="$tmp_dir/sharch.tar"
tar -C $tmp_dir -cf $sharch installer || {
echo "Error: Problems creating $sharch archive"
clean_up 1
}
echo -n "."
[ -f "$sharch" ] || {
echo "Error: $sharch not found"
clean_up 1
}
sha1=$(cat $sharch | sha1sum | awk '{print $1}')
echo -n "."
cp $installer_dir/sharch_body.sh $output_file || {
echo "Error: Problems copying sharch_body.sh"
clean_up 1
}
# Replace variables in the sharch template
sed -i -e "s/%%IMAGE_SHA1%%/$sha1/" $output_file
echo -n "."
cat $sharch >> $output_file
rm -rf $tmp_dir
echo " Done."
echo "Success: Demo install image is ready in ${output_file}:"
ls -l ${output_file}
clean_up 0