LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trying to use the dd command (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-use-the-dd-command-4175533064/)

Septym 02-04-2015 12:38 PM

Trying to use the dd command
 
Hi i am trying to use the dd command to create an iso of my Ubuntu machine but am having some problems with the syntax trying to do it using an external hard drive as the file location.

can anyone help me out?

schneidz 02-04-2015 12:42 PM

the general syntax is usually:
Code:

dd if=/path/to/input/file of=/path/to/output/file bs=blocksize
you would need to be triply cautious that you are referring to the correct disks. there are no training wheels with dd (it will not warn you about overwriting your harddrive irrevocably).

if i understand your question correctly, your if should be the disk that your ubuntu is installed on (what does df -h print out for you ?).
i htink your of would output to some new file on your external drive (i think the same df output above would give us an idea of that).

before dd-ing, consider filling the drive with logical zeros so that it compresses better. this is what i do:
Code:

dd if=/dev/zero of=tmp.zero; rm tmp.zero
dd if=/dev/sdb bs=2048 | bzip2 > fc-20.iso.bz2          # to create the image
bunzip2 -c fc-20.iso.bz2 | sudo dd of=/dev/sdb bs=2048  # to restore the image


Septym 02-04-2015 12:48 PM

thank you for the quick response but im still a little confused, what blocksize should i use and where do i point the command to copy the whole machine input or output?

suicidaleggroll 02-04-2015 12:51 PM

Let's back up a bit here and determine if dd is even the right tool for the job.

What drive are you trying to back up, and to where are you backing it up? What is on the drive being backed up? How big are the source and destination drives? What, exactly are you trying to do, and for what purpose? What's the end goal?

It is VERY easy to destroy the data on your drive and render the system unbootable with dd. And if you have to ask these kinds of questions, it's pretty doubtful that dd is even the right tool in the first place.

schneidz 02-04-2015 12:51 PM

i edited my post above. blocksize isnt important (i think it helps with making it run faster) and depends on a lot of variables, cpu speed, how many cores, how much ram, type of harddrives, ...

start by running this command:
Code:

dd if=/dev/zero of=tmp.zero; rm tmp.zero
then reboot into a live-usb. (we shouldnt be trying to image a disk that is in use).

grail 02-04-2015 07:17 PM

So, I am not looking to hijack this question, however I to am a novice with dd (have basic understanding and have copied stuff to use and so on).

My additional question is, how do you only copy the data (ie. actual disk is say 20GB but only 15GB in use)? ... or is this suicidaleggroll's point that dd may not be the correct tool in this example?

Fred Caro 02-04-2015 08:50 PM

septym,
the location will be the mount point, perhaps /media/New Volume
If you refer to that put New Volume in single quotes becuase of the gap.
No expert on anything, much less dd but it does seem to copy "literally" from one place to another given certain peramiters match:

https://en.wikipedia.org/wiki/Dd_%28Unix%29

It is also running and changing at the same time (the booted distro)
Perhaps a bootable G4Liux (ghost for linux) disk to copy it elsewhere.
You could try cloning it to another usb hdd in a caddy, take it out of caddy and put it in the pc.

Fred.

yancek 02-04-2015 09:09 PM

Are you trying to create an iso image from data on your drive or just use dd to copy? If the former, you should use mkisofs or genisoimage to do that.

schneidz 02-05-2015 07:42 AM

Quote:

Originally Posted by grail (Post 5312217)
So, I am not looking to hijack this question, however I to am a novice with dd (have basic understanding and have copied stuff to use and so on).

My additional question is, how do you only copy the data (ie. actual disk is say 20GB but only 15GB in use)? ... or is this suicidaleggroll's point that dd may not be the correct tool in this example?

if you have a brand new 1tb disk with nothing written to it then dd is designed to copy 1 tb worth of logical zeros (or do unwritten disks come from the factory with all blocks = ff ?). dd has no perception of files and directories only block devices and bytes.

my idea of creating a dummy file full of /dev/zero's to fill up the disk should help with compressing it since unlinked files will be overwritten.

maples 02-05-2015 09:14 AM

Quote:

Originally Posted by grail (Post 5312217)
So, I am not looking to hijack this question, however I to am a novice with dd (have basic understanding and have copied stuff to use and so on).

My additional question is, how do you only copy the data (ie. actual disk is say 20GB but only 15GB in use)? ... or is this suicidaleggroll's point that dd may not be the correct tool in this example?

If you just want to backup the files, you might want to look at rsync.

fatmac 02-05-2015 09:36 AM

Sounds like the wrong tool for the job in hand.

dd copies disc blocks/sectors, not files.

To make an .iso (cdrom) image you use mkisofs/genisoimage, however if it is to be a dvd, you use growisofs, then you 'burn' it to disc.

If you are wanting to back up your files, I would either copy to another disk or use tar, then back that up.

There is no reason to copy/backup your operating system, as you can just re install it.

suicidaleggroll 02-05-2015 10:11 AM

Quote:

Originally Posted by fatmac (Post 5312523)
dd copies disc blocks/sectors, not files.

It can copy files too, but that's typically not what it's used for.

Quote:

Originally Posted by fatmac (Post 5312523)
There is no reason to copy/backup your operating system, as you can just re install it.

There are many reasons one might want to copy/backup the OS, especially in the professional environment.


We need to wait for the OP to respond with his goals before this thread can really continue though...

J Martin Rushton 02-05-2015 11:17 AM

"dd" comes from "disk to disk copy", so that is just what it does. It copies its input (file, pipe, partition, disk, tape) to its output (likewise file, pipe, disk, tape or partition) without any comprehension of what it is doing. It will happily copy a file onto a disk, or a partition or read from a tape into a file.

When copying files it does have the useful property that you can force it to copy part of a file (starting at an arbitrary point), or even to copy more than a file. This is the standard way to generate large scratch files such as new swap files. For instance, from the mkswap(8) man page:
Code:

# dd if=/dev/zero of=swapfile bs=1024 count=65536
This creates "swapfile" to be 65536 blocks of 1024 bytes filled with zeros.

dd can also perform manipulations such as ASCII <-> EBCDIC or swapping bytes.

273 02-05-2015 12:21 PM

Quote:

Originally Posted by J Martin Rushton (Post 5312586)
"dd" comes from "disk to disk copy"

I take issue with this, it stands for "Data Destroyer" as any fule know... ;)


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