create lvm from loop

cd /root
losetup /dev/loop0 lvm_disk.img


sfdisk /dev/loop0 << EOF ,,8e,, EOF

Checking that no-one is using this disk right now ...
BLKRRPART: Invalid argument
OK
Disk /dev/loop0: cannot get geometry

Disk /dev/loop0: 2871 cylinders, 255 heads, 63 sectors/track
/dev/loop0: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/loop0p1 0+ 2870 2871- 23061307 8e Linux LVM
/dev/loop0p2 0 - 0 0 0 Empty
/dev/loop0p3 0 - 0 0 0 Empty
/dev/loop0p4 0 - 0 0 0 Empty

fdisk -l /dev/loop0
Disk /dev/loop0: 23.6 GB, 23622320128 bytes
255 heads, 63 sectors/track, 2871 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/loop0p1 1 2871 23061307 8e Linux LVM

vi /etc/lvm/lvm.conf
filter = [ "a|/dev/loop.*|", "r/.*/" ]

pvcreate /dev/loop0
Physical volume "/dev/loop0" successfully created

vgcreate testvg /dev/loop0
Volume group "testvg" successfully created

vgdisplay -v
Using volume group(s) on command line.
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 22.00 GiB
PE Size 4.00 MiB
Total PE 5631
Alloc PE / Size 0 / 0
Free PE / Size 5631 / 22.00 GiB
VG UUID H4ebYh-LzsJ-9LJG-4Bdj-UWig-u7y2-1QAaFX

--- Physical volumes ---
PV Name /dev/loop0
PV UUID JyEC3B-8svS-n8D3-OFgV-Vxwe-llUj-63rGA6
PV Status allocatable
Total PE / Free PE 5631 / 5631

lvcreate -l 100%FREE -ntest_lv testvg
Logical volume "test_lv" created

Leave a Reply

Your email address will not be published. Required fields are marked *