LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-28-2011, 09:51 AM   #1
vzxen
Member
 
Registered: Jul 2010
Posts: 126

Rep: Reputation: 4
Duplicate a partition to a smaller size


Hi,

I have one partition /dev/sda1 which is of size 10G
Its actual usage is 950M.

I want to make a copy of it in /dev/sda2 which is of 1G in size.
Is it possible to :
dd if=/dev/sda1 of=/dev/sda2
resize2fs /dev/sda2

I tried the above command and it fails to resize again.
Or can we rsync it :
rsync -avzp /mnt/sda1 /mnt/sda2

Though rsyncing works its much slower.
Also I am not fully sure of Symlinks or Hardlinks being replicated properly alongwith other permissions and ownership issues.
Will I need to add more parameters of rsync ?

dd is very fast and if there is a way, nothing like it
 
Old 06-28-2011, 05:42 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by vzxen View Post
I tried the above command and it fails to resize again.
OK, so you're letting us know it failed, but letting us know the actual error you're getting could help as your command line seems OK. Did you try zeroing root-reserved blocks (see tune2fs if extfs) before resizing the copied partition?
 
Old 06-28-2011, 06:02 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
No is the answer.
The dd will fail when the target fills. At which point the filesystem (in the target) is incomplete - read invalid. Hence any of the e2fsprogs tools (including resize) will fail.
Wait for the rsync (or similar) filesystem aware tool to complete. Data validity is more important than impatience.
 
Old 06-28-2011, 10:03 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,973

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
tar should work or other file based may be a better choice.

One can in some cases dd to a file then back to the smaller drive but it would be better to shrink the original to equal to or smaller than target then dd it.
 
Old 06-29-2011, 01:54 AM   #5
vzxen
Member
 
Registered: Jul 2010
Posts: 126

Original Poster
Rep: Reputation: 4
Hi,

tar -pzcf /file *
works but is some what slower.

Quote:
Originally Posted by unSpawn View Post
OK, so you're letting us know it failed, but letting us know the actual error you're getting could help as your command line seems OK. Did you try zeroing root-reserved blocks (see tune2fs if extfs) before resizing the copied partition?
The problem is it says that the superblock is having the wrong size of 2621440 (4k) blocks while the actual size is 262144 (4k) blocks. And then its asks to abort.
I know that this is because of the DDing of the partition, but isnt there no way to update the size to the correct values ?
 
Old 06-29-2011, 01:21 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Regarding the main issue in syg00's post can you please first confirm /dev/sda2 is an identical copy (as in 'sha1sum /dev/sda1 /dev/sda2') of /dev/sda1 before you resize slash continue?
 
Old 06-29-2011, 01:26 PM   #7
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,841

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
Why not image(clone or backup) the partition, using clonezilla, then resize the original using something like gparted-live?
If you make a mistake atleast you have a backup copy that you can restore.
Gparted-live checks for data loss before making the actual changes.

Last edited by EDDY1; 06-29-2011 at 01:28 PM.
 
Old 06-29-2011, 03:18 PM   #8
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,973

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
"The problem is it says that the superblock"

Boot to a live media and try using a file check?? Dunno if that would work but it is simple enough to try.
 
Old 06-30-2011, 12:43 AM   #9
vzxen
Member
 
Registered: Jul 2010
Posts: 126

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by unSpawn View Post
Regarding the main issue in syg00's post can you please first confirm /dev/sda2 is an identical copy (as in 'sha1sum /dev/sda1 /dev/sda2') of /dev/sda1 before you resize slash continue?
Hi,

The sha1sum fails.
Might be because of the fact that /dev/sda2 is on 1G in size.
/dev/sda1 is 10G in size and has 950 MB in usage only.

I think syg00 is right that there is no easy way of DD and then resizing.
All e2fsprogs fail.
 
Old 06-30-2011, 02:15 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by vzxen View Post
I think syg00 is right that there is no easy way of DD and then resizing.
I failed to read your OP well enough to notice you're not copying and then resizing it. It's not a problem with the tools themselves but understanding how tools work. If no space remains then I agree: use rsync or tar.
 
  


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
xmame provides smaller size in fullscreen now mark_alfred Linux - Games 1 04-09-2011 11:42 AM
Smaller Font Size In HTML runnerpaul Programming 3 06-13-2007 06:20 AM
make mpg file size smaller secretlydead Linux - Software 2 02-14-2005 08:42 AM
Total partition size - User partition size is not equals to Free partition size navaneethanj Linux - General 5 06-14-2004 12:55 PM
Why is my screen size smaller? pablowablo Red Hat 5 05-25-2004 09:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:18 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