博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
破解Xen虚拟机密码
阅读量:2387 次
发布时间:2019-05-10

本文共 2816 字,大约阅读时间需要 9 分钟。

查看Xen镜像文件的位置:

more /etc/xen/selboo

virsh edit IM-243.35


找到类似以下一句话:
disk = ['file:/opt/disk/selboo.img,sda1,w']
说明 镜像文件的位置在 /opt/disk/selboo.img

<source file='/xen/hardDisk/IM-243.35.img'/>


关闭虚拟机:
xm  shutdown selboo

2.进行挂载镜像文件:
首先查看文件基本信息:
fdisk /xen/hardDisk/IM-243.35.img -l  #得知此镜像的簇大小为512
sfdisk -d /xen/hardDisk/IM-243.35.img

/opt/disk/selboo.img1 : start=       63, size=   208782, Id=83, bootable
/opt/disk/selboo.img2 : start=   208845, size= 16563015, Id=8e
/opt/disk/selboo.img3 : start=        0, size=        0, Id= 0
/opt/disk/selboo.img4 : start=        0, size=        0, Id= 0 
上述结果可以得知,簇的起始位置在63!

mount -o loop,offset=$((63*512)) /xen/hardDisk/IM-243.30.img /mnt

3.修改镜像文件的grub 修改为直接启动sh
     kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet  single  #单用户模式进入

        initrd /initrd-2.6.18-92.el5.img

取消挂载,umount /mnt

4.重新启动虚拟机:
       xm create selboo
5.修改密码:
passwd root
修改密码后,关闭虚拟机。
6.再次挂载镜像后,去除grub中  single 这句话。
7.重新启动虚拟机!OK

也可以直接挂在 跟 "/" 修改 /etc/shadow 即可



具体执行 virsh edit 虚拟机名 找到 虚拟机的镜像文件位置 ,即 img的位置



<domain type='xen' id='1'>

  <name>IM-TJ01-175.207</name>

  <uuid>b39f7d38-cb87-ac63-728e-56d1eb90a763</uuid>

  <memory>4096000</memory>

  <currentMemory>4096000</currentMemory>

  <vcpu>4</vcpu>

  <bootloader>/usr/bin/pygrub</bootloader>

  <bootloader_args>-q</bootloader_args>

  <os>

    <type>linux</type>

  </os>

  <clock offset='utc'/>

  <on_poweroff>destroy</on_poweroff>

  <on_reboot>restart</on_reboot>

  <on_crash>restart</on_crash>

  <devices>

    <disk type='file' device='disk'>

      <driver name='file'/>

      <source file=''/>

      <target dev='xvda' bus='xen'/>

    </disk>

    <interface type='bridge'>

      <mac address='00:16:3e:06:7a:d9'/>

      <source bridge='xenbr0'/>

      <script path='/etc/xen/scripts/vif-bridge'/>

      <target dev='vif1.0'/>

    </interface>

    <interface type='bridge'>

      <mac address='00:16:3e:63:a7:97'/>

      <source bridge='xenbr1'/>

      <script path='/etc/xen/scripts/vif-bridge'/>

      <target dev='vif1.1'/>

    </interface>

    <console type='pty'>

      <target port='0'/>

    </console>

 </devices>

</domain>  


1  首先关闭虚拟机  

 xm shutdown 虚拟机名字

2  挂载 

mount -o loop,offset=$((63*512)) /xen/hardDisk/IM-243.35.img /mnt


3  编辑启动文件 

   vim /mnt/grub/menu.lst

 

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE:  You have a /boot partition.  This means that

#          all kernel and initrd paths are relative to /boot/, eg.

#          root (hd0,0)

#          kernel /vmlinuz-version ro root=/dev/xvda3

#          initrd /initrd-version.img

#boot=/dev/xvda

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title Red Hat Enterprise Linux AS (2.6.9-78.ELxenU)

        root (hd0,0)

        kernel /vmlinuz-2.6.9-78.ELxenU ro root=LABEL=/  console=xvc0这里改为quiet single

        initrd /initrd-2.6.9-78.ELxenU.img


将 

 ,保存退出 

   卸载                      umount /mnt


4    进入到单用户模式            xm start 虚拟机 -c


5  修改root密码 passwd root 


6  exit ,再关闭虚拟机 ---》挂载 ------》编辑启动文件  把 quiet single 改为 console=xvc0 保存退出------》卸载-------》再执行  xm start 虚拟机名称 -c

转载地址:http://risab.baihongyu.com/

你可能感兴趣的文章
Linux常用C函数open和read以及write的使用说明
查看>>
几个字符串转数字的函数
查看>>
Linux Shell及常用命令简介
查看>>
Java的注释规范整理
查看>>
Java注释的写法
查看>>
Linux模块编程
查看>>
Linux内核模块编程
查看>>
初探Linux 2.6 内核--第一个内核模块
查看>>
Linux内核模块编程入门
查看>>
Linux 2.6.xx 内核模块编程入门
查看>>
linux-2.6 内核模块编程探索
查看>>
C/C++ 通用 Makefile
查看>>
2.6内核Makefile简单语法与应用
查看>>
C++强制转换
查看>>
c++强制转换的分析
查看>>
Eclipse中插件的安装
查看>>
使用 /proc 文件系统来访问 Linux 内核的内容
查看>>
syscall调用接口从2.6.19开始移到应用层
查看>>
Linux内核模块使用指南
查看>>
lex入门
查看>>