LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-04-2015, 01:38 PM   #1
Septym
LQ Newbie
 
Registered: Feb 2015
Posts: 2

Rep: Reputation: Disabled
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?
 
Old 02-04-2015, 01:42 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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

Last edited by schneidz; 02-04-2015 at 01:48 PM.
 
Old 02-04-2015, 01:48 PM   #3
Septym
LQ Newbie
 
Registered: Feb 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
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?
 
Old 02-04-2015, 01:51 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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.
 
Old 02-04-2015, 01:51 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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).

Last edited by schneidz; 02-04-2015 at 01:54 PM.
 
Old 02-04-2015, 08:17 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,255

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
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?
 
Old 02-04-2015, 09:50 PM   #7
Fred Caro
Member
 
Registered: May 2007
Posts: 999

Rep: Reputation: 166Reputation: 166
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.
 
Old 02-04-2015, 10:09 PM   #8
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 6,872

Rep: Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249
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.
 
Old 02-05-2015, 08:42 AM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Quote:
Originally Posted by grail View Post
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.
 
Old 02-05-2015, 10:14 AM   #10
maples
Member
 
Registered: Oct 2013
Location: IN, USA
Distribution: Arch, Debian Jessie
Posts: 810

Rep: Reputation: 264Reputation: 264Reputation: 264
Quote:
Originally Posted by grail View Post
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.
 
Old 02-05-2015, 10:36 AM   #11
fatmac
Senior Member
 
Registered: Sep 2011
Location: Surrey/Hants Border, UK
Distribution: BSD & Linux - As long as they are Lightweight
Posts: 1,500

Rep: Reputation: Disabled
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.
 
Old 02-05-2015, 11:11 AM   #12
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by fatmac View Post
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 View Post
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...
 
Old 02-05-2015, 12:17 PM   #13
J Martin Rushton
Member
 
Registered: Jan 2015
Location: England
Distribution: Mainly CentOS
Posts: 31

Rep: Reputation: Disabled
"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.

Last edited by J Martin Rushton; 02-05-2015 at 06:24 PM. Reason: for "disks" in para 2 read "files". sorry.
 
Old 02-05-2015, 01:21 PM   #14
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 6,012

Rep: Reputation: 1621Reputation: 1621Reputation: 1621Reputation: 1621Reputation: 1621Reputation: 1621Reputation: 1621Reputation: 1621Reputation: 1621Reputation: 1621Reputation: 1621
Quote:
Originally Posted by J Martin Rushton View Post
"dd" comes from "disk to disk copy"
I take issue with this, it stands for "Data Destroyer" as any fule know...
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] timestamp of command history doesn't show time command was executed? UprLftCstr Linux - Newbie 3 04-17-2014 01:31 PM
Command/Script required to send an email alert in case command will not respond rajaniyer123 Linux - General 1 05-19-2012 02:12 PM
Executing shell command from JSP file with command line arg from URL orcusomega Programming 2 01-13-2012 04:38 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 12:21 PM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 07:30 PM


All times are GMT -5. The time now is 02:39 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration