LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-01-2010, 12:55 PM   #1
bryanvick
LQ Newbie
 
Registered: Oct 2009
Posts: 15

Rep: Reputation: 0
Fake block device for testing LVM?


I want to test LVM+Raid. When I was testing ZFS on Solaris, I was able to create regular files, and use those as disks for testing.

I tried creating a regular file full of zeros w/ dd, then partitioning that. fdisk seemed to be able to create a partition on the regular file, but mkfs and parted couldn't work with it. Is there any way to create fake block devices for testing?
 
Old 06-01-2010, 07:03 PM   #2
tvynrylan
LQ Newbie
 
Registered: May 2010
Posts: 10

Rep: Reputation: 0
I'm not sure why you would've had difficulties using mkfs on a regular block device. I'm running Debian testing and the following works for me:

Code:
root@thirtyseven:~# dd if=/dev/zero of=test.img bs=1024 count=10240 # 10M
10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 0.207998 s, 50.4 MB/s
root@thirtyseven:~# mkfs.ext3 test.img 
mke2fs 1.41.12 (17-May-2010)
test.img is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
2560 inodes, 10240 blocks
512 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1280 inodes per group
Superblock backups stored on blocks: 
        8193

Writing inode tables: done                            
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
I can also partition the file as if it were a disk:

Code:
root@thirtyseven:~# parted test.img
GNU Parted 2.2
Using /root/test.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt                                                      
(parted) p                                                                
Model:  (file)
Disk /root/test.img: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted)
You won't want to use partitioning like this, however, if you're just playing around with LVM. I personally think of partitioning a hark disk as a way of getting block devices out of the disk without having to worry about other applications (like LiveCDs or OS installers) messing those block devices up. If you want to play with RAID or LVM, I suggest you just do

Code:
for n in $(seq 1 10); do dd if=/dev/zero of=testDevice$n.img bs=1024 count=10240; done
You should then be able to execute commands against those files the same way you could against a partition. If, for some reason, you must have a block device, you can always look into losetup for creating a loopback device over the file.

If you continue to have trouble doing so, please post the error messages you are getting along with your distro and version.
 
Old 06-01-2010, 07:21 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,131

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
What sort of twisted puppy puts a gpt partition table on a 10 Meg (psuedo) block device ? ...

Funnily enough I was looking at some similar testing - Linux guest in VirtualBox using multiple (simulated) partitions to test LVM and RAID. So many layers of software it was a wonder it ran at all ...
 
Old 06-02-2010, 11:04 AM   #4
bryanvick
LQ Newbie
 
Registered: Oct 2009
Posts: 15

Original Poster
Rep: Reputation: 0
I was able to create an ext3 filesystem on a regular file, but the first step of the LVM HOWTO fails.

pvcreate can't prepare the file for use w/ LVM: "Device disk1 not found (or ignored by filtering)."

bry@brybackup:/tmp$ dd if=/dev/zero of=disk1 bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 24.2265 s, 43.3 MB/s
bry@brybackup:/tmp$ mkfs.ext3 disk1
mke2fs 1.41.3 (12-Oct-2008)
disk1 is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
64000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
bry@brybackup:/tmp$
bry@brybackup:/tmp$ sudo pvcreate disk1
Device disk1 not found (or ignored by filtering).
 
Old 06-02-2010, 11:15 AM   #5
bryanvick
LQ Newbie
 
Registered: Oct 2009
Posts: 15

Original Poster
Rep: Reputation: 0
OK, figured it out using this post: http://nixforums.org/about64727.html

I had never messed w/ loop devices before. They were exactly what I was looking for.

So now before creating the ext3 filesystem on disk1 I do:
bry@brybackup:/tmp$ sudo losetup /dev/loop0 disk1

...then mkfs.ext3, then pvcreate.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Fake USB stick testing tool? suse_nerd Linux - Hardware 3 02-02-2010 08:25 AM
missing LVM block device on RHEL50 babel17 Linux - Server 3 01-24-2008 04:58 PM
How to make a fake /dev/hda* device jahvascriptmaniac Linux - Hardware 7 09-10-2006 07:47 AM
UL 1.0 GRUB: could not find device for /boot: not found or not a block device cma Linux - General 4 12-12-2005 03:35 AM
Linking a file on disk to a fake block device? fyhuang Linux - Software 2 10-31-2005 07:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration