Creating Filesystem using DD for LVM

I created a new filesystem using dd and mounted:

I have a filesystem /FAW with 1Terra space

/dev/sdb1            1151331444  24742604 1068104612   3% /FAW

Steps I followed to create a new filesystem

# dd if=/dev/zero of=/FAW/vms/linux_vm/disk2.img bs=1 count=1024 seek=500G
# mke2fs disk2.img 

# mount -o loop disk2.img /FAW/xen_vm/ 

Now df -k output is :

/FAW/vms/linux_vm/disk2.img
                     516061624     71448 489775776   1% /FAW/xen_vm

I want to be able to add the above disk2.img partition to pvcreate lvm which does not recognize.

Can someone tell me how i should convert it to filetype recognised by LVM.

LVM, by default, ignores any "devices" outside of /dev, or anything with a filesystem on it. So the recommended (by me) way would be to run

# dd if=/dev/zero of=/FAW/vms/linux_vm/disk2.img bs=1 count=0 seek=500G
# losetup -sf /FAW/vms/linux_vm/disk2.img
# pvcreate /dev/loop<x>

where x is the number reported by losetup. Or, if there's no other data on it, use the whole of /dev/sdb1 for LVM.

Hi Pludi,

# losetup -sf /FAW/vms/linux_vm/disk2.img
losetup: invalid option -- s

So i did:

losetup -f                                                # find unused
# losetup -f /FAW/vms/linux_vm/disk2.img

Still does not show up

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.7G  5.7G  3.5G  63% /
/dev/sda1             190M   45M  136M  25% /boot
/dev/sdb1             1.1T   24G 1019G   3% /FAW

/FAW/vms/linux_vm/disk2.img
                      493G   70M  468G   1% /FAW/xen_vm
# losetup -a
/dev/loop0: [fd01]:49160 (/FAW/vms/linux_vm/disk2.img)
/dev/loop2: [fd01]:49160 (disk2.img)

is there a way to make is use /dev/sdc1 ?

Of course it won't show up in df after losetup, since df shows only mounted filesystems. Remove the loopback you've just created, unmount /FAW/xen_vm, then set up the loopback device again and run pvcreate on it. After this it will still not show up in df, but you can create a volume group and logical volumes on it, which you can then put a filesystem on.

Thanks a lot,

I think i made a mistake here.

After creating the disk
dd if=/dev/zero of=/FAW/vms/linux_vm/disk2.img bs=1 count=1024 seek=500G

I created a file system:

mke2fs disk2.img

After creating physical,logical volumes i again tried to create filesystem and it hanged.

mkfs.ext3 /dev/xen-vm/xen_prov

Wait wait wait. The correct order is

  1. Create an image file
  2. Create a loopback device for the file
  3. Run pvcreate on the loopback device
  4. Run vgcreate on the "physical" volume
  5. Run lvcreate on the volume group
  6. Create a filesystem on the logical volume
  7. Mount the logical volume

Why did you create a filesystem on the image file? What were your exact steps and what does your system look like now?

Sorry I am back to work just now, yesterday was a holiday for us.

I have not yet got the machine back to test it.

Ok here I am listing down what you said,

1) Create an image file
===============
#dd if=/dev/zero of=/FAW/vms/linux_vm/disk2.img bs=1 count=1024 seek=500G 
2)Create a loopback device for the file
===========================
#losetup -f /FAW/vms/linux_vm/disk2.img


# losetup -a
/dev/loop0: [fd01]:49160 (/FAW/vms/linux_vm/disk2.img)

3) Run pvcreate on the loopback device
===============================
# pvcreate /dev/loop0  (initialise disk created)
  Physical volume "/dev/loop0" successfully created
4)Run vgcreate on the "physical" volume
===============================
#vgcreate xen-vm /dev/loop0
Volume group "xen-vm" successfully created
5) Run lvcreate on the volume group
============================
#lvcreate -L450G -nxen_prov xen-vm

Logical volume "xen_prov" created
6)Create a filesystem on the logical volume
===================================
#mkfs.ext3 /dev/xen-vm/xen_prov
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
58982400 inodes, 117964800 blocks
5898240 blocks (5.00%) reserved for the super user
First data block=0
......................
.........................................
7) Mount the logical volume
========================
mount /dev/xen-vm/xen_prov /FAW/xen_vm

Let us know if this is rite, I have not yet executed the 7th point since I have not go the system back yet.

1 Like

Step 7 as you've written it is not correct. You have to mount the logical volume, not the image file!

mount /dev/xen-vm/xen_prov /FMW/xen_vm

And I hope that this is only for experimenting with LVM, since a loopback device will not be re-created automatically after a reboot, and thus can't be automatically be mounted during startup. This is why I suggested that you use the whole of sdb1 if possible.

Overlooked thanks :slight_smile:

---------- Post updated at 06:36 AM ---------- Previous update was at 06:21 AM ----------

yes just saw once rebooted all vanished :(. i am not entitled to use the whole of sdb1 which is 1T, i have only got 500 G of that, thats why.

---------- Post updated at 06:38 AM ---------- Previous update was at 06:36 AM ----------

can;t that be mounted on /etc/fstab for permanent addition ?

Lets take a step back here and look at the complete picture. You have a 1TB drive/partition, on which you should create a 500G filesystem for use with Xen. What about the rest of the drive? Is this reserved for a different project? If so, could that project also use LVM? If not, would it be possible to re-partition the drive?

1 Like

Thanks for your help pludi.

No 500 GB is for another team, so could only use 500gb of it,

But you know, what i could do is i needed the 500 GB for xen virtualistaion

So heres what i did:

Created the disk image using dd :

thanks again!