【发布时间】:2019-06-09 13:30:10
【问题描述】:
我正在尝试制作一个 bash 脚本,它基本上需要一堆 .deb,解压缩它们并将二进制文件和库放在 /usr/local/opt/{lib}bin 中。
脚本检查 / 是挂载为 ro 还是 rw,如果挂载为 ro 则重新挂载为 rw。 然而,在 chromebook 上,为了将 / 挂载为 rw,您需要为有问题的分区删除_rootfs_verification。当为 / 启用 rootfs_verification 时,脚本无法回显上述内容,应该退出 1,而是继续执行。
这是我所指的脚本部分
### ChromeOS's Specific!!!
# The following assumes rootfs_verification for / has already been removed
if grep $rootfs /proc/mounts | grep ro; then
mount -o remount,rw / &> mount.out
elif
grep -iw 'read-write' mount.out; then
echo '\nrootfs_verification for the root partition must to be removed in order to remount,rw /
To remove rootfs_verification run the following command and than reboot the system:
"sudo /usr/share/vboot/bin/make_dev_ssd.sh --remove_rootfs_verification --partitions 4"'
else exit 1
fi
完整的 WIP 脚本可以在这里找到https://pastebin.com/ekEPSvYy
这就是我执行它时发生的情况
localhost /usr/local # ./kvm_install.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 124 0 124 0 0 322 0 --:--:-- --:--:-- --:--:-- 345
100 135 100 135 0 0 170 0 --:--:-- --:--:-- --:--:-- 170
100 60384 100 60384 0 0 57950 0 0:00:01 0:00:01 --:--:-- 344k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 143 0 143 0 0 407 0 --:--:-- --:--:-- --:--:-- 412
100 154 100 154 0 0 202 0 --:--:-- --:--:-- --:--:-- 202
100 1298k 100 1298k 0 0 929k 0 0:00:01 0:00:01 --:--:-- 3020k
/dev/root / ext2 ro,seclabel,relatime,block_validity,barrier,user_xattr,acl 0 0
./kvm_install.sh: line 31: /etc/env.d/30kvm: Read-only file system
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 66802 100 66802 0 0 69657 0 --:--:-- --:--:-- --:--:-- 74555
./kvm_install.sh: line 39: ar: command not found
tar (child): control.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
md5sum: md5sums: No such file or directory
基本上这里发生的情况是找不到 ar,因为脚本无法将 PATH 变量添加到 /etc/env.d/30kvm,因为根分区无法挂载,因为 / 上启用了 root_verification。
我尝试按照此处的一些建议在 [[ 中添加 elif "grep" 命令,但这不起作用并增加了更多语法问题。
我正在学习 bash 脚本的基础知识。如果剧本写得不好,我深表歉意。
谢谢
我最终还是这样做了。
if grep $rootfs /proc/mounts | grep 'ro,'; then
mount -o remount,rw / &> mount.out
if
grep 'read-write' mount.out; then
echo 'something to echo' && exit 1
fi
fi
它并不漂亮,但在我找到/学习更好的方法来实现循环之前它可以工作。
【问题讨论】:
-
mount.out仅在if部分中创建。如果elif部分中有可供阅读的内容,则它不是直接在上面创建的内容,而是来自您之前成功的if运行。那可不好;-) 我对mount选项做得还不够,无法提供有用的cmets。似乎您理解了这个问题,但我会添加像echo "inside elif"这样的调试语句,这样您就可以确定脚本遵循您期望的路径。祝你好运。 -
还要注意
grep ro将匹配/dev/root / ext2 rw以及/dev/root / ext2 ro -
@shellter 我不完全确定您的意思:“mount.out 仅在 if 部分中创建。如果在 elif 部分中有可供阅读的内容,则不是创建的内容直接在上面,是你之前成功的if run。" 谢谢
-
我应该在评论前加上“基于您提供的代码”,但现在我记得您只包含了部分脚本。在任何情况下,当您在
elif部分检查它时,您的mount.out可能会受到怀疑,因此请确保其中包含最新信息。如果您仍然遇到问题,我认为我的调试想法是您应该从哪里开始。祝你好运。
标签: bash google-chrome-os chromebook