Linux 使用sed将grub条目中的根参数替换为分区号
我有下面的grub.cfgLinux 使用sed将grub条目中的根参数替换为分区号,linux,sed,grub,Linux,Sed,Grub,我有下面的grub.cfg # Automatically created by OE serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 default=boot timeout=10 menuentry 'boot'{ linux /bzImage LABEL=boot root=/dev/ram0 rootwait console=ttyS0,115200 console=tty0 initrd /initrd }
# Automatically created by OE
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
default=boot
timeout=10
menuentry 'boot'{
linux /bzImage LABEL=boot root=/dev/ram0 rootwait console=ttyS0,115200 console=tty0
initrd /initrd
}
menuentry 'install'{
linux /bzImage LABEL=install-efi root=/dev/ram0 rootwait console=ttyS0,115200 console=tty0
initrd /initrd
}
我需要用它的UUID替换root
root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs})
swupdate_part_uuid=$(blkid -o value -s PARTUUID ${swupdatefs})
当我执行以下sed命令时,它将用相同的值替换两个根参数,我需要用以下值替换第一个根参数
sed -i "s/ root=[^ ]*/ root=PARTUUID=$root_part_uuid rw $rootwait quiet " grub.cfg
swupdate\u part\u uuid.的第二个根参数。。我怎样才能做到这一点呢?你想要什么还不清楚。预期的输出是什么?我需要用blkid命令生成的两个不同uuid替换两个根字符串。。当前两个根都指向/dev/ram0如果您只想替换
LABEL=boot
部分,那么只需执行以下操作:sed-i”/LABEL=boot/s/root=[^]*/root=PARTUUID=$root\u part\u uuid rw$rootwait quiet”grub.cfg
我在执行上述命令时遇到以下错误:unterminated's'commandsorry在最后一个“
之前添加一个/
,它应该是:sed-I”/LABEL=boot/s/root=[^]*/root=PARTUUID=$root\u part uuid rw$rootwait quiet/“grub.cfg