如何在运行overlayroot的系统上更新grub?

我们提供configuration了overlayroot的盒子 ,使用下面的overlayroot.conf:

overlayroot=device:dev=/dev/sda6,timeout=20,recurse=0 

其中产生以下安assembly置:

 $ mount overlayroot on / type overlayfs (rw,errors=remount-ro) /dev/sda5 on /media/root-ro type ext3 (ro,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered) /dev/sda6 on /media/root-rw type ext3 (rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered) /dev/sda1 on /boot type ext3 (rw) 

正如你所看到的,三个关键的物理分区:sda1是/ boot,sda5是一个只读的“工厂”根目录,sda6是一个“用户”根目录,可以随时擦除以将机器恢复到原始出厂状态。

现在,出于任何原因运行update-grub时会出现问题:

 $ sudo update-grub [sudo] password for administrator: /usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?). 

可以理解,因为/是一个overlayfs。

/usr/sbin/update-grub是:

 #!/bin/sh set -e exec grub-mkconfig -o /boot/grub/grub.cfg "$@" 

使用/usr/sbin/grub-mkconfig是事务的一部分。 但实际的问题在/usr/sbin/grub-probe ,由grub-mkconfig调用,而grub-probe是一个二进制文件。

所以我的问题是,是否有一个参数或任何可以使grub-probe在面对/作为overlayfs时做正确的事情? 其次,是否有办法破解/补丁,以便update-grub脚本只是做正确的事情?

谢谢。

我的解决方法:

 #!/bin/bash # Patch grub-mkconfig to not probe / when GRUB_DEVICE is set. cat <<'PATCH' | patch /usr/sbin/grub-mkconfig +++ /usr/sbin/grub-mkconfig 2013-10-28 11:33:15.000000000 -0400 @@ -129,7 +129,7 @@ mkdir -p ${GRUB_PREFIX} # Device containing our userland. Typically used for root= parameter. -GRUB_DEVICE="`${grub_probe} --target=device /`" +GRUB_DEVICE=${GRUB_DEVICE-"`${grub_probe} --target=device /`"} GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true # Device containing our /boot partition. Usually the same as GRUB_DEVICE. -------------------------------- PATCH # Pass the GRUB_DEVICE parameter through sudo echo 'Defaults env_keep +="GRUB_DEVICE"' > /etc/sudoers.d/keep-grub-device chmod 0440 /etc/sudoers.d/keep-grub-device 

现在,将其设置(在bashrc或其他地方)并更新:

 export GRUB_DEVICE=/dev/sda5 sudo update-grub 

绝对不理想,但可能会更糟糕。 将欢迎改进这种方法。

这看起来像一个应该在Grub中修复的bug。 需要学习的是overlayroot的存在,当发现这种情况的时候,需要深入一点才能find真正的根设备。

如果您想在Launchpad中提交错误,并在错误编号中添加注释,我会对其进行分类和优化:

充分披露:我是overlayroot的合着者和共同维护者 。