LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2010, 11:26 AM   #1
ldesamero
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Rep: Reputation: 0
How to copy files from a partition to another


Hi All,

Now I have learned creating partition in linux (ubuntu), well that's an achievement for a newbie.

The next thing that I want to know is, how can I copy the contents of a partition to another partition. Like if I want to backup its content to a new partition that Im going to create.


Any ideas please. And Thank you
 
Old 12-10-2010, 11:31 AM   #2
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,272

Rep: Reputation: 148Reputation: 148
If both partitions mount with respective directories just use copy command "cp"
 
Old 12-10-2010, 01:02 PM   #3
ldesamero
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you for the reply kirukan, that helped me.

I was just thinking if this scenario is possible:

I have an existing partition sdb1 and I created a new partition sdb2, then copied the contents of sdb1 to sdb2. Then I deleted my sdb1 partition. Now I want my sdb2 to act as my previous sdb1 that I have deleted so that I could mount it again from the previous directory where the old sdb1 is mounted and use all the copied files or maybe also applications from the previous deleted partition; and also renaming sdb2 to sdb1?

Basically the contents of sdb2 will be a total replication of what sdb1 have before, but might have a difference in size. Example: old sdb1 is 10GB, then sdb2 is 8GB. So if you could notice, sdb1 is a copy of sdb2 that is being Shrinked in size


Any ideas from all the members here if this is possible? And if yes how can this be achieved?

For some reason I preferred using native scripts of linux, like fdisk, cp, etc and not
using other apps to achieve this.


THank you very much
 
Old 12-10-2010, 02:58 PM   #4
darkefge
LQ Newbie
 
Registered: Dec 2010
Location: Milwaukee
Distribution: Debian
Posts: 6

Rep: Reputation: 0
You would probably want to try parted/gparted. Given you are using an extended partition with sdb2 you might have to move the files to another non sdbX then fdisk sdb into one partition and move the files back. Parted does allow for partition resizes though.

http://www.gnu.org/software/parted/m...l#Partitioning
 
Old 12-10-2010, 09:15 PM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 806

Rep: Reputation: 186Reputation: 186
As implied by kirukkan's post, all you need to do is to mount sd2 instead of sd1 into the logical mount point.

So if youe earlier mount points were something like:
sd1 /usr/special
sd2 /usr/special_back

you would probably do:

cp/dd/rsycn sd1 sd2
umount /usr/special
umount /usr/special_back
mount sd2 /usr/special.

Be sure to change the default mount points also by reading `man mount` (how brokebackish).
 
Old 12-10-2010, 09:51 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by ldesamero View Post
... how can I copy the contents of a partition to another partition.
The dd command for simply copying the contents of one partition to another but dd is seldom the best choice if the partition contains a file system because a) if the old file system is fragmented the fragmentation is also reproduced b) if the new partition is bigger the extra space is unused c) if the new partition is smaller it fails d) if there is an error during copying, the resulting breakage can be extensive.

Is it a file system that you want to copy?
 
Old 01-04-2011, 07:05 PM   #7
RootAround
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
The dd command for simply copying the contents of one partition to another but dd is seldom the best choice if the partition contains a file system because a) if the old file system is fragmented the fragmentation is also reproduced b) if the new partition is bigger the extra space is unused c) if the new partition is smaller it fails d) if there is an error during copying, the resulting breakage can be extensive.

Is it a file system that you want to copy?
I'm interested to know if there's a better, preferably free, method besides dd to copy a partition. I use dd to backup my partition on the basis of this article.

As for item (b), above, I'm wondering if the resize2fs command addresses this issue.
This link seems to indicate that it can with limitations.

I've tested these 2 commands below with flat files, and backed up, but not recovered, a partition with the 1st. I'm interested in any comments more experienced administrators might have on them.

dd if=/$dirname/$filename | gzip > /ExternalFile/$filename.img.gz
gunzip /ExternalFile/$filename.img.gz -c | dd of=/$dirname/$filename

where $dirname = dev for the entire partition
$filename = hda2 (or sda2, etc.)
 
Old 01-04-2011, 08:42 PM   #8
silvyus_06
Member
 
Registered: Oct 2010
Distribution: Ubuntu 10.04 , Linux Mint Debian Edition , Microsoft Windows 7
Posts: 390

Rep: Reputation: 50
well ... i think that it would be a good idea to drag 'n' drop the files .
1.mount the 2 partitions .
2. drag drop the files from sdb1 to sdb2
3.delete sdb1 .
4. use gparted to move /dev/sdb2 and leave the free space of sdb1 to the right .
5 . mount sdb2 (if it still remains under the same name ) with the previous mount point of dev sdb1 . eg: /dev/sdb1 mountpoint is /media/files and /dev/sdb2 mount point is /media/files1 change /dev/sdb2 mount to /media/files

if that's what you want to do ... basically .. i think it's suppose to be sdb1 after you move it on the place of the free space.
 
Old 01-04-2011, 10:55 PM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If you really do want to copy a partition (which does not have to contain a file system) then dd is the tool but if you want to copy a file system then it is better to use a file copying utility such as rsync. There are other utilities such as cp, cpio and tar; some people have strong preferences.

If copying a file system from a smaller to a larger partition using dd then resize2fs can be used (on ext2, 3 and maybe 4 file systems) but this is not the best method for reasons already given in this thread.
 
Old 01-05-2011, 02:56 AM   #10
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 872

Rep: Reputation: 112Reputation: 112
sudo cfdisk /dev/yourdevice
sudo mke2fs -j /dev/yourdevice
sudo mount -t auto /dev/yourdevice /your-mount-point
cd to/your/files/you/want/to/copy
cp -R your/files/from/here to/your/files/there
sudo umount /dev/yourdevice


were your device would be would be something like /dev/sda1 /your-mount-point would be the folder you wish to mount the device too such as /mnt. the -R on the cp command allows to to copy all file and folders that are inside a folder.

Please read

man cfdisk
man mke2fs
man mount
man cd
man cp
mount umount

to get a better understanding.

Good luck
 
Old 01-05-2011, 12:40 PM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If using cp, it's better to use its --archive option.
 
Old 01-06-2011, 02:01 PM   #12
linuxunix
Member
 
Registered: Mar 2010
Location: California
Distribution: Slackware
Posts: 235

Rep: Reputation: 18
I generally prefer using this.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files from windows to linux partition nataly Linux - Newbie 6 10-09-2007 12:08 PM
Copy files from partition to partition nataly Linux - General 4 10-06-2007 10:18 PM
Copy files from Windows partition to Linux partition Shibumgeorge Linux - Software 3 04-20-2007 11:08 AM
Copy files from partition to partition too slow, SATA hard disk.What should I do£¿ Ryanlee SUSE / openSUSE 20 10-31-2005 08:30 AM
Copy files to Windows partition DavidW567 Linux - Software 5 11-16-2004 07:11 PM


All times are GMT -5. The time now is 12:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration