Skip to content

Commit

Permalink
Skybian boot fixes.
Browse files Browse the repository at this point in the history
* Instead of rebooting after skybian-firstrun unit, start hypervisor/visor unit.

* Add additional 512 bytes to raw image.

* Reenable apt clean during image build.
  • Loading branch information
志宇 committed Apr 24, 2020
1 parent d23c8be commit e300f94
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 132 deletions.
4 changes: 2 additions & 2 deletions build.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# PATCH version when you make backwards-compatible bug fixes.
#
# version must always start with "v" like: v0.1.45-rc
VERSION=v0.1.1
VERSION=v0.1.2
# This must match the tags in the github repository

# loading the actual path
Expand All @@ -25,4 +25,4 @@ IMG_OFFSET="" # 8192
IMG_SECTOR="" # 512

# how much will we increase the original image in MB
BASE_IMG_ADDED_SPACE=0 # before: 768
BASE_IMG_ADDED_SPACE=512 # before: 768
249 changes: 126 additions & 123 deletions integration/run.sh
Original file line number Diff line number Diff line change
@@ -1,126 +1,129 @@
#!/bin/bash

# ROOT should be the base directory of this repository.
ROOT=$(pwd)

export CHROOT_DIR=$ROOT/integration/mnt

setup_chroot()
{
teardown_chroot || return 1

# Create chroot directory.
rm -rf "$CHROOT_DIR" || return 1
mkdir -p "$CHROOT_DIR"/{bin,usr/bin,etc,dev,tmp} || return 1

# Copy libraries.
# TODO(evanlinjin): Figure out a way to copy required binaries.
cp -r /{lib,lib64} "$CHROOT_DIR" &> /dev/null
cp -r /usr/{lib,lib64} "$CHROOT_DIR"/usr &> /dev/null

# Copy binaries.
cp -rv /bin/{bash,ls,mkdir,cat} "$CHROOT_DIR/bin" &> /dev/null
cp -rv /usr/bin/{bash,ls,mkdir,cat} "$CHROOT_DIR/usr/bin" &> /dev/null

return 0
}

teardown_chroot()
{
sudo rm -rf "$CHROOT_DIR" || return 1
}

test_skyconf()
{
if ! setup_chroot; then
echo "setup_chroot failed"
return 1
fi

if ! cp -v "$ROOT/bin/skyconf" "$CHROOT_DIR/usr/bin"; then
echo "copying skyconf failed"
return 1
fi

# Create mock device with MBR.
mbr_dev="$CHROOT_DIR/dev/mmcblk0"
touch "$mbr_dev" || return 1

cd "$CHROOT_DIR" || return 1

# Test visor setup.
echo "Testing visor config generation..."
go run "$ROOT/integration/cmd/mock_mbr.go" -m=1 -of="$mbr_dev" || return 1
eval "$(sudo chroot "$CHROOT_DIR" /usr/bin/skyconf)"
cat "$CHROOT_DIR/$LOGFILE" || return 1
cat "$CHROOT_DIR/etc/skywire-visor.json" || return 1


# Test hypervisor setup.
echo "Testing hypervisor config generation..."
go run "$ROOT/integration/cmd/mock_mbr.go" -m=0 -of="$mbr_dev" || return 1
eval "$(sudo chroot "$CHROOT_DIR" /usr/bin/skyconf)"
cat "$CHROOT_DIR/$LOGFILE" || return 1
cat "$CHROOT_DIR/etc/skywire-hypervisor.json" || return 1
cat "$CHROOT_DIR/etc/skywire-hypervisor/key.pem" || return 1
cat "$CHROOT_DIR/etc/skywire-hypervisor/cert.pem" || return 1

# Teardown everything.
teardown_chroot
}

