How to copy most of a Linux filesystem onto a new drive?

1

I am getting a SSD and I'd like it to become my new Linux boot drive. However, it is smaller than my current hard drive's root Linux partition, so I'd like to copy over the filesystem and exclude some directories (which I'll leave on another hard drive). So I can't just clone the partition with parted or similar because it is too big.

I want to make sure all the data, metadata, links and such are preserved. That seems to exclude "cp" because it doesn't preserve all the metadata and link information.

The two basic techniques I've been able to identify seem to be something like:

 find / -xdev -print0 | cpio -pa0V /mnt/dst

and:

 rsync -avP -H -S --numeric-ids / /mnt/dst

Can anyone chime in with what they've used in the past, whether one of these or a different method, or if they see any flaws in these approaches.

Nick

Posted 2011-04-06T01:59:57.387

Reputation: 11

Answers

0

Not sure what you mean by metadata. Inode numbers? A cp -a will copy all the permissions, links, etc. If you want to exclude things I would use rsync's --exclude option. If you have sparse files (probably you don't unless you are doing virtualization), then you should use the -S option if you are going to use rsync.

If its your boot drive then you'll also need to reinstall your bootloader, etc. and possibly configure your partitions.

deltaray

Posted 2011-04-06T01:59:57.387

Reputation: 1 665

0

Overall, the approach of using find and cpio should be fine (I tend to use find, xargs and tar, but that is more caused by existing knowledge of those tools). Generally, tar and cpio are made for backing up and as such they should store everything needed. However there might be some meta data they miss to include (ACL like SELinux labels), there is star that apparently have better support for this. I would expect rsync to be better than cp but worse than star in handling additional meta data.

hlovdal

Posted 2011-04-06T01:59:57.387

Reputation: 2 760