Skip to content

Commit b549adc

Browse files
andriymoroz-mlnxlguohan
authored andcommitted
[image]: SONiC-to-SONiC update (#464)
1 parent 07bc009 commit b549adc

File tree

8 files changed

+166
-107
lines changed

8 files changed

+166
-107
lines changed

build_debian.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/linux-image-3.16.0-4-amd64_*.de
116116
## Update initramfs for booting with squashfs+aufs
117117
cat files/initramfs-tools/modules | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-tools/modules > /dev/null
118118

119+
IMAGE_VERSION=$(. functions.sh && sonic_get_version)
120+
119121
## Hook into initramfs: change fs type from vfat to ext4 on arista switches
120122
sudo mkdir -p $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/
123+
sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" files/initramfs-tools/arista-convertfs
121124
sudo cp files/initramfs-tools/arista-convertfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs
122125
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs
123126
sudo cp files/initramfs-tools/mke2fs $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs
@@ -195,7 +198,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
195198
iptables-persistent \
196199
logrotate \
197200
curl \
198-
kexec-tools
201+
kexec-tools \
202+
unzip
199203

200204
## Disable kexec supported reboot which was installed by default
201205
sudo sed -i 's/LOAD_KEXEC=true/LOAD_KEXEC=false/' $FILESYSTEM_ROOT/etc/default/kexec

build_image.sh

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then
4545
cp $ONIE_INSTALLER_PAYLOAD $OUTPUT_ABOOT_IMAGE
4646
## Add Aboot boot0 file
4747
j2 -f env files/Aboot/boot0.j2 ./onie-image.conf > files/Aboot/boot0
48+
sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" files/Aboot/boot0
4849
pushd files/Aboot && zip -g $OLDPWD/$OUTPUT_ABOOT_IMAGE boot0; popd
4950
pushd files/Aboot && zip -g $OLDPWD/$ABOOT_BOOT_IMAGE boot0; popd
5051
echo "$IMAGE_VERSION" >> .imagehash

files/Aboot/boot0.j2

+18-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ kernel_params=kernel-params
2525
aboot_machine="arista_unknown"
2626

2727
target_path=/mnt/flash
28+
image_path="$target_path/image-%%IMAGE_VERSION%%"
2829

2930
# expect the swi to be a non empty file
3031
[ -s "$swipath" ] || exit 1
@@ -48,8 +49,10 @@ extract_image() {
4849
fi
4950
done
5051

52+
mkdir "$image_path"
53+
5154
## Unzip the image
52-
unzip -oq "$swipath" -x boot0 -d "$target_path"
55+
unzip -oq "$swipath" -x boot0 -d "$image_path"
5356

5457
## Remove installer swi as it has lots of redundunt contents
5558
rm -f $swipath
@@ -59,19 +62,22 @@ extract_image() {
5962

6063
## vfat does not support symbol link
6164
if [ $rootfs_type != "vfat" ]; then
62-
mkdir -p "$target_path/{{ DOCKERFS_DIR }}"
65+
mkdir -p "$image_path/{{ DOCKERFS_DIR }}"
6366

6467
## extract docker archive
65-
tar xf "$target_path/{{ FILESYSTEM_DOCKERFS }}" -C "$target_path/{{ DOCKERFS_DIR }}"
68+
tar xf "$image_path/{{ FILESYSTEM_DOCKERFS }}" -C "$image_path/{{ DOCKERFS_DIR }}"
6669

6770
## clean up docker archive
68-
rm -f "$target_path/{{ FILESYSTEM_DOCKERFS }}"
71+
rm -f "$image_path/{{ FILESYSTEM_DOCKERFS }}"
6972
else
7073
echo "/mnt/flash is $rootfs_type, extract {{ FILESYSTEM_DOCKERFS }} in later stage"
7174
fi
7275

73-
## replace with boot swi
74-
mv "$target_path/{{ ABOOT_BOOT_IMAGE }}" "$swipath"
76+
## use new reduced-size boot swi
77+
echo "SWI=flash:image-%%IMAGE_VERSION%%/{{ ABOOT_BOOT_IMAGE }}" > "$target_path/boot-config"
78+
79+
## remove original boot swi
80+
rm -f "$swipath"
7581

7682
## sync disk operations
7783
sync
@@ -118,14 +124,14 @@ echo "$append" >/tmp/append
118124
parse_environment_config >>/tmp/append
119125
cat /etc/cmdline | sed "/^\(${bootconfigvars// /\|}\|crashkernel\|loglevel\|ignore_loglevel\)\(\$\|=\)/d;/^\$/d" >>/tmp/append
120126

121-
echo "rw loop=fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor quiet" >>/tmp/append
127+
echo "rw loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor quiet" >>/tmp/append
122128

123129
# process platform specific operations
124130
platform_specific
125131

126132
# use extra parameters from kernel-params hook if the file exists
127-
if [ -f "$target_path/$kernel_params" ]; then
128-
cat "$target_path/$kernel_params" >>/tmp/append
133+
if [ -f "$image_path/$kernel_params" ]; then
134+
cat "$image_path/$kernel_params" >>/tmp/append
129135
fi
130136

131137
# setting root partition if not overridden by kernel-params
@@ -137,15 +143,15 @@ fi
137143

138144
# check the hash file in the image, and determine to install or just skip
139145
GIT_REVISION=$(unzip -p "$swipath" .imagehash)
140-
LOCAL_IMAGEHASH=$(cat $target_path/.imagehash 2>/dev/null || true)
146+
LOCAL_IMAGEHASH=$(cat $image_path/.imagehash 2>/dev/null || true)
141147
if [ "$GIT_REVISION" != "$LOCAL_IMAGEHASH" ]; then
142148
extract_image
143149
write_machine_config
144150
fi
145151

146152
# chainloading using kexec
147-
initrd_path="$target_path/$initrd"
148-
kernel_path="$target_path/$kernel"
153+
initrd_path="$image_path/$initrd"
154+
kernel_path="$image_path/$kernel"
149155
cmdline="$(tr '\n' ' ' </tmp/append)"
150156

151157
kexec --load --initrd="$initrd_path" --append="$cmdline" "$kernel_path"

files/image_config/platform/rc.local

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,27 @@
1515

1616
echo "install platform dependent packages at the first boot time"
1717

18-
if [ -f /host/platform/firsttime ]; then
18+
sonic_version=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
19+
20+
if [ -f /host/image-$sonic_version/platform/firsttime ]; then
1921

2022
if [ -n "$aboot_platform" ]; then
2123
platform=$aboot_platform
2224
elif [ -n "$onie_platform" ]; then
2325
platform=$onie_platform
2426
else
2527
echo "Unknown sonic platform"
26-
rm /host/platform/firsttime
28+
rm /host/image-$sonic_version/platform/firsttime
2729
exit 0
2830
fi
2931

3032
cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/
3133

32-
if [ -d /host/platform/$platform ]; then
33-
dpkg -i /host/platform/$platform/*.deb
34+
if [ -d /host/image-$sonic_version/platform/$platform ]; then
35+
dpkg -i /host/image-$sonic_version/platform/$platform/*.deb
3436
fi
3537

36-
rm /host/platform/firsttime
38+
rm /host/image-$sonic_version/platform/firsttime
3739
fi
3840

3941
exit 0

files/initramfs-tools/arista-convertfs.j2

+5-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ for x in "$@"; do
116116
;;
117117
varlog_size=*)
118118
varlog_size="${x#varlog_size=}"
119+
;;
120+
image_dir=*)
121+
x1="${x#loop=}"
122+
image_dir="${x1%/*}"
119123
esac
120124
done
121125
root_dev="$ROOT"
@@ -191,7 +195,7 @@ cmd="mount -t ext4 $root_dev $root_mnt"
191195
run_cmd "$cmd" "$err_msg"
192196

193197
err_msg="Error: extract docker directory"
194-
cmd="[ -f $tmp_mnt/{{ FILESYSTEM_DOCKERFS }} ] && rm -rf $root_mnt/{{ DOCKERFS_DIR }} && mkdir $root_mnt/{{ DOCKERFS_DIR }} && tar xzf $tmp_mnt/{{ FILESYSTEM_DOCKERFS }} -C $root_mnt/{{ DOCKERFS_DIR }} && rm -f $tmp_mnt/{{ FILESYSTEM_DOCKERFS }}"
198+
cmd="[ -f $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }} ] && rm -rf $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && mkdir -p $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && tar xzf $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }} -C $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && rm -f $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }}"
195199
run_cmd "$cmd" "$err_msg"
196200

197201
err_msg="Error: copying files form $tmp_mnt to $root_mnt failed"

files/initramfs-tools/union-mount.j2

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ case $1 in
66
esac
77

88
## Mount the aufs file system: rw layer over squashfs
9-
mkdir -p ${rootmnt}/host/rw
10-
mount -n -o dirs=${rootmnt}/host/rw:${rootmnt}=ro -t aufs root-aufs ${rootmnt}
9+
image_dir=$(cat /proc/cmdline | sed -e 's/.*loop=\(\S*\)\/.*/\1/')
10+
mkdir -p ${rootmnt}/host/$image_dir/rw
11+
mount -n -o dirs=${rootmnt}/host/$image_dir/rw:${rootmnt}=ro -t aufs root-aufs ${rootmnt}
1112
## Check if the root block device is still there
1213
[ -b ${ROOT} ] || mdev -s
1314
## Mount the raw partition again
1415
mount ${ROOT} ${rootmnt}/host
1516
## Mount the working directory of docker engine in the raw partition, bypass the aufs
1617
mkdir -p ${rootmnt}/var/lib/docker
17-
mount --bind ${rootmnt}/host/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/docker
18+
mount --bind ${rootmnt}/host/$image_dir/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/docker
1819
## Mount the boot directory in the raw partition, bypass the aufs
1920
mkdir -p ${rootmnt}/boot
20-
mount --bind ${rootmnt}/host/boot ${rootmnt}/boot
21+
mount --bind ${rootmnt}/host/$image_dir/boot ${rootmnt}/boot
2122
## Mount loop device for /var/log
2223
[ -f ${rootmnt}/host/disk-img/var-log.ext4 ] && mount -t ext4 -o loop,rw ${rootmnt}/host/disk-img/var-log.ext4 ${rootmnt}/var/log

0 commit comments

Comments
 (0)