Making an ISO File of CD/DVDs:
If you want to make an ISO file of your CD or DVD disk. You can easily do that with the dd command.
Let’s say, you’ve inserted a DVD of a movie into the CD/DVD reader of your computer. Now, you want to create a ISO file from that DVD.
First, run the following command to find the device name of your CD/DVD reader.
As you can see, the device name is sr0 in my case. So, I can access it as /dev/sr0
Now, you can make an ISO file of the CD/DVD disk with the following command:
Here, /path/filename.iso is the path and filename of your ISO file. In my case, I will save it to ~/Downloads/ubuntu.iso
As you can see, the ISO file is created. The disk write speed is about 29.4 MB/s and about 851 MB of data is written in total.
You should be able to find the ISO file in the directory where you saved it.
Making a Bootable USB Thumb Drive of Your Favorite Linux Distribution:
You can use dd to create a bootable USB thumb drive of your favorite Linux distribution.
To create a bootable USB thumb drive, you need a USB thumb drive of about 4GB or more in size and an ISO image of your preferred Linux distribution.
Let’s say, you want to make a bootable USB thumb drive of Ubuntu Server 18.04.1 LTS. You’ve downloaded the ISO file of Ubuntu Server 18.04.1 LTS and it’s in your ~/Downloads directory.
First, insert the USB thumb drive which you want to make bootable.
Now, run the following command to find the device name of your USB thumb drive.
As you can see, my 32GB USB thumb drive is listed here. The device name is sdb. So, I can access it as /dev/sdb
Now, run the following command to make a bootable USB thumb drive from the ISO image of your preferred Linux distribution.
Your USB thumb drive now can be used to install your desired Linux distribution.
Creating Virtual File Systems:
The dd command can be used to create file based virtual file systems. You can format, mount, store files etc from there.
Let’s say, you want to create a 512MB virtual file system.
To do that, run the following command:
NOTE: bs=1M means the block size is 1 MB and count=512 means the disk1.raw file will contain 512 blocks. 512 * 1MB = 512 MB. You can also set bs=1G to change the block size to 1 GB.
The 512MB raw file disk1.raw should be created.
As you can see, a new file disk1.raw is in my current working directory.
Now, you can format the file disk1.raw file as any filesystem you want. I will format it as EXT4 filesystem.
To format the disk1.raw file as EXT4 filesystem, run the following command:
NOTE: Here, datastore1 is the label of the virtual disk. You may change it if you want.
A virtual EXT4 filesystem should be created.
Now, make a new directory where you can mount the virtual filesystem with the following command:
Now, mount the virtual filesystem to the newly created directory with the following command:
As you can see, the virtual filesystem is mounted correctly.
This is great for testing.
Wiping The Whole Disk:
You can use the dd command to wipe the partition table off of your disk or USB thumb drives.
Let’s say, you want to wipe off the partition table off of the disk /dev/sdb. To do that, run the following command:
The whole partition table of your disk should be removed. This is a very destructive operation. You will not be able to recover your partitions anymore. If you want to use this disk again, you will have to create a new partition table.
If you want to sell your hard drive or SSD to someone else, then it is always safe to completely wipe out all your personal data. Complete wipe out means replacing the contents of the whole disk with either zeros or random values. So, the new owner of the disk won’t be able to recover any of your personal data.
If you want to replace the contents of the whole disk with zeros, then you can use dd as follows:
This will take a long time to complete.
If you want to replace the contents of the whole disk with random values, then you can use dd as follows:
This will take a long time to complete as well.
Where to Go Next?
The dd command has a lot of options that may come in handy. You may checkout the dd manpage for more information on all the supported command line options and usages of the dd command.
To access the manpage of dd, run the following command:
So, that’s how you use dd command on Linux to do various tasks. Thanks for reading this article.