test_skywire_startup()
{
if ! setup_chroot; then
echo "setup_chroot failed"
return 1
fi

if ! cp -v "$ROOT/bin/skyconf" "$CHROOT_DIR/usr/bin"; then
echo "copying skyconf failed"
return 1
fi

if ! cp -v "$ROOT/static/skywire-startup" "$CHROOT_DIR/usr/bin"; then
echo "copying skywire-startup failed"
fi
chmod a+x "$CHROOT_DIR/usr/bin/skywire-startup"

# Create mock device with MBR.
mbr_dev="$CHROOT_DIR/dev/mmcblk0"
touch "$mbr_dev" || return 1

cd "$CHROOT_DIR" || return 1

# Create mock visor and hypervisor.
printf "#!bin/bash\n\necho 'Successfully started visor!'\n" >> "$CHROOT_DIR/usr/bin/skywire-visor" || return 1
chmod a+x "$CHROOT_DIR/usr/bin/skywire-visor" || return 1
printf "#!bin/bash\n\necho 'Successfully started hypervisor!'\n" >> "$CHROOT_DIR/usr/bin/skywire-hypervisor" || return 1
chmod a+x "$CHROOT_DIR/usr/bin/skywire-hypervisor" || return 1

echo "Testing skywire-startup with visor..."
go run "$ROOT/integration/cmd/mock_mbr.go" -m=1 -of="$mbr_dev" || return 1
sudo chroot "$CHROOT_DIR" /usr/bin/skywire-startup || return 1

echo "Testing skywire-startup with hypervisor..."
go run "$ROOT/integration/cmd/mock_mbr.go" -m=0 -of="$mbr_dev" || return 1
sudo chroot "$CHROOT_DIR" /usr/bin/skywire-startup || return 1

# Teardown everything.
teardown_chroot
}

# Magic starts here.

if ! test_skyconf; then
teardown_chroot
exit 1
fi

if ! test_skywire_startup; then
teardown_chroot
exit 1
fi

teardown_chroot
exit 0

# TODO(evanlinjin): This needs to be reimplemented.
## ROOT should be the base directory of this repository.
#ROOT=$(pwd)
#
#export CHROOT_DIR=$ROOT/integration/mnt
#
#setup_chroot()
#{
# teardown_chroot || return 1
#
# # Create chroot directory.
# rm -rf "$CHROOT_DIR" || return 1
# mkdir -p "$CHROOT_DIR"/{bin,usr/bin,etc,dev,tmp} || return 1
#
# # Copy libraries.
# # TODO(evanlinjin): Figure out a way to copy required binaries.
# cp -r /{lib,lib64} "$CHROOT_DIR" &> /dev/null
# cp -r /usr/{lib,lib64} "$CHROOT_DIR"/usr &> /dev/null
#
# # Copy binaries.
# cp -rv /bin/{bash,ls,mkdir,cat} "$CHROOT_DIR/bin" &> /dev/null
# cp -rv /usr/bin/{bash,ls,mkdir,cat} "$CHROOT_DIR/usr/bin" &> /dev/null
#
# return 0
#}
#
#teardown_chroot()
#{
# sudo rm -rf "$CHROOT_DIR" || return 1
#}
#
#test_skyconf()
#{
# if ! setup_chroot; then
# echo "setup_chroot failed"
# return 1
# fi
#
# if ! cp -v "$ROOT/bin/skyconf" "$CHROOT_DIR/usr/bin"; then
# echo "copying skyconf failed"
# return 1
# fi
#
# # Create mock device with MBR.
# mbr_dev="$CHROOT_DIR/dev/mmcblk0"
# touch "$mbr_dev" || return 1
#
# cd "$CHROOT_DIR" || return 1
#
# # Test visor setup.
# echo "Testing visor config generation..."
# go run "$ROOT/integration/cmd/mock_mbr.go" -m=1 -of="$mbr_dev" || return 1
# eval "$(sudo chroot "$CHROOT_DIR" /usr/bin/skyconf)"
# cat "$CHROOT_DIR/$LOGFILE" || return 1
# cat "$CHROOT_DIR/etc/skywire-visor.json" || return 1
#
#
# # Test hypervisor setup.
# echo "Testing hypervisor config generation..."
# go run "$ROOT/integration/cmd/mock_mbr.go" -m=0 -of="$mbr_dev" || return 1
# eval "$(sudo chroot "$CHROOT_DIR" /usr/bin/skyconf)"
# cat "$CHROOT_DIR/$LOGFILE" || return 1
# cat "$CHROOT_DIR/etc/skywire-hypervisor.json" || return 1
# cat "$CHROOT_DIR/etc/skywire-hypervisor/key.pem" || return 1
# cat "$CHROOT_DIR/etc/skywire-hypervisor/cert.pem" || return 1
#
# # Teardown everything.
# teardown_chroot
#}
#
#test_skywire_startup()
#{
# if ! setup_chroot; then
# echo "setup_chroot failed"
# return 1
# fi
#
# if ! cp -v "$ROOT/bin/skyconf" "$CHROOT_DIR/usr/bin"; then
# echo "copying skyconf failed"
# return 1
# fi
#
# if ! cp -v "$ROOT/static/skywire-startup" "$CHROOT_DIR/usr/bin"; then
# echo "copying skywire-startup failed"
# fi
# chmod a+x "$CHROOT_DIR/usr/bin/skywire-startup"
#
# # Create mock device with MBR.
# mbr_dev="$CHROOT_DIR/dev/mmcblk0"
# touch "$mbr_dev" || return 1
#
# cd "$CHROOT_DIR" || return 1
#
# # Create mock visor and hypervisor.
# printf "#!bin/bash\n\necho 'Successfully started visor!'\n" >> "$CHROOT_DIR/usr/bin/skywire-visor" || return 1
# chmod a+x "$CHROOT_DIR/usr/bin/skywire-visor" || return 1
# printf "#!bin/bash\n\necho 'Successfully started hypervisor!'\n" >> "$CHROOT_DIR/usr/bin/skywire-hypervisor" || return 1
# chmod a+x "$CHROOT_DIR/usr/bin/skywire-hypervisor" || return 1
#
# echo "Testing skywire-startup with visor..."
# go run "$ROOT/integration/cmd/mock_mbr.go" -m=1 -of="$mbr_dev" || return 1
# sudo chroot "$CHROOT_DIR" /usr/bin/skywire-startup || return 1
#
# echo "Testing skywire-startup with hypervisor..."
# go run "$ROOT/integration/cmd/mock_mbr.go" -m=0 -of="$mbr_dev" || return 1
# sudo chroot "$CHROOT_DIR" /usr/bin/skywire-startup || return 1
#
# # Teardown everything.
# teardown_chroot
#}
#
## Magic starts here.
#
#if ! test_skyconf; then
# teardown_chroot
# exit 1
#fi
#
#if ! test_skywire_startup; then
# teardown_chroot
# exit 1
#fi
#
#teardown_chroot
#exit 0
7 changes: 5 additions & 2 deletions static/chroot_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ locale-gen en_US.UTF-8

