LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-26-2014, 09:33 PM   #1
MBA Whore
Member
 
Registered: May 2006
Location: Kansas City, MO
Distribution: Various: pclos, Debian, Ubuntu, etc . . .
Posts: 610

Rep: Reputation: 30
Some questions on using did command to image


I know the dd command can make a bit-by-bit clone. I know it can also make an image. The image should avoid copying unused blocks therefore that is what I want to use.

So, here are my questions:

1) What command line syntax would I use to make the dd image and compress it at the same time?

2) What command line syntax would I use to uncompress and restore the dd image at the same time?

3) What limitations regarding files system type (ext, nfts, fat, etc) and what limitations regarding hard drive size (both source and destination) do I face with this approach?

This looks like it has potential but the command line is very scary. Any insight or resources would be appreciated.

Thank you.
 
Old 09-27-2014, 04:20 AM   #2
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 304

Rep: Reputation: 121Reputation: 121
dd is not the most appropriate tool for this task because it has no way of determining which blocks are unused. To do that, you would need something else that can analyze the file system and create a list of blocks to save. I don't know how to do that, but I would like to find out.

However, if you insist on using dd, one simple approach would begin by filling the unused space with zeroes. Example:
Code:
dd if=/dev/zero of=bigfile
rm bigfile
Then create the dd image, and finally compress it with gzip or any compressor you like. The zero-filled blocks will be highly compressible.

If you execute dd and gzip as two consecutive commands, the destination would have to be large enough to temporarily hold both the uncompressed image and the compressed image. If you pipe the output of dd into gzip, you eliminate the need for temporary storage of the uncompressed image. Example:
Code:
dd if=/dev/sda1 | gzip - > dd_image_sda1.gz    #  to make the dd image and compress it

gzip -cd dd_image_sda1.gz | dd of=/dev/sda1    # to uncompress and restore the dd image
Please note, I have not actually saved or restored a dd image in this way. I've only read the manual and worked out a plan. You will have to test and debug it yourself. Before trying it on an important hard drive, I would test it on a spare drive or a small flash drive and see how that works.

Quote:
3) What limitations regarding files system type (ext, nfts, fat, etc)
The method outlined above should work for any of those file systems, provided it is not encrypted or compressed.
 
Old 09-27-2014, 08:57 AM   #3
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,176

Rep: Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835
let's take 1 step back:

what are you trying to achieve with that?
 
Old 09-27-2014, 02:54 PM   #4
jomen
Senior Member
 
Registered: May 2004
Location: Leipzig/Germany
Distribution: Arch
Posts: 1,687

Rep: Reputation: 54
To simply answer the questions:

There is no way to avoid copying unused blocks using dd.
It creates a bit-by-bit copy. That includes all blocks, of course.
All you can do is fill the empty space with zeroes, so that the compressed image will be small (the zeroes compress very well to almost nothing).
See the example by beryllos.

1.)
Code:
dd if=/dev/sda conv=sync,noerror bs=64K | gzip -c  > /mnt/sdb1/sda.img.gz
2.)
Code:
gunzip -c /mnt/sdb1/sda.img.gz | dd of=/dev/sda
/dev/sda is your source, /dev/sdb1 is some drive you use to store the backup image to.

3.)
There are no limitations on filesystems at all - dd does a bit by bit copy and does not care at all about filesystems.

The target must be of equal or larger size than the original. A smaller target disk (where you want to restore to) is not possible with this.

I lifted the info from here and have indeed actually successfully used it multiple times:
https://wiki.archlinux.org/index.php/disk_cloning
 
Old 09-27-2014, 11:19 PM   #5
MBA Whore
Member
 
Registered: May 2006
Location: Kansas City, MO
Distribution: Various: pclos, Debian, Ubuntu, etc . . .
Posts: 610

Original Poster
Rep: Reputation: 30
Interesting. I was hoping to make a backup (image) that would avoid unused blocks but it looks like I can't do so. I will just look for some other imaging solution. Thank you all.
 
Old 09-28-2014, 09:31 AM   #6
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,176

Rep: Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835
rsync?
 
Old 09-28-2014, 09:33 AM   #7
jomen
Senior Member
 
Registered: May 2004
Location: Leipzig/Germany
Distribution: Arch
Posts: 1,687

Rep: Reputation: 54
See if fsarchiver or partimage (part of clonezilla) suit your purpose.
 
Old 10-06-2014, 02:27 PM   #8
RockDoctor
Senior Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Linux Mint, Ubuntu
Posts: 1,504

Rep: Reputation: 325Reputation: 325Reputation: 325Reputation: 325
FWIW, I've been using fsarchiver to make backup images, and have found it to work well enough.
 
  


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
Some questions on changing the boot splash of an ISO image Ru1138 Linux - Newbie 2 08-10-2014 11:32 PM
Kernel image corrupted : Wrong Image Format for bootm command ERROR: can't get kernel blink182 Linux - Embedded & Single-board computer 0 05-13-2011 04:11 AM
PHP - some questions about image selection kazuni Programming 1 07-10-2009 06:56 AM
mounting usb drive image questions windowlicker Linux - Hardware 5 07-05-2007 10:39 PM
Few questions, HTML image links Taigrr Programming 2 02-28-2006 06:50 PM


All times are GMT -5. The time now is 07:04 AM.

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