...making Linux just a little more fun!

2-Cent Tips

2-cent Tip: Copying a partition

Kapil Hari Paranjape [kapil at imsc.res.in]


Mon, 19 Mar 2007 22:19:34 -0700

Hello,

Here is a way to copy a partition which is mounted without copying all the other partitions that are under it.

Let /patha be the mountpoint of the partition from which you want to copy (it could even be the root path /).

Let /dev/new be the device to which you want to copy the data.

	mkdir /var/tmp/src
	# The bind mount is the crucial thing!
	mount --bind /patha /var/tmp/src
	mkdir /var/tmp/target
	mount /dev/new /var/tmp/target
	cd /var/tmp/src
	# I find this a neat way to copy all files
	# and permissions
	find . | cpio -pdum /var/tmp/target
	umount /dev/new
	umount /var/tmp/src
	rmdir /var/tmp/{src,target}
And you are done! I hope the above commands are self-explanatory. If not, then I can explain further.

Kapil. --

[ Thread continues here (5 messages/4.94kB) ]


Talkback: Discuss this article with The Answer Gang

Copyright © 2007, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 137 of Linux Gazette, April 2007

Tux