# apt-get commands (install/remove/purge)
# modify and un-comment
info "Updating your system via APT"
export DEBIAN_FRONTEND=noninteractive

apt-get -y update
#apt-get -y install [your_pkgs_here]
#apt-get -y remove --purge [your_pkgs_here]
# keep this on the very end of this block
info "Cleaning apt cache..."
info "Cleaning the APT cache to make a smaller image"
apt-get clean

# forge a time on the system to avoid fs dates are in the future
Expand Down
13 changes: 12 additions & 1 deletion static/skybian-firstrun
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,29 @@ setup_network()
}
setup_network || exit 1

# TODO: Complete this.
for file in /etc/ssh/ssh_host* ; do
echo "[skybian-firstrun] Checking $file:"
cat "$file"
done

# Enable associated service.
case $MD in
"VISOR")
echo "Enabling 'skywire-visor.service'."
systemctl enable skywire-visor.service
sleep 2
systemctl start skywire-visor.service
;;
"HYPERVISOR")
echo "Enabling 'skywire-hypervisor.service'."
systemctl enable skywire-hypervisor.service
sleep 2
systemctl start skywire-hypervisor.service
;;
*)
exit 1
;;
esac

systemctl disable skybian-firstrun.service
exit 0
6 changes: 2 additions & 4 deletions static/skybian-firstrun.service
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
[Unit]
Description=Skybian Firstboot
After=network.target
After=NetworkManager.service
Conflicts=shutdown.target
After=NetworkManager.service network.target armbian-firstrun.service armbian-resize-filesystem.service systemd-user-sessions.service
Wants=NetworkManager.service

[Service]
Type=oneshot
User=root
Group=root
ExecStart=/usr/bin/skybian-firstrun
ExecStartPost=/sbin/reboot

[Install]
WantedBy=multi-user.target

0 comments on commit e300f94

Please sign in to comment.