Bug 971326 - ntfsresize-opts execute failed when omitted the 'size' option
ntfsresize-opts execute failed when omitted the 'size' option
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libguestfs (Show other bugs)
6.5
Unspecified Unspecified
medium Severity medium
: rc
: ---
Assigned To: Richard W.M. Jones
Virtualization Bugs
: Regression
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-06-06 05:33 EDT by bfan
Modified: 2013-11-20 23:44 EST (History)
2 users (show)

See Also:
Fixed In Version: libguestfs-1.20.8-4.el6
Doc Type: Bug Fix
Doc Text:
Cause: Resizing a Windows NTFS filesystem without specifying the target (final) size. Consequence: The operation would fail. Fix: The code for resizing NTFS filesystems has been fixed. Result: You can now resize an NTFS filesystem without specifying the size, and the size is taken automatically from the target disk.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-11-20 23:44:29 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description bfan 2013-06-06 05:33:17 EDT
Description of problem:
Once the disk has been resized before, ntfsresize-opts will execute failed without the "size" option

Version-Release number of selected component (if applicable):
libguestfs-1.20.8-1.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
$ guestfish -N fs:ntfs
><fs> ntfsresize-opts /dev/sda1 size:104693760 force:true
><fs> ntfsresize-opts /dev/sda1 force:true
libguestfs: error: ntfsresize: /dev/sda1:

but if not do anything before, it can work, like
$ guestfish -N fs:ntfs
><fs> ntfsresize-opts /dev/sda1 force:true


 
Actual results:
libguestfs: error: ntfsresize: /dev/sda1:


Expected results:
command works


Additional info:
It works with libguestfs-1.22.2-1.el7.x86_64 in rhel7
Comment 3 Richard W.M. Jones 2013-06-06 07:03:47 EDT
(In reply to bfan from comment #0)
> libguestfs: error: ntfsresize: /dev/sda1:
> 

Another bug is that the error message is empty.
Comment 4 Richard W.M. Jones 2013-06-06 09:50:23 EDT
Upstream:

$ ./run ./fish/guestfish -N fs:ntfs ntfsresize-opts /dev/sda1 size:104693760 force:true : ntfsresize-opts /dev/sda1 force:true
[no errors]
$ ./run ./fish/guestfish -N fs:ntfs ntfsresize-opts /dev/sda1 force:true
[no errors]

RHEL 6.5:

$ guestfish -N fs:ntfs ntfsresize-opts /dev/sda1 size:104693760 force:true : ntfsresize-opts /dev/sda1 force:true
libguestfs: error: ntfsresize: /dev/sda1: 
$ guestfish -N fs:ntfs ntfsresize-opts /dev/sda1 force:true
[no errors]

The commands being run (in the failing case) are:

mkfs -t ntfs -Q /dev/sda1
ntfsresize -P --size 104693760 --force /dev/sda1
ntfsresize -P --force /dev/sda1

You can't see the error in guestfish, so using virt-rescue instead:

><rescue> mkfs -t ntfs -Q /dev/sda1 
Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
><rescue> ntfsresize -P --size 104693760 --force /dev/sda1
ntfsresize v2.0.0 (libntfs 10:0:0)
Device name        : /dev/sda1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 10737398272 bytes (10738 MB)
Current device size: 10737401856 bytes (10738 MB)
New volume size    : 104690176 bytes (105 MB)
Checking filesystem consistency ...
Accounting clusters ...
Space in use       : 55 MB (0.5%)
Collecting resizing constraints ...
Needed relocations : 13209 (55 MB)
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Relocating needed data ...
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device '/dev/sda1'.
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.
><rescue> ntfsresize -P --force /dev/sda1
ntfsresize v2.0.0 (libntfs 10:0:0)
Device name        : /dev/sda1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 104690176 bytes (105 MB)
Current device size: 10737401856 bytes (10738 MB)
New volume size    : 10737398272 bytes (10738 MB)
Checking filesystem consistency ...
Accounting clusters ...
Space in use       : 55 MB (51.7%)
Collecting resizing constraints ...
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])?     <<<<-----

ntfsresize waits for input at the marked place, which obviously
libguestfs/guestfish cannot provide.

This is a bug in old ntfs-3g.  Fixing it would require
a rebase to the newer upstream version.
Comment 5 Richard W.M. Jones 2013-06-06 10:01:15 EDT
Trying a slightly different test in virt-rescue.  By redirecting
/dev/null into the last command I can (probably) simulate what
libguestfs does when there is no keyboard input:

><rescue> mkfs -t ntfs -Q /dev/sda1
><rescue> ntfsresize -P --size 104693760 --force /dev/sda1
><rescue> ntfsresize -P --force /dev/sda1 </dev/null

Now (both upstream and on RHEL 6.5), the last command
performs the resize anyway:

[...]
Are you sure you want to proceed (y/[n])? Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device '/dev/sda1'.

This may indicate that upstream libguestfs effectively
sets stdin to /dev/null whereas RHEL 6.5 libguestfs does not.
Comment 6 Richard W.M. Jones 2013-06-06 11:50:09 EDT
I don't understand what's happening, but there are various issues.

I checked and libguestfs on RHEL 6.5 does set stdin of the ntfsresize
process to /dev/null.

This is a bug in ntfsresize (RHEL 6.5) which has been fixed upstream:

The question dialog does:

	printf("Are you sure you want to proceed (y/[n])? ");
	buf[0] = 0;
	fgets(buf, sizeof(buf), stdin);
	if (!strchr(short_yes, buf[0])) {
		printf("OK quitting. NO CHANGES have been made to your "
				"NTFS volume.\n");
		exit(1);
	}

If the input is /dev/null, then buf[0] will contain \0 and so
the code does strchr("Yy", '\0').  If you read the man page
for strchr closely you'll see this is a strange corner-case
which returns non-NULL.

This explains why using the explicit redirect </dev/null works
to shortcircuit this dialog.  It doesn't explain why libguestfs
isn't behaving the same way when it reopens stdin as /dev/null
for the subprocess.
Comment 7 Richard W.M. Jones 2013-06-07 07:26:30 EDT
I added a workaround for this to the libguestfs 1.20.8-4.el6
package.  Can't add this to the bug because it's not acked.
Comment 9 bfan 2013-06-17 03:31:21 EDT
Verified with libguestfs-1.20.8-5.el6.x86_64

# guestfish -N fs:ntfs

Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.

Type: 'help' for help on commands
      'man' to read the manual
      'quit' to quit the shell

><fs> ntfsresize-opts /dev/sda1 size:104693760 force:true
><fs> ntfsresize-opts /dev/sda1 force:true
><fs> 

So, change the status to verified
Comment 11 errata-xmlrpc 2013-11-20 23:44:29 EST
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2013-1536.html

Note You need to log in before you can comment on or make changes to this bug.