Thread: Sending Files on Removable Media to stdin

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273

    Sending Files on Removable Media to stdin

    Hello,

    I'm in the process of selling my laptop (alas, I have fallen to the tablet disease ) and in a bid to improve its saleability have opted to supply it crud-free (fresh W7 SP1 install, one or two of the nice Lenovo tools but that's it. No Norton).

    I would also like to provide a backup of this configuation on DVDs. This would be a straight snapshot of the HDD, so if it was used in another system Windows would winge and de-activate and crash, most likely.

    After reviewing a couple of Linux-based backup solutions, I have found that they generally don't support restoration from removable media (compressed, my image takes up 2 and-a-bit DVDs).

    To me, the problem is simple: given the usual way of passing data from a file in Linux, i.e:-
    Code:
    cat file1 file2 file3 >program
    ...find a way of getting the terminal to prompt to change media after every successive file, without closing stdin (causing the problem to think it's finished) and automounting the media when inserted.

    I think this would be best solved "the Linux way", without resorting to C. But I suspect cat would need to be swapped out for this to work properly.

    Has this problem already been solved?

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    1): You can't really accept the "Windows 7" EULA on behalf of the purchaser. You need to use the "oem sysprep" tools to reset the "license accepted" flag.

    2): I don't know what you are smoking, but "GNU/Linux" administration discs support restoration from and to just about everything including multiple discs. You will need a live disc that allows you to install everything temporarily to a memory partition so that tools don't need to be read from the disc.

    3): You can create temporary duplicates of the standard handles under most shells before redirecting "stdout" for a child. You could easily duplicate "stdout", redirect "1" to a file, create a child shell, use any tools with which you are familiar that writes to "stdout", and simply write to the duplicated handle for the "insert next disc" prompt.

    4): Use "Clonezilla", either the tool on any distribution you like of just use that as a distribution, to copy only the install partition. (Yes. You can do this with just "dd" and "cat", but you should not.) You can backup/restore only the install partition allows a data partition. If you have enough space, you can also have a recovery partition allowing the install image to continue residing on the disc.

    5): Don't forget to clone the "bootstrap", wherever it may live, so that recovery may conditionally recover that component if you change to just imaging the install partition.

    Soma

    I am not a lawyer.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Actually I did sysprep the image, thank you. Getting my Windows 8 Deployment certification was one of the proudest moments of my life, sniff.
    (OOBE is on so it does the EULA, create new account, etc. Generalize is off, so it doesn't re-detect the hardware)

    Forgot to mention that the HDD is an SSD, and I would like to minimize writes.

    Many of the backup tools that I have tried (and I have tried Clonezilla) are reliant on ntfsclone, which has no direct way of reading split images. Most of these would like to reassemble the image from its pieces before feeding to ntfsclone, and the laptop doesn't have enough RAM to do that. Treating the partitions as opaque (dd) would need more DVDs to hold the result.

    I made sure to get hold of the boot area of the drive, this has caused problems in the past when VirtualBoxing stuff.

    I am v. interested in your point 3 though and would like to subscribe to your newsletter.

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Most of these would like to reassemble the image from its pieces before feeding to ntfsclone, and the laptop doesn't have enough RAM to do that.
    O_o

    They are then, if taken at your word, doing it wrong.

    However, "most" would actually concatenate the image "live", without resorting to a temporary file, which is exactly still what you need to accomplish.

    The only change you need to make is, effectively, asking "continue?" allowing time for the client to swap discs between files.

    You can do that in a billion different ways with the standard shells and "POSIX" tools. You could use a named pipe. You could duplicate the identifier. You could use `dd' with redirection to oddly adjust the offset. I could literally continue for at least twenty minutes.

    [Edit]
    Yes. If you are really uptight and know exactly what you need, you can do this in a single line: `exec 3>&1 && ((cat in1.txt && echo "enter to continue" 1>&3 && read >/dev/null && cat in2.txt)>out.example.txt) && exec 3>&-'.
    [/Edit]

    Soma

    Code:
    #!/bin/bash
    
    exec 3>&1
    
    dump() {
      local FILENAME="."
      #"$CONTINUE" == "y"
      while [[ "$FILENAME" != "" ]]; do
        read -p "enter the next filename:" FILENAME 1>&3
        [[ -a "$FILENAME" ]] && cat "$FILENAME"
      done
    }
    
    # dump | clonezilla ???
    dump >"out.example.txt"
    Last edited by phantomotap; 07-11-2014 at 03:58 PM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Thanks, I shall have a play with that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sending Files with Email using dev C++ (help).
    By Roleaxes in forum C++ Programming
    Replies: 9
    Last Post: 02-02-2013, 09:14 AM
  2. Sending two files in one command?
    By Mankthetank19 in forum C Programming
    Replies: 13
    Last Post: 12-11-2008, 04:13 PM
  3. eject removable media
    By geek@02 in forum Windows Programming
    Replies: 2
    Last Post: 09-28-2005, 02:36 PM
  4. sending files
    By majoub in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-06-2005, 11:08 AM
  5. Sending Files
    By marco in forum C++ Programming
    Replies: 1
    Last Post: 12-19-2001, 06:45 PM