LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 02-17-2010, 02:42 AM   #1
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Rep: Reputation: 0
Resize NTFS img file


Hi gurus!

I was cloned an entire disk (with one NTFS partition of 70GB, only 15GB used) using ddrescue with the following command...

Code:
ddrescue --no-split /dev/sda /media/usb250/ntfs.img /media/usb250/ntfs.log
The img file it's around 70GB. Now I want to restore it to another computer with 30GB of space. How can I reduce the size of img file?

If somebody can halp me, I will be a little bit more happy
 
Old 02-17-2010, 04:10 AM   #2
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
Maybe the ntfsresize(8) command is the right one for you.
 
Old 02-17-2010, 05:06 AM   #3
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Original Poster
Rep: Reputation: 0
Thank's irmin, I tried ntfsresize before, but don't work with an entire disk image...

Code:
$ /media/DISK/$ ntfsresize -i sapbes.img
ntfsresize v2.0.0 (libntfs 10:0:0) Failed to startup volume: Invalid argument.
ERROR(22): Opening 'sapbes.img' as NTFS failed: Invalid argument The device 'sapbes.img' doesn't have a valid NTFS.
Maybe you selected the wrong partition? Or the whole disk instead of a partition (e.g. /dev/hda, not /dev/hda1)? This error might also occur if the disk was incorrectly repartitioned (see the ntfsresize FAQ).
Do you have another idea?

For now, I'm creating a new image, only with one partition...

Code:
ddrescue --no-split /dev/sda1 /media/usb250/ntfspart1.img /media/usb250/ntfs.log
After I try with ntfsresive. I will comment on changes.
 
Old 02-17-2010, 05:14 AM   #4
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
From ntfsresize(8):
Quote:
Partitioning
When recreating the partition by a disk partitioning tool, make sure
you create it at the same starting sector and with the same partition
type as before. Otherwise you won't be able to access your filesystem.
Use the 'u' fdisk command to switch to the reliable sector unit from
the default cylinder one.

Also make sure you set the bootable flag for the partition if it
existed before. Failing to do so you might not be able to boot your
computer from the disk.
You cannot apply ntfsresize to a whole harddisk, but only to partitions. So you took the right steps ...
 
Old 02-17-2010, 12:13 PM   #5
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
In post #1 you have copied a whole HDD as a whole disk image, not just the relevant partition as a partition image.

You need to get the partition out of the whole disk image, and then mount that with the -o loop option.

Fortunately, this is remarkably easy to do with linux. See this thread and read it all the way to the end before you start experimenting.

If you have created a new image of just the partition, then mount it (all as root):

Code:
modprobe  ntfs-3g
mkdir /mnt/olddisk
mount  -t  ntfs  -o  loop  /path/to/PartitionImage.iso   /mnt/olddisk
Once you have mounted the "partition" (it is really a file, but now you can treat it as a disk), you can then just copy the files to the new disk's formatted partition.

Don't forget to ummount everything before you start unplugging things.
 
1 members found this post helpful.
Old 02-18-2010, 02:33 AM   #6
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Original Poster
Rep: Reputation: 0
Ok, the command ntfsresize finish ok! ...
Code:
$ ntfsresize -s 28G sapbes.img 
ntfsresize v2.0.0 (libntfs 10:0:0)
Device name        : sapbes.img
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 73394139648 bytes (73395 MB)
Current device size: 73394141184 bytes (73395 MB)
New volume size    : 27999994368 bytes (28000 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 17519 MB (23.9%)
Collecting resizing constraints ...
Needed relocations : 1206303 (4942 MB)
WARNING: Every sanity check passed and only the dangerous operations left.
Make sure that important data has been backed up! Power outage or computer
crash may result major data loss!
Are you sure you want to proceed (y/[n])? y
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device 'sapbes.img'.
You can go on to shrink the device for example with Linux fdisk.
IMPORTANT: When recreating the partition, make sure that you
  1)  create it at the same disk sector (use sector as the unit!)
  2)  create it with the same partition type (usually 7, HPFS/NTFS)
  3)  do not make it smaller than the new NTFS filesystem size
  4)  set the bootable flag for the partition if it existed before
Otherwise you won't be able to access NTFS or can't boot from the disk!
If you make a mistake and don't have a partition table backup then you
can recover the partition table by TestDisk or Parted's rescue mode.
But the file size it's the same... (69GB instead of 28GB)
Code:
$ ls -lh
-rwxrwxrwx 1 ubuntu ubuntu 512 2010-02-18 08:42 mbr.img
-rwxrwxrwx 1 ubuntu ubuntu 69G 2010-02-18 08:04 sapbes.img
Where is the problem?

Thank's!
 
