Page 2 of 2 FirstFirst 12
Results 11 to 11 of 11

Thread: tar from stdin: piping to tar.

  1. #11
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Re: tar from stdin: piping to tar.

    Quote Originally Posted by JohnGalt131 View Post
    I want to do something like this
    Code:
    # dd if=/dev/sdX | tar -cvz /location/of/harddiskimage.tar.gz
    I am currently using the following
    Code:
    # dd if=/dev/sdX | gzip > /location/of/harddiskimage.img.gz
    However I would like to be able to add other things into the archive, not just compress the image.
    Any help is appreciated
    I believe Glennric is right, if you send standard output to tar, it needs to be a list of files to tar together; when you use "dd" to create an image, you are creating one, single huge "file" of your entire drive, so tar "cowardly" refuses to tar a single file. If you want to append files to your cloned HDD image that you create with dd, the only way I know of to do it is if the HDD image is decompressed, and then you can mount a partition (sda6 in the example below) in the HDD image by doing:
    Code:
    sudo losetup -o $((512*$(sudo sfdisk -luS harddiskimage.img 2>/dev/null | grep sda6 | awk '{print $2}'))) /dev/loop0 harddiskimage.img
    sudo mount /dev/loop0 /mnt
    And then your sda6 partition is mounted on /mnt, and you can add files to it. Essentially the code above is the same as manually doing:
    Code:
    sudo sfdisk -luS harddiskimage.img
    And then using that output to know the starting sector of your sda6 partition as "start_sector" (sda6 is just an example), then you can do:
    Code:
    sudo losetup -o $((512*start_sector)) /dev/loop0 harddiskimage.img
    sudo mount /dev/loop0 /mnt
    And that's the same thing.
    Last edited by caljohnsmith; December 11th, 2008 at 07:28 PM.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •