Wednesday, February 22, 2012

cp: An amazing swiss knife of GNU

  The other day I was banging my head wondering how to infuse life (read, extra space) into my ageing laptop and into the Arch Linux installation, which, by the way, is turning five this year. The rolling release model and its light-weight packaging has bitten me way back in 2007. I had used my old 80GB, Turion 64x2, 1.5GB DDR2 Presario V3029AU to the maximum, and it's showing.

   Last week, I tried to install Oracle 10g XE on Fedora 16 and it asked for a minimum of 1024MB of swap, a whisker short of what my harddisk actually had. So, I was only left with one dreaded option: to re-format my internal drive and to make space for three Linux distros and a Windows 7 x64 primary partition with sufficient swap space. For that, I had to retain the contents of my Arch. A few options I found after scouting the Internet were:
  1. Use dd to take an as-is backup of the partition to an image file
  2. Use clonezilla to take backup to an image file
  3. Use partimage
  4. Use cp to simple copy all the files onto a separate "linux-compatible" filesystem (read, one which retains the permissions and ownership of the files)
  Obviously, as my main intention was to expand in-place the partition or move files onto a bigger partition, the first option was ruled out. Clonezilla had to be used by burning the live iso  onto a CD or a pen drive. The only sensible option I was left with was to use cp.

cp -ax /source-path/* /destination-path/

   Mind you, I didn't know what all cp could do even after using it for the past seven years on a daily basis. This command simply copies all the files onto the new partition, of course, with all the necessary bells and whistles such as permissions, file ownership and other necessary attributes. Note the two command-line options "-a" and "-x". The latter is to indicate to cp that only one file system needs to be copied. Ignoring this option will end you up with copies of files present on mounted partitions too on your new partition. These two options are absolutely essential for your new partition to work as intended.

  This left me with sufficient space (13GB each) for Arch , LMDE and Fedora 16.

  This scenario reinforces the simplicity of design and everything-is-transparent-to-user philosophy of GNU/Linux. And, cp truly is an amazing swiss knife of it!