徒涉春冰

导航

xen 虚机丢失密码/ssh配置错误无法登陆解决方案

今天发现一个古老的虚机ssh登陆不了,root密码也没人记得了(早前都是通过key上去的),重启虚机发现sshd配置文件错误,无法启动服务,用key当然上不去了。天下能有什么事难住我们技术宅。放狗搜之,遂解决。主要参考下面这篇文章。

Mounting Individual Parititons in RAW Disk Images

Let us say, for the sake of simplicity, that you backup whole disks by using dd in Linux. Now let us assume that you need just a single file out of a backup and do not want to (or can not realistically) restore the whole backup to disk for the single file. You can not mount -o loop because the backup does not contain a single partition. “What to do” you ask? Well I will tell you, wary traveler.

Mount your raw disk image as a loopback device: losetup /dev/loop0 [path to image]
Run kpartx and: kpartx -va /dev/loop0
This will add your partitions to /dev/mapper/loop0pX where each X is a different partition
You can now mount each partition: mount /dev/mapper/loop0pX /media/partition
If you want to make sure you do not write anything to your backup simply mount it as read-only: mount -o ro /dev/mapper/loop0pX /media/partition
Once you are finished you will need to do your clean up.

挂载boot分区,修改grub配置文件,重启虚机进单用户模式,修改root密码,修改sshd配置文件,再重启,问题解决。

Unmount: umount /media/partition
Remove the mapper devices: kpartx -d /dev/loop0
Remove the loopback device: losetup -d /dev/loop0
These commands may all need to be run as root. If loop0 reports that it is busy just pick another loop device (/dev/loop1, ect).

posted on 2013-02-04 12:01  徒涉春冰  阅读(466)  评论(0编辑  收藏  举报