查看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
将
,保存退出
3 卸载 umount /mnt
4 进入到单用户模式 xm start 虚拟机 -c
5 修改root密码 passwd root
6 exit ,再关闭虚拟机 ---》挂载 ------》编辑启动文件 把 quiet single 改为 console=xvc0 保存退出------》卸载-------》再执行 xm start 虚拟机名称 -c