Skip to main content

You are here

dd

Creating large files in Solaris for testing purposes

In the Linux world, I use the dd utility to create files that need to be a certain size. Even though it works perfectly fine, its kind of annoying figuring out the output file's size of the file. This is because the size is based on the "bs" (block size) value and the total number of block size "count" together.

For example, the following dd command creates a 300 mb file called 300mb-test-fil. Each block size will be 1000 bytes, and I want of a total of 300,000 blocks.
Formula: ( (1000 x 300000) / 1000000 )

[[email protected] ~]$ dd if=/dev/zero of=300mb-test-file bs=1000 count=300000
300000+0 records in
300000+0 records out
300000000 bytes (300 MB) copied, 2.0363 s, 147 MB/s

Luckily in the Solaris world this can be easily accomplished using the mkfile utility, without doing any conversion.
I used the mkfile utility to easily create test disk files to experiment with ZFS.

[email protected]:~# mkfile 300m testdisk1
[email protected]:~# mkfile 300m testdisk2
[email protected]:~# ln -s /root/testdisk1 /dev/dsk/testdisk1
[email protected]:~# ln -s /root/testdisk2 /dev/dsk/testdisk2
[email protected]:~# zpool create tonytestpool mirror testdisk1 testdisk2
[email protected]:~# zpool status tonytestpool
pool: tonytestpool
state: ONLINE
scan: none requested
config:

NAME STATE READ WRITE CKSUM
tonytestpool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
testdisk1 ONLINE 0 0 0
testdisk2 ONLINE 0 0 0

errors: No known data errors

Linux: 

Awesome Applications: 

Unix: 

Creating a loopback file system for testing purposes

(This example the block size is 1024 bytes and a total of 5000 blocks)

dd if=/dev/zero of=/tmp/temploopbackimage.img bs=1024 count=5000

Associate the image file to the loopback device

losetup /dev/loop3 /tmp/temploopbackimage.img

Now you should be able to format /dev/loop3

Awesome Applications: 

Securely cloning Linux partitions to a different system

Getting a bit-by-bit copy of a partition or an entire hard drive is quite simple using the tool dd.

Depending on what you're trying to accomplish, there are two ways to get a copy of your partitions/drives.

One option is to clone the partition/drive directly to an actual partion/drive of your different system.

dd if=/dev/sdb1 | ssh [email protected] of=/dev/sdb1

Other option is to clone the partition/drive to a raw file on your second system, and associate the raw file to a loopback on your secondary host. This will give you the ability to easily mount the file as it were an actual partion/drive stored on your drive.

dd if=/dev/sdb1 | ssh [email protected] of=/root/rubysecurity_sdb1
[email protected] # losetup /dev/loop2 /root/rubysecurity_sdb1
[email protected] # mount /root/rubysecurity_sdb1 /mnt

Awesome Applications: 

Premium Drupal Themes by Adaptivethemes