Adventures with DD

In my humble opinion when it comes to CLI tools `dd` ranks pretty high in my toolkit. Right there with `nc` and a few other ‘ole favorites.

Today I wanted to show a quick hack on how to determine information about a block device using dd. This goes along the same path asĀ  previous post about using `dd` to get LVM configuration off devices.

Well enough talk lets get down to the CLI:

DD IS DESTRUCTIVE USE IT WITH CAUTION AND UNDERSTANDING OF WHAT YOU ARE RUNNING!…ok now that is out of the way…

# Thanks to file(1) magic(5)
# Example 1 - CentOS 6 LVM2
>dd if=/dev/sda3 of=/tmp/info bs=512 count=1000
1000+0 records in
1000+0 records out
512000 bytes (512 kB) copied, 0.0190352 s, 26.9 MB/s
You have new mail in /var/spool/mail/root
> file /tmp/info
/tmp/info: LVM2 (Linux Logical Volume Manager) , UUID: M7pUi7daFBsEQ95UNJUd5pN604qSa0Z


#Example 2 - CentOS 7 LVM2
> dd if=/dev/sda2 of=/tmp/info bs=4k count=100
100+0 records in
100+0 records out
409600 bytes (410 kB) copied, 0.00487443 s, 84.0 MB/s
> file /tmp/info
/tmp/info: LVM2 PV (Linux Logical Volume Manager), UUID: fYcfT0-3Oyk-J87h-A6SV-rYCc-q1of-zhx7Fd, size: 119508303872


#Example 3 - CentOS 7 XFS
> dd if=/dev/sda1 of=/tmp/info bs=4k count=100
100+0 records in
100+0 records out
409600 bytes (410 kB) copied, 0.00990939 s, 41.3 MB/s
> file /tmp/info
/tmp/info: SGI XFS filesystem data (blksz 4096, inosz 256, v2 dirs)


#Example 4 - CentOS 7 BTRFS
> dd if=/dev/vdb2 of=/tmp/info bs=4k count=100
100+0 records in
100+0 records out
409600 bytes (410 kB) copied, 0.00324626 s, 126 MB/s
> file /tmp/info
/tmp/info: BTRFS Filesystem (label "----_fs", sectorsize 4096, nodesize 16384, leafsize 16384)


#Example 5 - CentOS 6 - EXT4
> dd if=/dev/sda1 of=/tmp/info bs=4k count=100
100+0 records in
100+0 records out
409600 bytes (410 kB) copied, 0.0132642 s, 30.9 MB/s
> file /tmp/info
/tmp/info: Linux rev 1.0 ext4 filesystem data (needs journal recovery) (extents) (huge files)

I always forget to test this when I have more “esoteric” filesystems in my home lab. If anyone can and post a comment with the results from other filesystems’s or distros I would appreciate it!

Leave a Reply