文档
Amazon EC2 / TurnKey Hub - 修复 grub 靴子问题 / 恢复根密码
在VM(或裸金属安装)上,可以使用活的ISO来修复许多grub,内核和其他相关的问题(如丢失的根存取). 但在AWS上,这不是一个选项. 然而,可以将根音量从一个服务器附到另一个服务器,使您有一个类似环境来修复许多grub, boot和相关问题. 本页面概述了如何通过Hub,AWS控制台和SSH会话来完成这项工作.
具体步骤 -- -- 包括命令
我使用服务器标签 OLD 和 NEW 分别表示原始(损坏)服务器和新的临时服务器.
如前所述,这些步骤应在“ Hub” 或“ AWS 控制台” 内完成。 命令全部要在 NEW 服务器的 shell 内执行( 通过 SSH 会话) 。
- 汉普顿: 在区域内启动 NEW 服务器 与服务器损坏的相同可用区。这可以是任意的 应用设备 或大小,例如 t2. 微芯是好的 - 但必须是在同一可用区!
- 汉普顿: 停止 OLD 服务器 。
- AWS控制台 : OLD停止后,将根卷拆解.
- AWS控制台 : 将 (OLD) 根卷附加到 NEW (作为第二卷)。 当请求挂载点时, 使用
/dev/sdf. - 登录到 NEW 中通过 SSH : 使用下列命令设置一个chroot并输入:
# check that the OLD server volume is attached as /dev/xvdf: gdisk -l /dev/xvdf # Assuming OLD server volume is /dev/xvdf, mount it and chroot in: mkdir /mnt2 mount /dev/xvdf2 /mnt2 mount --bind /dev /mnt2/dev mount --bind /proc /mnt2/proc mount --bind /sys /mnt2/sys chroot /mnt2
- SSH - 执行chroot中的固定 : 假设成功没有出错, 您现在处于您的 OLD 服务器卷的chroot 中。 您接下来要做什么取决于您想要处理的问题 。 我注意到一些与启动问题和重设根密码有关的可能办法:
# optional: update kernel
apt-get update
apt-get install linux-image-$(dpkg --print-architecture)
apt-get install linux-image-$(uname -r)
# optional: regenerate initramfs (will be run automatically if the kernel is updated)
update-initramfs -u
# Note: as part of the initramfs regeneration process (whether via updating the
# kernel, or manually regenerating) it is expected and normal to see the
# following errors/warnings:
#
# /usr/share/initramfs-tools/scripts/casper-bottom/25autologin: 13: .: Can't open /scripts/casper-functions
# /usr/share/initramfs-tools/scripts/casper-bottom/25singleuser_shell: 6: .: Can't open /scripts/casper-functions
# /usr/share/initramfs-tools/scripts/casper-bottom/25ssh_emptypw: 6: .: Can't open /scripts/casper-functions
# To avoid adding grub boot entries for the host machine (i.e. the NEW server), disable the OS prober
# (note os-prober has no value other than on dual boot machines)
chmod a-x /etc/grub.d/30_os-prober
# reinstall grub2
grub-install --boot-directory=/boot /dev/xvdf
update-grub
# reset root password
passwd root
# add a public SSH key
echo "_keytype_ _public_key_data_ _email_" >> /root/.ssh/authorized_keys
# IMPORTANT: replace "_keytype_ _public_key_data_ _email_" with the contents of your public key.
# email is optional but highly recommended
# 您可以做其他工作, 如检查日志或按要求安装额外软件包 。- SSH - Unmount OLD volume: 希望一切都好,你不会出错,假设这样,离开车厢,卸下一切:
# exit and tidy up exit umount /mnt2/dev umount /mnt2/proc umount /mnt2/sys umount /mnt2
- AWS控制台 : 从 NEW 解析 OLD 根卷, 并重析到原始服务器( OLD )。 指定附件点为
/dev/xvda. - 汉普顿: 靴子 OLD - 手指交叉了它, 现在会踢出它! 如果这样棒的话! 如果不行, 请重复步骤 2 - 8 尝试在chroot(步骤 6) 内的一些不同步骤 。