Old 02-18-2010, 02:42 AM   #7
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Original Poster
Rep: Reputation: 0
Wait a moment... if I mount the new file...


Code:
$ mount -o loop sapbes.img /mnt/temp
and look for the free space...

Code:
$ df -h
...
/dev/loop1          27GB     17GB    9.8G   63%   /mnt
...
the partition size is 27GB... ok, that sounds good!

Now I try to restore the img file to a new (little) disk.

I will comment on changes
 
Old 02-18-2010, 06:07 AM   #8
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Original Poster
Rep: Reputation: 0
No luck,

after a couple of hours, i get this error...

Code:
$ dd if=./mbr.img of=/dev/sda
0+1 records in
0+1 records out
512 bytes (512 B) copied, 0,0250117 s, 17,8 kB/s

$ dd if=./sapbes.img of=/dev/sda1
...
32 GB Copied. No space left on device
...
And windows 2003 server don't boot...

Code:
*** STOP: 0x0000007B (0xF789A63C,0xC0000034,0x00000000,0x00000000)
the 7B stop error is due to an inaccessible boot device. It probably means that the computer cannot locate the system partition.

Now, as tredegar said, I'm trying to mount sapbes.img, and copy files using 'cp' command instead of dd.

Again, I will comment on changes.

Last edited by nandelbosc; 02-18-2010 at 06:17 AM.
 
Old 02-18-2010, 10:33 AM   #9
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
But the file size it's the same... (69GB instead of 28GB)
You have resized the filesystem (to the beginning of the partition) but the partition size is the same.
So there is empty space after the filesystem on that partition.

From man ntfsresize
Code:
Shrinkage
       If you wish to shrink an NTFS partition, first use ntfsresize to shrink
       the  size  of the filesystem. Then you could use fdisk(8) to shrink the
       size of the partition by deleting the partition and recreating it  with
       the  smaller size.  Do not make the partition smaller than the new size
       of NTFS otherwise you won’t be able to boot. If  you  did  so  notwith‐
       standing then just recreate the partition to be as large as NTFS.
So you need to unmount your loop-mounted partition, and then use fdisk to repartition it to
a size that will hold your resized filesystem.

Easier, I think, is just to copy the files to a new filesystem on a partition of the right size on the disk
of your choice.
 
Old 02-18-2010, 10:56 AM   #10
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Original Poster
Rep: Reputation: 0
Ok, I tried to copy the files to a new system with the same result

I think it's a problem with the Windows 2003 and the disk controller drivers.

Now I try to explain why I'm doing this ...

We had an old server with Windows 2003. This server had a hard disk that began to fail and we cannot copy in any way (Veritas BackupExec, ntbackup, ...). To demostrate the versatility of Linux to my work colleagues I wanted to pass the old system of this machine to a host within a VMware ESX Server using Ubuntu LiveCD, but as you saw, does not boot. I think the installation of windows can not support this beasty hardware change (from an old Asus server to a VM ESX virtual host).

Tomorrow I try to restore it in another (phisical) machine with a similar hard as the initial I can.

Thank's for you support!
 
Old 02-18-2010, 11:09 AM   #11
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
Now I try to explain why I'm doing this ...
Thanks for the explanation.

What you are trying to do is "Copy Windows".

Unlike linux, win does not like to be "copied". It likes to be "reinstalled" from the original medium with the "product activation codes" etc.

We are not supposed to help you copy windows, even if it is for an understandable reason.
( Check the LQrules. )
 
Old 02-18-2010, 11:16 AM   #12
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by tredegar View Post
We are not supposed to help you copy windows, even if it is for an understandable reason.
( Check the LQrules. )
Ok, I understand and accept the forum rules... not the windows rules!

anyway, thank's again for your support!
 
Old 02-18-2010, 11:32 AM   #13
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
anyway, thank's again for your support!
That's OK.
At least you learnt something, and can now rescue your files, if not win.
 
Old 02-18-2010, 11:43 AM   #14
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Original Poster
Rep: Reputation: 0
Exactly, and as a last option, we can just buy a hard drive and return to the old Asus server with the recovered files.
 
  


Reply

Tags
ntfs, resize



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
[SOLVED] Mounting .img file (chromiumos.img); can't mount it?? Help please? linus72 Linux - General 2 11-27-2009 08:11 PM
Resize NTFS partition Sammora Linux - Newbie 5 10-21-2008 07:54 PM
NTFS resize problems xladdx Linux - Newbie 7 08-14-2006 09:24 PM
NTFS Resize cheetahman Linux - Software 11 08-01-2005 03:33 PM
resize NTFS Joey.Dale Linux - General 2 04-16-2004 02:53 PM

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

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