如何修复导致远程虚拟机上 / 只读的损坏 fstab?

如何修复导致远程虚拟机上 / 只读的损坏 fstab?

我在 AWS ec2 上粘贴多行命令破坏了我的 fstab。

奇迹般地,操作系统仍然启动。输出mount

ec2-user@host:~ $ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=1001720k,nr_inodes=250430,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
/dev/xvda1 on / type xfs (ro,relatime,attr2,inode64,noquota)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=27,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=14220)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=203952k,mode=700,uid=1000,gid=1000)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=203952k,mode=700)

我尝试过的东西:

ec2-user@host:~ $ sudo mount -o remount,rw /dev/xda1 /
Cannot create a temporary file: /var/tmp/scl5pGkRA
ec2-user@host:~ $ sudo remount / rw
Cannot create a temporary file: /var/tmp/sclUmQEPx
ec2-user@host:~ $ sudo mount -o rw,remount /
Cannot create a temporary file: /var/tmp/sclwlQGn3
ec2-user@host:~ $ mount -o rw,remount /
mount: only root can use "--options" option
ec2-user@host:~ $ su root
Password:
su: Authentication failure
ec2-user@host:/tmp $ pkexec mount -o rw,remount /
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/bin/mount' as the super user
Authenticating as: EC2 Default User (ec2-user)
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized

如您所见,没有 root 密码,因此无法su登录。sudo su由于 sudo 想要创建临时文件,所以无法登录。现在怎么办?

答案1

好吧,我没有找到软解决方案。

我必须进入管理控制台,在同一网络中创建一个新的虚拟机,并关闭旧的虚拟机。

转到“卷”并分离 ECB 磁盘。将其重新连接到新的 VM,它将插入/dev/sdf(由于某种原因重命名为 xvdf)。

然后 UUID 相同,因此使用sudo mount --rw -t xfs -o nouuid /dev/xvdf1 somedirectory

使用以下方法修复 fstabsudoedit somedirectory/etc/fstab

卸载、注销、返回管理控制台、关闭新虚拟机。返回“卷”再次分离,然后使用重新连接到旧虚拟机/dev/xvda

重新启动旧虚拟机。已修复。
这需要一个小时:'(真可惜

相关内容