One of the best references for getting started using virtual machines using XEN and CentOS can be found here. It is well written, very easy to follow and can quickly get you up and running.
Recently I had the task of revisiting a virtual machine that was provisioned with a file based file system as outlined in the tutorial. The main task I needed to achieve was to expand the size of the filesystem. Given that the tutorial has you build the virtual machine using tools that have this capability I figured it would not be that hard.
What is not obvious is that although the filesystem is made in such a way as to easily support this, that the actual practice of making it happen is a little more complicated. Having spent a lot of time googling all the various technologies and not coming up with a solution, I thought I would share what I learned, and give a recipe to perform the same operation on your own virtual server. All the usual caveats apply (use at your own risk, etc.)
If you are attempting to do something similar, or you are using a different Linux distribution it still may be useful to look at the following, and translate the steps accordingly.
Here is the recipe, feel free to let me know if it works for you:
1. Shutdown the VM
2. Backup the disk image file:
cp /xen/client8.img /xen/client8.img.backup
3. Restart the VM so that it can continue to serve while we work
4. Okay now make a working image from the backup:
cp client8.img.backup client8ext.img
5. Use dd to append more space to the end of the file:
dd if=/dev/zero of=/xen/client8xen.img bs=1M seek=10000 count=5000
This assumes an initial filesystem that is 10G and is expanding it to 15G
6. Check to see that the disk image file has grown the correct amount
ls -l /xen/client8ext.img
Should look something like
-rw-r–r– 1 root root 15728640000 Oct 26 02:22 client8ext.img
7. Mount the disk image on the loopback device:
/sbin/losetup /dev/loop1 /xen/client8ext.img
Here I am mounting it on loop1 because my initial loop0 was already in use. Just make sure that you mount it on an unused loop device and you should be fine.
Check that it has mounted okay:
/sbin/fdisk -l -u /dev/loop1
Should look something like:
Disk /dev/loop1: 15.7 GB, 15728640000 bytes
255 heads, 63 sectors/track, 1912 cylinders, total 30720000 sectors
Units = sectors of 1 * 512 = 512 bytesDevice Boot Start End Blocks Id System
/dev/loop1p1 * 63 208844 104391 83 Linux
/dev/loop1p2 208845 20466809 10128982+ 8e Linux LVM
7. Find the start of the primary root partition. In the above example the LVM partition starts at 208845. Use the following formula to find the offset in the file where the LVM starts.
START * 512
8. Mount the volume group using the -o parameter and the calculated start value:
/sbin/losetup -o 106928640 /dev/loop2 /dev/loop1
9. Edit lvm.conf to filter out any other devices. If you are not actively using lvm on your working server it may be easy enough to just filter out everything but the loop devices. and return it back after you have finished. Here is a good reference on how to do this. In the end I just ended up changing the filter setting to
filter = [ "a/loop.*/", "r/.*/" ]
10. Rerun vgscan and check that it finds the volumes
/sbin/vgscan
You should see something like:
Reading all physical volumes. This may take a while…
Found volume group “VolGroup00″ using metadata type lvm2
11. Okay now to resize the physical volume. Check to see that you can see it:
/usr/sbin/pvdisplay
Should get something like:
— Physical volume —
PV Name /dev/loop2
VG Name VolGroup00
PV Size 9.66 GB / not usable 3.58 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 309
Free PE 0
Allocated PE 309
PV UUID IUefv0-aFx9-iPQn-p2nb-VOGO-ioQo-4XsfUc
12. Okay now to resize the physical volume:
/usr/sbin/pvresize /dev/loop2
Check that it worked:
/usr/sbin/pvdisplay
Output should now look something like:
— Physical volume —
PV Name /dev/loop2
VG Name VolGroup00
PV Size 14.55 GB / not usable 17.84 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 465
Free PE 156
Allocated PE 309
PV UUID IUefv0-aFx9-iPQn-p2nb-VOGO-ioQo-4XsfUc
13. Now to resize the logical volumes:
/usr/sbin/lvdisplay
Should get something like:
— Logical volume —
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID 4vMcGJ-jOdo-idMa-Q3qR-31Hg-YKHs-2ppTQA
LV Write Access read/write
LV Status NOT available
LV Size 9.16 GB
Current LE 293
Segments 1
Allocation inherit
Read ahead sectors 0— Logical volume —
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID wRtiQA-dZX1-fKI0-4yv2-FfPw-0F3C-8RThgX
LV Write Access read/write
LV Status NOT available
LV Size 512.00 MB
Current LE 16
Segments 1
Allocation inherit
Read ahead sectors 0
14. Start by extending the swap space:
/usr/sbin/lvextend -L +512M /dev/VolGroup00/LogVol01
Then extend the root partition. Let’s use all available space this time.
Look up free extents:
/usr/sbin/vgdisplay
Get Something like:
— Volume group —
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 14.53 GB
PE Size 32.00 MB
Total PE 465
Alloc PE / Size 325 / 10.16 GB
Free PE / Size 140 / 4.38 GB
VG UUID ecCfkb-oPKd-Tf4S-VTLj-2M9c-LJJj-BHBPh2
15. Free extents are 140. Use this to extend the root partition:
/usr/sbin/lvextend -l+140 /dev/VolGroup00/LogVol00
16. Activate the root logical volume so that we can resize it:
/usr/sbin/lvchange -ay /dev/VolGroup00/LogVol00
17. Now we need to resize the file system. The docs I found suggest that you run a filesystem check both before and after you have resized the partiion:
/sbin/e2fsck -f /dev/VolGroup00/LogVol00
/sbin/resize2fs /dev/VolGroup00/LogVol00
Check the filesystem again:
/sbin/e2fsck -f /dev/VolGroup00/LogVol00
18. Okay now deactivate the root partition:
/usr/sbin/lvchange -an /dev/VolGroup00/LogVol00
19. Activate the swap partition:
/usr/sbin/lvchange -ay /dev/VolGroup00/LogVol01
20. Run mkswap on the extended swap partition:
/sbin/mkswap /dev/VolGroup00/LogVol01
21. Everything okay, now deactivate it again:
/usr/sbin/lvchange -an /dev/VolGroup00/LogVol01
22. Change the size of the LVM partition on /dev/loop1 using fdisk. This step caught me out. The disk partition information needs to be updated to reflect the new LVM size. Just launch fdisk and find the last partition. Then change it to reflect the full size of the drive.
fdisk /dev/loop1
fdisk>d
fdisk>2
fdisk>n
fdisk>2
fdisk>enter
fdisk>enter
fdisk>w
23. Deactivate the loop devices:
/sbin/losetup -d /dev/loop2
/sbin/losetup -d /dev/loop1
Your file based filesystem should now be ready to use with your current virtual machine. Change the appropriate line in your server’s XEN configuration and restart your server and enjoy!
相关推荐
xen guest 配置文件,作为参考,方便 大家搭建环境
基于centos操作系统的xen安装文档,基于centos操作系统的xen安装文档,基于centos操作系统的xen安装文档
本文是自己所学课程做的一个实验,基于Xen实现Apache及tomcat集群,并进行session测试。首先你要自己已经安装好Xen及虚拟机。
xen虚拟镜像的启动配置文件(样本) 其中对每一个项目都有详细说明.
请与installXen_linux-2.6.31.8+xen-4.1.2.sh.txt配合使用.....
Ubuntu_12.04上安装基于Xen的虚拟机.pdf 虚拟机的安装的详细步骤
用于qemu vexpress-a15启动xen Dom0 FreeRTOS文件
在xen环境下domain0与domainU之间虚拟驱动样例代码;使用方法如下: 1)在domain0中编译domain0代码 并使用insmod命令进行安装驱动 2)在domainU中编译domainU代码以及应用app 3)在domainU中insmod安装domainU驱动 4)...
xen 4.0 最新源码xen 4.0 最新源码xen 4.0 最新源码
主要介绍基于Redhat Enterprise Linux AS 5 的XEN安装与配置.Xen是一个基于虚拟硬件监控器技术的虚拟化软件。Xen运行在一个宿主linux系统上,提供同时引导启动多个linux实例的能力.
Citrix Xen 使用称为“XVA”的自定义虚拟设备格式进行导入/导出。它基本上是一个制作奇特的 tar 文件。你不需要这个程序来解压这个 tar 文件,只需使用你最喜欢的 tar 解压器(tar、gtar、bsdtar)。解压后,您将...
ubuntu下安装xen的脚本 放在这里备份
XEN4.0内核编译XEN4.0内核编译XEN4.0内核编译XEN4.0内核编译XEN4.0内核编译XEN4.0内核编译XEN4.0内核编译XEN4.0内核编译
用shell脚本来实现xen虚拟机的创建、启动、删除等操作
Memory CoW in Xen xen memory cow 介绍
基于Xen的路由器虚拟化研究与设计,郑军,马跃,传统的路由器架构中,在软件功能、安全性、设备性能等方面有着良好的表现。但是每个应用环境通常都需要按最大的负载来构建,如何
基于i.MX8虚拟化Xen方案的Linux双系统设计
在不断涌现出的虚拟化解决方案中,开源解决方案Xen以其独特的虚拟化设计模式,以及接近单机操作系统的性能被学术界和工业界广泛看好,被认为是未来最有前途的虚拟化解决方案之一。, 《Xen虚拟化技术》以Xen 3.1.0...
Xen是一个基于虚拟硬件监控器技术的虚拟化软件。Xen运行在一个宿主linux系统上,提供同时引导启动多个linux实例的能力。每个由Xen生成的虚拟机,被称为domain 。新创建的domain需要为其安装一个操作系统,方可引导并...
在linux下安装及配置XEN2.0的详细过程包括截图。推荐在vmware下使用XEN。