0

I have an LVM logical volume (LV) and would like to create partitions within this LV to provide an ext3 partition and a swap partition. This LV would then get mounted as a disk to a virtual machine (Using Xen).

How would I go about this?

Thanks

jtnire
  • 777
  • 2
  • 7
  • 15

3 Answers3

2

I've just done this to refresh my memory. It's on a RHEL 5.6 system but should work anywhere fairly modern. I've done it a few times and it's been slap-your-forehead simple for me once I learned it:

lvcreate -L 100M -n lvVMDisk01 vgSystem
fdisk /dev/vgSystem/lvVMDisk01

fdisk throws and error at first:

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

but you just do a "w" to write the new partition table and exit. Then go back in with fdisk again and create your partitions as you like. Here's what "sfdisk -l" shows after I made a single partition as a demo.

sfdisk -l /dev/vgSystem/lvVMDisk01

Disk /dev/vgSystem/lvVMDisk01: 12 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/vgSystem/lvVMDisk01p1          0+      4       5-     40131   83  Linux
/dev/vgSystem/lvVMDisk01p2          0       -       0          0    0  Empty
/dev/vgSystem/lvVMDisk01p3          0       -       0          0    0  Empty
/dev/vgSystem/lvVMDisk01p4          0       -       0          0    0  Empty

Best of luck!
Mike

Mike Diehn
  • 859
  • 4
  • 8
0

I think you may be confusing terms. Partitions are done on physical disks, you can't partition a logical volume.

With LVM, you have volume groups (made up of physical volumes) that you can further chunk into logical volumes, but if you have all of your space allocated to a single logical volume, you can't further "partition" it. You'd have to shrink your disk, shrink your LV and then create a new logical volume.

Alex
  • 6,477
  • 1
  • 23
  • 32
  • 1
    You *can* partition a LV, it just doesn't make any *sense* to do so. – Ignacio Vazquez-Abrams Jun 14 '11 at 20:10
  • 1
    You have misunderstood me. This is an LV for a virtual machine, which sees this as one physical disk. I need to make a couple of partitions on this LV without running the setup ISO on the virtual machine. – jtnire Jun 14 '11 at 20:12
  • 1
    Sorry, I missed that distinction in the question. In that case, I'm afraid I can't offer any more. Haven't used xen past an initial install for testing. – Alex Jun 14 '11 at 20:20
-1

I'm assuming this is on Linux. Certain distros have GUIs available for doing this, so look at your documentation to see if that's available to you which should simplify things.

Failing that, tools for working with LVMs are pvcreate, vgcreate, lvcreate, mkfs.ext3 and mkswap.

Here's an example of starting from a blank disk:

# pvcreate /dev/sdb2
# vgcreate VolGroup01 /dev/sdb2
# lvcreate --name LogVol00 --size ?G VolGroup01
# lvcreate --name LogVol01 --size ?G VolGroup01
# mkfs.ext3 /dev/VolGroup01/LogVol00
# mkswap /dev/VolGroup01/LogVol01

Where each --size ?G argument is the size of the LVs you'd like to create.

brent
  • 3,481
  • 3
  • 25
  • 37
  • No, I'm sorry but you have misunderstood me. I already know how to create LVs. I'm trying to create partitions within an LV. Thanks – jtnire Jun 14 '11 at 20:00
  • You didn't read what I provided then. You're confusing what you need to do here. If you need multiple ext3 file systems create multiple LVs inside the volume group. You can create an ext3 filesystem inside an LV using mkfs.ext3 as I said in my original post. I don't appreciate the negative vote. – brent Jun 14 '11 at 20:44