LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-25-2001, 10:50 PM   #1
system
Member
 
Registered: Dec 2001
Distribution: LFS, RH, Slack
Posts: 104

Rep: Reputation: 15
Copying a filesystem.


Is there an easy way to copy a filesystem in Linux? I currently have one ext2 filesystem with / on it. I want Linux on a different hdd. Can I copy the whole partition to the new disk? how?

Also, is it possible to resize an ext2 partition? Even if only to make it smaller, I would value this alot.
 
Old 12-25-2001, 11:57 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Yes it is possible.

You can use GNU parted shrink or grow a partition then you will need to run resize2fs to shrink the fs.

GNU parted will also copy partitions, but I'd prefer to mount the new partition and issue a command such as:
Code:
find / -xdev | cpio -pvmd /mnt
This will copy everything recursivly from / to the /mnt mount point.
 
Old 12-26-2001, 07:17 AM   #3
system
Member
 
Registered: Dec 2001
Distribution: LFS, RH, Slack
Posts: 104

Original Poster
Rep: Reputation: 15
Thank you. To shrink the fs, you would need to run resize2fs first then parted shrink, correct? To grow you would need to run them in the opposite order, correct?

Will that copy command keep special files such as /dev/* intact? Also, will it keep ownership and permissions intact?

What is the cpio command and how does it differ from cp ?

Thanks
 
Old 12-26-2001, 10:49 AM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
My last post was a bit misleading, you are correct, resize before shrinking with parted.

From the resize2fs man page:
Quote:
If you wish to shrink the an ext2 partition, first use
resize2fs to shrink the size of filesystem. Then you may
use fdisk(8) to shrink the size of the partition. When
shrinking the size of the partition, make sure you do not
make it smaller than the new size of the ext2 filesystem!
The cpio program is for creating and extracting from archives. It will preserve ownership, permissions and dates.
 
Old 12-26-2001, 11:07 AM   #5
system
Member
 
Registered: Dec 2001
Distribution: LFS, RH, Slack
Posts: 104

Original Poster
Rep: Reputation: 15
Thank you very much! I cannot wait to try this out!

This is one of many steps I am learning to do in order to make my linux box do as I wish. By the time I'm done with it, perhaps I'll know how to use linux a little hahahaha. Thanks!!
 
Old 07-08-2002, 06:17 PM   #6
jess_wundring
Newbie
 
Registered: Jul 2002
Location: Alaska
Distribution: Suse 7x & 8x
Posts: 3

Rep: Reputation: 0
I realize this thread is really old but it's come close enough to answering a question I have.
Is there's actually an advantage to creating a new partition and then using find-cpio instead of just using parted to copy it? ...or is it strictly a preference because parted is unfriendly and maybe even a little scary? How many ways are there of creating a copy of a partition?

Quote:
Originally posted by crabboy

GNU parted will also copy partitions, but I'd prefer to mount the new partition and issue a command such as:
Code:
find / -xdev | cpio -pvmd /mnt
This will copy everything recursivly from / to the /mnt mount point.
 
Old 07-08-2002, 07:33 PM   #7
system
Member
 
Registered: Dec 2001
Distribution: LFS, RH, Slack
Posts: 104

Original Poster
Rep: Reputation: 15
The reason cpio is preferred to parted has nothing to do with parted being scary or hard to use. I believe that when you copy a partition with parted, the copy will neccesarily be the same size as the original. If you are copying a small partition to a big drive and you want to use more space for the copy of the partition, you'd have to copy it, then resize it. This is tedious. cpio is preferred because it will just copy the files to a ready made partition that can be any size you wish so long as it is big enough to hold the data.
 
Old 02-14-2012, 04:42 PM   #8
romagnolo
Member
 
Registered: Jul 2009
Location: Montaletto
Distribution: Debian GNU/Linux
Posts: 107

Rep: Reputation: 5
Quote:
Originally Posted by crabboy View Post
Code:
find / -xdev | cpio -pvmd /mnt
I'm updating this for searchers' reference.
The correct syntax, at least today, is
Code:
find / -depth -xdev | cpio -pdmv /dest
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copying old HD to new? greenmeanie Debian 2 05-24-2005 12:44 PM
DISCUSSION: Virtual Filesystem: Building a Linux Filesystem from an Ordinary File mchirico LinuxAnswers Discussion 0 10-28-2004 10:35 PM
Encrypted Root Filesystem HOWTO and /dev filesystem tmillard Linux From Scratch 0 10-18-2004 03:58 PM
copying the root filesystem Nevion Linux - General 4 09-01-2003 02:57 AM
filesystem & partition copying/relocating/restoring jqpdev Linux - General 1 03-06-2003 10:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration