`

lvm on xen

阅读更多

Moving a Xen Guest into an LVM container from a loopback sparse image is easy enough.

You’ll need to power down the VM using xm shutdown mymachine

Once done, create the logical volume with: lvcreate –name mymachine-disk –size 10G myvg 10G should match the exact size (if not more) of your current VM. Now create the same for the swap file: lvcreate -name mymachine-swap -size 128M myvg. Now edit your machine’s config (/etc/xen/mymachine.cfg), replacing the disk part from:

disk        = [
'file:/xen/mymachine/mymachine-swap,sda1,w',
'file:/xen/mymachine/mymachine-disk,sda2,w',
]

to

disk        = [
'phy:/dev/myvg/mymachine-swap,sda1,w',
'phy:/dev/myvg/mymachine-disk,sda2,w',
]

And use dd to write the disk to your new LVM filesystem:

dd if=/xen/mymachine/mymachine-disk of=/dev/myvg/mymachine-disk
dd if=/xen/mymachine/mymachine-swap of=/dev/myvg/mymachine-swap

Remembering that you can use killall -SIGUSR1 dd at any time to gain a status update on dd’s IO.

Once done, power up your VM again with xm create mymachine.cfg

 

 

When using XEN virtualization it's good practice to use LVM volumes as raw disk devices for the vm guests. The main advantage is that there is no file system for the Xen host to manage and the guest has direct access to the physical volume = better performance!
Another advantage is that you can leverage LVM snapshots adding a similar function to your Xen setup as known in VMWare.

One drawback when using LVM for your virtual guests is that the vm's disk is less portable. There are tools that can handle LVM imaging, but dd is the OSS tool giving you a 1:1 copy of your disk. It's free & it's proven.
dd's known drawback is that the dd dump files get big and time to backup/restore a LVM volume can be lengthy.

Here's how to speed things up and also save on space needed for your LVM images & backups by combining dd with gzip. On modern hardware you can get speeds up to ~90Mb/sec - meaning you can restore a template or image of 15 GB in 3 to 4 minutes.

NOTE: With big data partitions containing a small percentage of data (25% or less of the disk total), it's better to use traditional backup methods. Here dd will lose you precious time backing up parts that contain no real data.

To create an image from the LVM volume:

NOTE: Always make sure your guest is shutdown to ensure data integrity.

dd if=/dev/[lvmsystem]/[lvmpartition] bs=64k | gzip -c > /[path for your image file]/[machine_disk name].img.gz

This command tells dd to use your LVM volume as input using a block size of 64k, the pipe then hands this input stream over to gzip and that zips the stream to the given img.gz file.

* If your source LVM volume contains errors due to disk failure or other, you can tell dd to copy all parts of the disk it can acces. To do this add options conv=sync,noerror before the bs=64k statement.

Restore and Image / Template to an LVM volume:

*If necessary first create a LVM volume where you want the copy written back. It must be at lease the same size (or bigger) than the original LVM volume where the image was taken from.

gunzip -c /[path containing your image file]/[machine_disk name].img.gz | dd of=/dev/[lvmsystem]/[lvmpartition] bs=64k

 

 

1. Yes, you can have a seperate LV per Xen guest OS and you should of course.
2. LVM snapshots go something like this.

Snapshotting is a way to take a "point-in-time" image of a filesystem. What this allows you is to do is access files that would normally be locked so you can back them up. The process is as follows:

  1. Take the snapshot
  2. Mount the snapshot
  3. Take a backup of the snapshot
  4. Unmount and destroy the snapshot
Taking the snapshot

When you take the snapshot, you're essentially creating a new LVM device that appears to be a duplicate of the "real" filesystem at a point in time. To do this we create another LVM device (using lvcreate) with an argument of -s to indicate we want a snapshot and the -n argument to name it. In this case LogVol00 is the original LV and LVsnap is the name of the snapshot. You can name them whatever you want.

lvcreate -l 500 -s -n LVsnap /dev/VolGroup00/LogVol00

Mounting the snapshot

Next, we mount the snapshot somewhere else, we use /media/snap. We also mount it read only.

mkdir /media/snap
mount -o nouuid,ro /dev/VolGroup00/LVsnap /media/snap
Do the backup

Now, backup /media/LVsnap like you would any other directory:

Unmount and destroy the snapshot

Now we have to unmount the snapshot and destroy it. The reason we destroy it because any I/O that takes place on the device uses space to track the differences betweeen the real and the snapshot filesystem. Plus, we've done our job so there's no reason to keep it around.

unmount /media/LVsnap
lvremove -f /dev/VolGroup/LVsnap

3. Migrating an LV depends some on whether you have to depend on a bootloader in the LV or not. You could do any of the following depending on your circumstances.

  • Snapshot the old LV, create a new LV on the destination machine, export it with NFS and copy all files across using cp.
  • Snapshot the old LV, create a new LV on the destination, export it with NFS and use dump and restore to dum the old LV to the new one.
    dump 0 -f - /dev/VolGroup00/LogVol00 | (cd /dest; restore -rf - )
  • Snapshot the old LV, create a new LV on the destination machine, and dd the snapshot and pipe it into ssh
dd if=/dev/VolGroup00/LVsnap | ssh -c arcfour 192.168.2.100  "dd of=/dev/VolGroup00/LogVol00"

I don't think I have to tell you to be VERY careful with the last one. If you get the destination Logical Volume screwed up you will toast the destination. I specified arcfour for the cipher because it's much faster than the default. You will probably want to mess with dd's blocksize too as you can double the speed in which dd will copy if the blocksize is larger. Another option would be to use ddrestore or dd_restore in place of dd. Make sure you look at the syntax difference first. Both of these are faster than stock dd but if you bump the blocksize dd will almost keep up. I assume you only keep the VM OS on the LV and not all data. If so then it won't take long to copy. It takes about 45 min per 80 GB here. If you're running a 10GB OS LV then you can figure about 5 minutes.

分享到:
评论

相关推荐

    Oracle11g on AIX6.1 安装指南(RAC + LVM

    Oracle11g on AIX6.1 安装指南(RAC + LVMOracle11g on AIX6.1 安装指南(RAC + LVMOracle11g on AIX6.1 安装指南(RAC + LVMOracle11g on AIX6.1 安装指南(RAC + LVM

    Xen Users’ Manual

    5. **配置存储**:根据需求配置存储选项,如使用LVM、RAID等。 #### 四、启动Xen虚拟机 启动Xen虚拟机主要包括以下几个步骤: 1. **创建虚拟硬盘**:使用工具如`qemu-img`创建虚拟硬盘镜像。 2. **配置虚拟机**:...

    ListView Messages (LVM_)ListView控件类的消息常量常量

    - **代码示例**:`Public Const LVM_GETITEM = (LVM_FIRST + 5)` - **应用场景**:当需要获取列表中的某一项的具体信息时,如项的状态、文本等,可以使用该消息。 ##### 2. **LVM_SETITEM** - **定义**:用于...

    lvm基本命令详解

    lvm 基本命令详解 LVM(Logical Volume Manager)是一种逻辑卷管理器,用于管理磁盘分区和文件系统之间的逻辑层。它提供了一个抽象的盘卷,在盘卷上建立文件系统。 LVM 的基本术语包括: * 物理存储介质(The ...

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

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

    lvm2代码 可编译 已验证

    **LVM2(Logical Volume Manager 2)**是Linux操作系统中的一个高级磁盘管理工具,它允许用户在物理硬盘上创建逻辑卷,从而提供更大的灵活性和扩展性。LVM2比传统的分区方式更加灵活,因为它可以跨越多个硬盘,动态...

    lvm2离线安装包 ,亲测可用

    LVM(Logical Volume Manager)是Linux系统中一种高级的存储管理技术,它允许管理员将物理硬盘组织成逻辑卷,提供更灵活的磁盘管理和扩展能力。LVM2是其第二代版本,相较于第一代,它增加了更多的功能和优化,提高了...

    lvm使用手册,详细介绍lvm的操作命令

    LVM 使用手册 LVM(Logical Volume Manager,逻辑卷管理)是一种高级的磁盘存储管理技术,旨在提供更高层次的磁盘存储解决方案。它使系统管理员可以更方便地为应用程序和用户分配存储空间。在 LVM 管理下的存储卷...

    Linux LVM硬盘管理及LVM扩容

    "Linux LVM硬盘管理及LVM扩容" 根据提供的文件信息,以下是相关的知识点: 一、LVM简介 LVM(Logical Volume Manager)是一种逻辑卷管理系统,由Heinz Mauelshagen在Linux 2.4内核上实现。LVM可以将一个或多个...

    LVM(逻辑卷管理)

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

    linux常用命令 lvm

    Linux LVM,全称为Logical Volume Manager,是Linux操作系统下的一种磁盘管理工具,它提供了一种灵活、可扩展的方式来管理磁盘存储空间。LVM允许系统管理员创建和管理逻辑卷,这些逻辑卷可以跨越多个物理硬盘,从而...

    xen man xen man

    - **LVM支持的VBD**:利用逻辑卷管理(LVM)创建虚拟磁盘。 - **NFS根目录**:通过网络文件系统(NFS)挂载虚拟机的根文件系统。 ### CPU管理 Xen支持动态调整虚拟机的CPU资源,允许用户根据实际需求调整分配给各个...

    Linux7扩容根分区(LVM+非LVM).docx

    Linux 7 扩容根分区(LVM+非 LVM) Linux 7 扩容根分区是指在 Linux 7 操作系统中扩展根分区的大小,以满足存储需求。在本文中,我们将介绍使用 LVM(Logical Volume Manager)和非 LVM 两种方法来扩容根分区。 使用...

    Linux LVM硬盘管理

    Linux LVM 硬盘管理 Linux LVM 硬盘管理是指通过 Logical Volume Manager(逻辑卷管理)来管理硬盘的存储空间。LVM 将一个或多个硬盘的分区在逻辑上集合,相当于一个大硬盘来使用。当硬盘的空间不够使用的时候,...

    [原创]CentOS6.9数据库生产服务器扩容手册(LVM+非LVM)

    CentOS6.9 数据库服务器扩容手册(LVM+非LVM) 本文档旨在指导用户在 CentOS6.9 环境下扩容数据库服务器,涵盖了 LVM 和非 LVM 两种情况。该手册将分为四个部分:准备工作、LVM 扩容、非 LVM 扩容和总结。 准备...

    Linux新建LVM的过程.docx

    # parted /dev/sdb set 1 lvm on ``` 修改完成后,执行`partprobe`命令更新内核分区表缓存,确保系统识别到分区类型的更改。 ```bash # partprobe ``` ### 二、创建PV、VG、LV #### 1. 使用`pvcreate`创建PV 创建...

    linux LVM管理整合打包

    Linux LVM(Logical Volume Manager,逻辑卷管理)是Linux操作系统中一种高级的磁盘管理工具,它提供了一种灵活的方式来组织存储空间,使得磁盘管理更为便捷和高效。本资料包整合了关于LVM管理的各种知识,涵盖了从...

    xen 用户手册

    3. **Logical Volume Manager (LVM)**:结合LVM可以在多个物理硬盘上创建逻辑卷,实现存储的动态扩展和备份。 4. **Xen Storage Domains (SDs)**:SDs是Xen的存储抽象,允许在不同的物理存储设备之间迁移虚拟机。 ...

    AIX LVM管理介绍 AIX LVM管理介绍

    ### AIX LVM管理介绍 逻辑卷管理器(Logical Volume Manager, LVM)是IBM AIX操作系统中的一个重要组件,用于简化存储管理和提高数据可用性。本文将深入探讨AIX LVM的基本概念、管理方法以及一些实用技巧。 #### 1...

Global site tag (gtag.js) - Google Analytics