There are two issues with the the "sed" command which is now applied for all distros.
1. After a fix for https://bugs.launchpad.net/diskimage-builder/+bug/1771366 we now have kernel parameters listed twice in GRUB config for Centos. I think the same problem could be seen on other distros but nobody noticed.
The problem is that the "sed" command changes both GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT parameters in /etc/default/grub. But, both these entries are appended by grub2-mkconfig to the end of list of kernel parameters.
For example, with the default value for DIB_BOOTLOADER_DEFAULT_CMDLINE we have in /etc/default/grub
```
# cat /etc/default/grub |grep GRUB_CMDLINE_LINUX
GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto console=ttyS0,115200 nofb nomodeset vga=normal"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200 no_timer_check nofb nomodeset vga=normal"
```
and in /boot/grub2/grub.cfg we have these parameters listed twice for both normal and rescue modes:
```
linux16 /vmlinuz-3.10.0-514.10.2.el7.x86_64 root=LABEL=root ro console=tty0 crashkernel=auto console=ttyS0,115200 nofb nomodeset vga=normal console=tty0 console=ttyS0,115200 no_timer_check nofb nomodeset vga=normal
linux16 /vmlinuz-0-rescue-b7ab9add9a761df2e33b16b2038dbf9c root=LABEL=root ro console=tty0 crashkernel=auto console=ttyS0,115200 nofb nomodese
t vga=normal console=tty0 console=ttyS0,115200 no_timer_check nofb nomodeset vga=normal
```
And the same happens when we use non-default value for DIB_BOOTLOADER_DEFAULT_CMDLINE. For example:
DIB_BOOTLOADER_DEFAULT_CMDLINE="crashkernel=auto rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup"
The result:
```
# cat /etc/default/grub |grep GRUB_CMDLINE_LINUX
GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto console=ttyS1,115200 crashkernel=auto rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200 no_timer_check crashkernel=auto rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup"
```
and in /boot/grub2/grub.cfg we have duplicates again:
```
# grep linux16 /boot/grub2/grub.cfg
linux16 /vmlinuz-3.10.0-514.10.2.el7.x86_64 root=LABEL=root ro console=tty0 crashkernel=auto console=ttyS1,115200 crashkernel=auto rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup console=tty0 console=ttyS0,115200 no_timer_check crashkernel=auto rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup
linux16 /vmlinuz-0-rescue-b7ab9add9a761df2e33b16b2038dbf9c root=LABEL=root ro console=tty0 crashkernel=auto console=ttyS1,115200 crashkernel=auto rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup console=tty0 console=ttyS0,115200 no_timer_check crashkernel=auto rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup
```
2. The second issue is cause by the same "sed" command. If DIB_BOOTLOADER_DEFAULT_CMDLINE contains parameter(s) with a forward slash then the command fails.
For example, with:
DIB_BOOTLOADER_DEFAULT_CMDLINE="crashkernel=auto rd.lvm.lv=vg_root/root rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup"
We have:
```
2018-09-07 15:51:07.221 | + GRUB_CMDLINE_LINUX_DEFAULT='console=tty0 console=ttyS0,115200 no_timer_check'
2018-09-07 15:51:07.221 | + echo 'GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200 no_timer_check"'
2018-09-07 15:51:07.221 | + echo 'GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"'
2018-09-07 15:51:07.221 | + sed -i -e 's/\(^GRUB_CMDLINE_LINUX.*\)"$/\1 crashkernel=auto rd.lvm.lv=vg_root/root rhgb quiet LANG=en_US.UTF-8 biosdevname=1 consoleblank=0 intel_idle.max_cstate=0 iommu=pt mce=ignore_ce net.ifnames=0 nosoftlockup"/' /etc/default/grub
2018-09-07 15:51:07.223 | sed: -e expression #1, char 69: unknown option to `s'
2018-09-07 15:51:07.228 | ++ diskimage_builder/lib/img-functions:run_in_target:59 : check_break after-error run_in_target bash
```
I think the correct fix should be:
- Remove the "sed" command completely and
- replace
echo "GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE_LINUX_DEFAULT}\"" >>/etc/default/grub
with
echo "GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE_LINUX_DEFAULT} ${DIB_BOOTLOADER_DEFAULT_CMDLINE}\"" >>/etc/default/grub