`

How to Convert An Image-Based Guest To An LVM-Based Guest

阅读更多

Xen: How to Convert An Image-Based Guest To An LVM-Based Guest

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 03/09/2009

This short article explains how you can move/convert a Xen guest that uses disk images to LVM volumes. Virtual machines that use disk images are very slow and heavy on disk IO, therefore it's often better to use LVM. Also, LVM-based guests are easier to back up (using LVM snapshots ).

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

To use LVM-based guests, you need a volume group that has some free space that is not allocated to any logical volume. In this example, I use the volume group /dev/vg0 with a size of approx. 465GB...

vgdisplay

server1:~# vgdisplay
  --- Volume group ---
  VG Name               vg0
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               465.28 GB
  PE Size               4.00 MB
  Total PE              119112
  Alloc PE / Size       59842 / 233.76 GB
  Free  PE / Size       59270 / 231.52 GB
  VG UUID               gnUCYV-mYXj-qxpM-PEat-tdXS-wumf-6FK3rA

server1:~#

... that contains the logical volume /dev/vg0/root with a size of approx. 232GB and the logical volume /dev/vg0/swap_1 (about 1GB) - the rest is not allocated and can be used for Xen guests:

lvdisplay

server1:~# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg0/root
  VG Name                vg0
  LV UUID                kMYrHg-d0ox-yc6y-1eNR-lB2R-yMIn-WFgzSZ
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                232.83 GB
  Current LE             59604
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

  --- Logical volume ---
  LV Name                /dev/vg0/swap_1
  VG Name                vg0
  LV UUID                SUI0uq-iTsy-7EnZ-INNz-gjvu-tqLD-rGSegE
  LV Write Access        read/write
  LV Status              available
  # open                 2
  LV Size                952.00 MB
  Current LE             238
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:1

server1:~#

<script type="text/javascript"> &lt;!-- document.write('&lt;div align=&quot;center&quot;&gt;'); //--&gt; </script>
<!-- begin ad tag Rectangle B --> <script type="text/javascript"> if (typeof ord=='undefined') {ord=Math.random()*10000000000000000;} document.write('&lt;script language=&quot;JavaScript&quot; src=&quot;http://a.collective-media.net/adj/idgt.howtoforge.en/article_above;sec=article;fold=above;tile=3;sz=300x250;ord=' + ord + '?&quot; type=&quot;text/javascript&quot;&gt;&lt;\/script&gt;'); </script><script src="http://a.collective-media.net/adj/idgt.howtoforge.en/article_above;sec=article;fold=above;tile=3;sz=300x250;ord=6093188042843771?" type="text/javascript"></script><script src="http://a.collective-media.net/cmadj/idgt.howtoforge.en/article_above;tile=3;fold=above;sec=article;sz=300x250;ord=6093188042843771;ord1=44781;cmpgurl=http%253A//www.howtoforge.com/xen-how-to-convert-an-image-based-guest-to-an-lvm-based-guest?"></script><script type="text/javascript">document.write('&lt;scr'+'ipt language=&quot;javascript&quot; src=&quot;http://ad.doubleclick.net/adj/idgt.howtoforge.en/article_above;net=idgt;u=idgt-87683997_1257068512,110ff3a0448ae86,virtualization,;;tile=3;ord1=44781;fold=above;sec=article;sz=300x250;contx=virtualization;btg=;ord=6093188042843771?&quot;&gt;&lt;/scr'+'ipt&gt;');</script><script>CollectiveMedia.createAndAttachAd(&quot;idgt-87683997_1257068512&quot;, &quot;http://ad.doubleclick.net/adj/idgt.howtoforge.en/article_above;net=idgt;u=idgt-87683997_1257068512,110ff3a0448ae86,virtualization,;;tile=3;ord1=44781;fold=above;sec=article;sz=300x250;contx=virtualization;btg=;ord=6093188042843771?&quot;,&quot;300&quot;,&quot;250&quot;);</script><script src="http://ad.doubleclick.net/adj/idgt.howtoforge.en/article_above;net=idgt;u=idgt-87683997_1257068512,110ff3a0448ae86,virtualization,;;tile=3;ord1=44781;fold=above;sec=article;sz=300x250;contx=virtualization;btg=;ord=6093188042843771?"></script><!-- AMG Tag 300x250 --><script src="http://cdn.amgdgt.com/base/js/v1/amgdgt.js" type="text/javascript"></script><script src="http://ad.amgdgt.com/ads/?t=i&amp;f=j&amp;p=2388&amp;pl=d5b49f4b&amp;rnd=48919001670101370" type="text/javascript"></script><!-- EC_TYPE_1 AG --> Click Here! <noscript>&lt;a href="http://ad.amgdgt.com/ads/?t=c&amp;c=bJXNdH" target="_blank"&gt;&lt;img src="http://ad.amgdgt.com/ads/?t=i&amp;f=h&amp;p=2388&amp;pl=d5b49f4b&amp;c=bJXNdH&amp;rnd=3362199" width="300" height="250" border="0" /&gt;&lt;/a&gt;</noscript> <noscript>&lt;a href="http://a.collective-media.net/jump/idgt.howtoforge.en/article_above;sec=article;fold=above;tile=3;sz=300x250;ord=123456789?" target="_blank"&gt;&lt;img src="http://a.collective-media.net/ad/idgt.howtoforge.en/article_above;sec=article;fold=above;tile=3;sz=300x250;ord=123456789?" width="300" height="250" border="0" alt=""&gt;&lt;/a&gt;</noscript> <!-- End ad tag Rectangle B --> <script type="text/javascript"> &lt;!-- document.write('&lt;/div&gt;'); //--&gt; </script>

I have an image-based Xen guest called xen1.example.com that I created using the following command:

xen-create-image --hostname=xen1.example.com --size=4Gb --swap=256Mb --ip=192.168.0.101 --memory=128Mb --arch=amd64 --role=udev

This is its Xen configuration file:

vi /etc/xen/xen1.example.com.cfg

#
# Configuration file for the Xen instance xen1.example.com, created
# by xen-tools 3.9 on Mon Mar  9 19:22:40 2009.
#

#
#  Kernel + memory size
#
kernel      = '/boot/vmlinuz-2.6.26-1-xen-amd64'
ramdisk     = '/boot/initrd.img-2.6.26-1-xen-amd64'
memory      = '128'

#
#  Disk device(s).
#
root        = '/dev/xvda2 ro'
disk        = [
                  'file:/home/xen/domains/xen1.example.com/swap.img,xvda1,w',
                  'file:/home/xen/domains/xen1.example.com/disk.img,xvda2,w',
              ]


#
#  Hostname
#
name        = 'xen1.example.com'

#
#  Networking
#
vif         = [ 'ip=192.168.0.101,mac=00:16:3E:F2:DC:FA' ]

#
#  Behaviour
#
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

As you see, the guest is using two disk images, /home/xen/domains/xen1.example.com/disk.img (4GB) and /home/xen/domains/xen1.example.com/swap.img (256MB).

We need the exact image sizes so that we can create logical volumes of the same size. If you don't remember the exact disk and swap sizes anymore, you can go to the directory where the images are stored...

cd /home/xen/domains/xen1.example.com

... and run the following command - it will show the image sizes in human-readable format:

ls -lh

 

2 Converting The Images To LVM

Before we convert the images, we must shut down the guest:

xm shutdown xen1.example.com

Then we create logical volumes of the same size as the disk images, e.g. as follows:

lvcreate -L4G -n xen1_root vg0
lvcreate -L256M -n xen1_swap vg0

This creates the logical volumes /dev/vg0/xen1_root (4GB) and /dev/vg0/xen1_swap (256MB):

lvdisplay

server1:~# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg0/root
  VG Name                vg0
  LV UUID                kMYrHg-d0ox-yc6y-1eNR-lB2R-yMIn-WFgzSZ
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                232.83 GB
  Current LE             59604
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

  --- Logical volume ---
  LV Name                /dev/vg0/swap_1
  VG Name                vg0
  LV UUID                SUI0uq-iTsy-7EnZ-INNz-gjvu-tqLD-rGSegE
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                952.00 MB
  Current LE             238
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:1

  --- Logical volume ---
  LV Name                /dev/vg0/xen1_root
  VG Name                vg0
  LV UUID                MQzhrS-OpOt-2IbY-BozD-l5vN-3doB-GRtyMc
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                4.00 GB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:2

  --- Logical volume ---
  LV Name                /dev/vg0/xen1_swap
  VG Name                vg0
  LV UUID                GHwsIT-a0sj-M72J-OVof-Ydju-Sexf-Ex824b
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                256.00 MB
  Current LE             64
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:3

server1:~#

Now we can convert the images as follows:

dd if=/home/xen/domains/xen1.example.com/disk.img of=/dev/vg0/xen1_root
dd if=/home/xen/domains/xen1.example.com/swap.img of=/dev/vg0/xen1_swap

(This can take a lot of time, depending on how big the images are.)

Afterwards, we must open /etc/xen/xen1.example.com.cfg ...

vi /etc/xen/xen1.example.com.cfg

... and change...

[...]
disk        = [
                  'file:/home/xen/domains/xen1.example.com/swap.img,xvda1,w',
                  'file:/home/xen/domains/xen1.example.com/disk.img,xvda2,w',
              ]
[...]

... to ...

[...]
disk        = [
                  'phy:/dev/vg0/xen1_swap,xvda1,w',
                  'phy:/dev/vg0/xen1_root,xvda2,w',
              ]
[...]

You can now start the guest again:

xm create /etc/xen/xen1.example.com.cfg

If everything goes well, you can delete the disk images:

rm -f /home/xen/domains/xen1.example.com/disk.img
rm -f /home/xen/domains/xen1.example.com/swap.img

 

分享到:
评论
1 楼 alvin198761 2014-01-21  
非常感谢,国外的被封杀了,你这里还有一份

相关推荐

    system-config-lvm

    用于RedHat6、7通过图形化界面控制LVM分区管理,需要显示器和GNOME(GNU)图形化界面,为RedHat7光盘缺失LVM图形配置工具而准备

    基于GP-LVM和LS-SVM航班延误等级预测研究.pdf

    "基于GP-LVM和LS-SVM航班延误等级预测研究" 本研究论文主要探讨基于高斯过程隐变量模型(Gaussian Process Latent Variable Model,GP-LVM)和最小二乘支持向量机(Least Square Support Vector Regression,LS-SVM...

    Local Distance Preservation in the GP-LVM through Back constraints

    在这篇关于"Local Distance Preservation in the GP-LVM through Back constraints"的文献中,作者主要探讨了高斯过程潜在变量模型(GP-LVM)的扩展,这种方法通过后向约束(back constraints)来保留局部距离,与...

    docker-lvm-plugin:用于LVM卷的Docker卷插件

    1) git clone git@github.com:projectatomic/docker-lvm-plugin.git (You can also use HTTPS to clone: git clone https://github.com/projectatomic/docker-lvm-plugin.git) 2) cd docker-lvm-plugin 3) export GO...

    docker-lvm-plugin-1.13.1-205.git7d71120.el7.centos.x86_64.rpm

    离线安装包,亲测可用

    libblockdev-lvm-devel-2.18-5.el7.i686.rpm

    官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装

    Howto create an initramfs image

    For example, if it is an lvm partition, encrypted or on USB. You can also stay in the initramfs. This can be very useful for debugging, or if you just want a very fast booting system.

    docker-lvm-plugin-1.13.1-47.2.gitf43d177.el7.x86_64.rpm

    docker-lvm-plugin-1.13.1-47.2.gitf43d177.el7.x86_64.rpm

    RockyLinux84-zsh-lvm-160g.ova.rar

    总之,RockyLinux84-zsh-lvm-160g.ova 是一个方便快捷的解决方案,为那些需要稳定、高效且易于管理的 Linux 环境的用户提供了一个全面的起点。通过使用 ZSH 和 LVM,用户可以在 Rocky Linux 8.4 上享受到更高效的...

    Ubuntu2004-zsh-lvm-160g.ova.rar

    标题中的"Ubuntu2004-zsh-lvm-160g.ova.rar"表明这是一个与Ubuntu 20.04操作系统、ZSH shell以及LVM(逻辑卷管理)相关的虚拟机镜像文件,大小为160GB。这个RAR压缩包包含了一个名为"Ubuntu2004-zsh-lvm-160g.ova"的...

    HP-LVM中文参考

    HP-LVM,全称为HP-UX Logical Volume Manager,是惠普UNIX系统中的一款强大的存储管理工具,用于管理和优化磁盘存储资源。它提供了一种灵活、高效的方式来组织和操作硬盘空间,包括创建、扩展、缩小和调整逻辑卷的...

    k8s-csi-lvm.tar.gz

    - `lvm-config.sh`:配置LVM的Shell脚本。 - `storageclass.yaml`:定义Kubernetes存储类的YAML文件,用于请求使用LVM的存储卷。 - `example-pvc.yaml`:示例Persistent Volume Claim(PVC)文件,用于测试和演示...

    离线安装LVM2-CentOS分区工具.zip

    离线安装LVM2-CentOS分区工具是一个针对CentOS操作系统的实用工具包,它包含了LVM2(Logical Volume Manager version 2)的核心组件。LVM2是Linux系统中广泛使用的磁盘管理工具,能够帮助管理员高效地管理和调整磁盘...

    HP-UX LVM使用手册

    # vgchange -an testvg # vgremove testvg ``` ##### 3.5 扩展 VG 当 VG 中的空间不足时,可以通过添加新的 PV 来扩展 VG: ```bash # vgextend testvg /dev/hdc1 ``` 注意,在扩展之前需要先使用 `pvcreate` 对...

    LVM(逻辑卷管理)

    **LVM(逻辑卷管理)**是Linux操作系统中一种先进的磁盘管理技术,它允许管理员在物理硬盘之上创建逻辑存储单元,以实现更灵活的磁盘空间管理和数据存储。LVM将物理硬盘组织成卷组(Volume Group),然后在卷组上...

    lvm2-cluster-2.02.187-6.el7.x86_64.rpm

    官方离线安装包,测试可用。请使用rpm -ivh [rpm完整包名] 进行安装

    lvm2-python-libs-2.02.187-6.el7.x86_64.rpm

    官方离线安装包,测试可用。请使用rpm -ivh [rpm完整包名] 进行安装

Global site tag (gtag.js) - Google Analytics