-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[build/onie installer] Install grub for SONiC post migration from another NOS #949
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ if [ ! -e /host/machine.conf ]; then | |
done | ||
fi | ||
|
||
migration="TRUE" | ||
umount /mnt/onie-boot | ||
fi | ||
|
||
|
@@ -76,6 +77,57 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then | |
dpkg -i /host/image-$sonic_version/platform/$platform/*.deb | ||
fi | ||
|
||
# If the unit booted into SONiC from another NOS's grub, we now | ||
# install a grub for SONiC based on ONIE grub. | ||
if [ -n "$onie_platform" ] && [ -n "$migration" ]; then | ||
mkdir -p /host/image-$sonic_version/tmp | ||
cd /host/image-$sonic_version/tmp | ||
|
||
# Extract ONIE's ramdisk which contain's the ONIE grub | ||
mount $onie_dev /mnt/onie-boot | ||
cp /mnt/onie-boot/onie/initrd.img-3.2.69-onie initrd.img-3.2.69-onie.xz | ||
xz -d initrd.img-3.2.69-onie.xz | ||
mv initrd.img-3.2.69-onie initrd.img-3.2.69-onie.cpio | ||
cpio -idv < initrd.img-3.2.69-onie.cpio | ||
cpio_retval=$? | ||
|
||
# Get the device and grub directory to be used for grub-install | ||
sonic_dev=$(blkid | grep SONiC-OS | head -n 1 | awk '{print $1}' | sed -e 's/[0-9]:.*$//') | ||
grub_platform_dir=`find . -name kernel.img -print` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is this file? there is no such file in initrd.img for 3.2.35. |
||
grub_platform_dir=$(dirname "${grub_platform_dir}") | ||
|
||
# Install the grub for SONiC | ||
if [ "$cpio_retval" -eq 0 ] && [ -n "$sonic_dev" ] && [ -n "$grub_platform_dir" ]; then | ||
grub-install --boot-directory=/host --recheck $sonic_dev --directory=/host/image-$sonic_version/tmp/$grub_platform_dir 2>/dev/null | ||
else | ||
echo "Unable install grub" >> /etc/migration.log | ||
fi | ||
|
||
# The SONiC "raw" build mode has already generated a proto grub.cfg | ||
# as part of the migration. Platform specific constants need to be | ||
# retrieved from installer.conf and assigned. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is default value. 9600 ttyS0 for CONSOLE_PORT and dev. If it is the default value, then installer.conf will not have those values. |
||
. /usr/share/sonic/device/$platform/installer.conf | ||
|
||
sed -i -e "s/%%CONSOLE_PORT%%/$CONSOLE_PORT/g" /host/grub.cfg | ||
sed -i -e "s/%%CONSOLE_DEV%%/$CONSOLE_DEV/g" /host/grub.cfg | ||
|
||
# Set the root based on the label | ||
sonic_root=$(blkid | grep SONiC-OS | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//') | ||
sonic_root=$(echo "$sonic_root" | sed 's/\//\\\//g') | ||
sed -i -e "s/%%SONIC_ROOT%%/$sonic_root/g" /host/grub.cfg | ||
|
||
# Add the Diag and ONIE entries | ||
. /mnt/onie-boot/onie/grub.d/50_onie_grub >> /host/grub.cfg | ||
|
||
# Set the SONiC's grub config | ||
mv /host/grub.cfg /host/grub/grub.cfg | ||
|
||
# Cleanup | ||
cd /host/image-$sonic_version | ||
rm -fr /host/image-$sonic_version/tmp | ||
umount /mnt/onie-boot | ||
fi | ||
|
||
rm /host/image-$sonic_version/platform/firsttime | ||
fi | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -423,7 +423,7 @@ else | |
demo_mnt="build_raw_image_mnt" | ||
demo_dev=$cur_wd/"%%OUTPUT_RAW_IMAGE%%" | ||
|
||
mkfs.ext4 $demo_dev | ||
mkfs.ext4 -L $demo_volume_label $demo_dev | ||
|
||
echo "Mounting $demo_dev on $demo_mnt..." | ||
mkdir $demo_mnt | ||
|
@@ -484,8 +484,13 @@ trap_push "rm $grub_cfg || true" | |
|
||
[ -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" | ||
if [ "$install_env" = "build" ]; then | ||
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" | ||
else | ||
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" | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep the original lines, here. In the rc.local, there the installer.conf override, then change the PORT and SPEED accordingly, otherwise, do not change. |
||
GRUB_SERIAL_COMMAND=${GRUB_SERIAL_COMMAND:-"$DEFAULT_GRUB_SERIAL_COMMAND"} | ||
GRUB_CMDLINE_LINUX=${GRUB_CMDLINE_LINUX:-"$DEFAULT_GRUB_CMDLINE_LINUX"} | ||
export GRUB_SERIAL_COMMAND | ||
|
@@ -535,6 +540,12 @@ if [ "$install_env" = "sonic" ]; then | |
onie_menuentry=$(cat /host/grub/grub.cfg | sed "/menuentry ONIE/,/}/!d") | ||
fi | ||
|
||
if [ "$install_env" = "build" ]; then | ||
grub_cfg_root=%%SONIC_ROOT%% | ||
else | ||
grub_cfg_root=$demo_dev | ||
fi | ||
|
||
cat <<EOF >> $grub_cfg | ||
menuentry '$demo_grub_entry' { | ||
search --no-floppy --label --set=root $demo_volume_label | ||
|
@@ -543,7 +554,7 @@ menuentry '$demo_grub_entry' { | |
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi | ||
insmod part_msdos | ||
insmod ext2 | ||
linux /$image_dir/boot/vmlinuz-3.16.0-4-amd64 root=$demo_dev rw $GRUB_CMDLINE_LINUX \ | ||
linux /$image_dir/boot/vmlinuz-3.16.0-4-amd64 root=$grub_cfg_root rw $GRUB_CMDLINE_LINUX \ | ||
loop=$image_dir/$FILESYSTEM_SQUASHFS loopfstype=squashfs \ | ||
apparmor=1 security=apparmor varlog_size=$VAR_LOG_SIZE $ONIE_PLATFORM_EXTRA_CMDLINE_LINUX | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the rc.local, you also need to replace the VAR_LOG_SIZE in case the VAR_LOG_SIZE is overriden in the installer.conf |
||
echo 'Loading $demo_volume_label $demo_type initial ramdisk ...' | ||
|
@@ -564,6 +575,7 @@ EOF | |
fi | ||
|
||
if [ "$install_env" = "build" ]; then | ||
cp $grub_cfg $demo_mnt/grub.cfg | ||
umount $demo_mnt | ||
else | ||
cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcoding onie kernel version does not sound a good design. this puts the sonic installation process highly dependent on the onie installer we have in the box. In the future, you may ship a ftos box with newer onie, then this will break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for example, on my box the onie is initrd.img-3.2.35-onie