1

Topic: Resizing/moving Windows 7 partitions

I've been using the GParted LiveCD for a while now for all my partitioning needs and so far it was a really great tool. However, I recently moved from Windows XP to Windows 7, and that's where the problems began. At first I had a triple boot setup - openSUSE, WinXP and Win7. XP was on the first primary partition, Win7 was on the second primary partition, GRUB boot loader was on the third primary partition and openSUSE with all its partitions was on an extended partition. Then I realised that I didn't allocate enough space for my WinXP installation, so I used GPartEd to take some space from my logical partitions. Naturally the process involved moving the Win7 partition, and when I checked, it didn't boot! I decided that it was probably just bad luck, reinstalled it since it didn't have much on it anyway and continued using XP as my primary OS.
Now recently I decided to move on to Win7 and get rid of the old WinXP partition altogether, and then add the remaining space to the Win7 partition. Everything was completed, but... Once again, Win7 didn't load! It gave me the error "The boot selection failed because a required device is inaccessible." I tried using the Win7 DVD repair options as asked by the error message, but it didn't find any Windows installations for some reason! When I used the command prompt command "bootrec /fixboot", it also complained about having no valid file systems, yet it found the installation. So right now I reinstalled Win7 and checked if its own partition manager is any good in hopes that I may use it to deal with Win7 partitions and GParted for the rest, but it seems that Microsoft didn't progress any...
So I'm left with a question - is there any safe way to resize or move Windows 7 partitions, without breaking its obviously too sensitive boot loader? I don't want to reinstall my system every time I want to add or remove some space from this partition...

2

Re: Resizing/moving Windows 7 partitions

Hello GreatEmerald,

1. Windows doesn't "see" Linux partitions, unless they use a Windows filesystem ( rare exception !)
2. Windows doesn't recognize Linux bootmanagers ( neither their Boot Records nor their menu scripts ).
3. Windows bootmanagers are not able to start Linux (well, there might be an exotic workaround with "Grub4DOS").
4. Linux  doesn't need neither a primary partition nor the "activity" (boot-) flag.
5. "GParted" regularly deletes the bootflag. It must be reset to the appropriate state afterwards.


In consequence, when installing a new Windows version to create a multiboot system:

1. The newer system is able to coexist with its predecessor and integrates it automatically in its bootmanager during installation, but NEVER the other way round.
2. Windows writes its own Master Boot Record to first sector of bootable device ( always overwrites Boot Record of Linux bootmanager )
3. If already set, Windows uses "active" partition to install its own bootmanager (and the dependencies). This is very important for multiboot Windows systems, because "active" partition is always drive C, and the older system must NOT loose its drive letter, which is thousand of times contained in its registry.
4. The system files of the new Windows version may be on an arbitrary partition, even on a logical volume in an extended partition.
5. After completed installation drive letter of latest Windows version is also fixed (not reassignable).

So what might go wrong ?

1. Concerning bootflag:
- boot partition is no more "active" (drive letters change!), no partition or more than one is set "active".
- extended partition is set "active" ( "activity" flag is only possible on primary partitions. Which one of the logical volumes should be booted, if the flag is on the whole "container" ?)

2. Concerning repartitioning:
- a partition in front of the "active" partition was deleted and unallocated space integrated to the "active"
  Case A : "Invisible" for Windows - partition data change, but same VolumeID
  Case B : Visible for Windows - drive letters and partition data change, but same VolumeID
 
3. Concerning drive cloning:
- Both drives have the same VolumeID, but different sizes. 
 
4. Registry key "MountedDevices" and "pagefile.sys" were NOT deleted, before repartitioning, i.e. Windows remembers the old partitioning and notices differences.

What went wrong with your system ?

Probably the old Win XP system had the "activity" flag (first partition suggests the assumption, that it was primary to all other OS), was drive C , and therefore got Win7 bootmanager. By deleting it, bootmanager is gone. Drive letter C jumps over either to the "active" successor or the former drive D. All other drive letters shift, except those, which you assigned. I further assume, that you did not delete registry key "MountedDevices" and file "pagefile.sys" (with Linux) in advance.

Regards
cmdr

3

Re: Resizing/moving Windows 7 partitions

Most of the things you mentioned here I already knew, except for MountedDevices and pagefile.
My setup has a special primary active partition that has nothing but GRUB installed. Before changing anything, the boot flag was set on it, and after that it was set on the Windows 7 partition. The Windows 7 installation had its main disk as F:, with C: being Windows XP, which got deleted.
To simplify things, here's a list of partitions before and after the process:

  1. NTFS, Windows XP, C:, primary

  2. NTFS, Windows 7, F:, primary

  3. EXT2, GRUB, /boot, primary active

  4. Extended, containing Linux and storage partition

And after that I have:

  1. NTFS, Windows 7, F: (C: after reinstall), primary

  2. EXT2, GRUB, /boot, primary active

  3. Extended, containing Linux and storage partition

So I guess I should have deleted those two files before partitioning; however, today I found out that Linux wasn't booting as well. The problem there was that for some unknown reason, the /boot partition changed its location in the drive list (so in /etc/fstab, the /boot partition was earlier marked as DRIVENAME-part3, and somehow it changed to DRIVENAME-part2, and since fstab wasn't changed, Linux refused to boot), even though I didn't even touch the /boot partition. So what could be the cause of that, and are these boot problems related to each other?

4

Re: Resizing/moving Windows 7 partitions

Cmdr has provided some very useful information.  Further to this I would like to add the following:

If you are using GRUB for your boot loader, and the /boot partition was moved then you might have encountered the problem stated in FAQ point #10.

10 : After moving or resizing my GRUB boot partition, GRUB fails to boot. How can I fix this?

The cause of this problem is that the absolute physical hard disk sector containing the start of the stage2 file has changed. When GRUB is installed, this absolute position is hard-coded into GRUB stage1.

GRUB stage1 might be installed in one of two places; at the beginning of the hard disk, or at the beginning of the boot partition.

To fix this problem you will need to reinstall GRUB. This will update stage1 with the new hard-coded absolute position of the stage2 file.

More information can be found at the following link:
Fixing GRUB Boot Problem


With logical partitions, if a logical partitions is deleted earlier in the chain, then all following logical partitions will change partitions numbers.  See the GParted manual CAUTION in the deleting a partition section (It is filed under Basic Partition Actions).
GParted Manual

5 (edited by GreatEmerald 2009-10-28 21:56:12)

Re: Resizing/moving Windows 7 partitions

Well, GRUB itself loaded just fine, except that it didn't let me graphically select boot options, I had to do that with the command line (and since for some reason the part of the disk the /boot partition was on changed, Linux didn't boot correctly).
As for the order of the logical partitions, I'm aware of that - that's the reason why you don't use /dev/sda* style paths to partitions in /etc/fstab. Instead you use /dev/disk/by-id/ata-DISKNAME-part*, and for me the ID of /boot partition changed after I deleted Windows XP partition and allocated the empty space to the Windows 7 partition...

6

Re: Resizing/moving Windows 7 partitions

GreatEmerald wrote:

As for the order of the logical partitions, I'm aware of that - that's the reason why you don't use /dev/sda* style paths to partitions in /etc/fstab. Instead you use /dev/disk/by-id/ata-DISKNAME-part*, and for me the ID of /boot partition changed after I deleted Windows XP partition and allocated the empty space to the Windows 7 partition...

Feel free to correct me if I am wrong, but I thought that the /dev/dis/by-id/ata-DISKNAME-part* were simply symbolic links to the respective partition.

For example:
/dev/disk/by-id/ata-SAMSUNG_HD160JJP_S0DFJ1HL426439-part7 -> /dev/sdc7

If an earlier logical partition was deleted, such as /dev/sdc5, then upon reboot the above link would become:
/dev/disk/by-id/ata-SAMSUNG_HD160JJP_S0DFJ1HL426439-part6 -> /dev/sdc6

Hence the number at the end of the part* will always match the /dev/sdc#.

At least that is my understanding.

If you wish to have something more permanent in /etc/fstab, my recommendation would be to use either the volume label, or the UUID.

7

Re: Resizing/moving Windows 7 partitions

Hello GreatEmerald,

And after that I have:
   1. NTFS, Windows 7, F: (C: after reinstall), primary
...

How did you assign the new drive letter F to first primary partition ? Just by moving the activity flag back to the Grub partition ? How do you know, that Win7 partition got F, if it boots no more ? Are there other (Windows) disks involved, which also have "active" partitions (Grub partition is invisible !)?

If you (re)install Win7 on a first primary partition of a single built-in disk, it always gets drive letter C, even if you remove the activity flag ... and it won't run with any other letter assigned. If "bootmgr" and "winload.exe" and a correct BCD registry are present on primary partition, Win7 should be able to boot and in worst case launch a STOP fault, if access to the altered harddisk or  NTFS is logically or physically not totally possible.

I would try to get Win7 work again isolated first. Reinstall a Win7 MBR, set the activity flag on first primary partition and try to repair Win7. Most of all let "chkdsk /f /r " run several times to correct all filesystem faults. Then reinstall Grub and add Win7 boot sequence in "menu.lst". Drive is ...DISKNAME_part1.  However, it might be easier to reinstall Win7 to the first primary partition; it's your choice. An alternative to "Grub" is "Grub4DOS", which doesn't need its own Master Boot Record. You just need two files, "grldr" and "menu.lst" in root folder of drive C. To use it with Win7 Boot Records just rename "bootmgr" to "w7ldr" and "grldr" to "bootmgr",  "chainload" w7ldr (in menu.lst) and Win7 runs. All Linux distros are startable by "Grub4DOS", too.

BTW, its possible to delete registry key "MountedDevices" afterwards with a Linux program, look here.

Regards
cmdr

8

Re: Resizing/moving Windows 7 partitions

gedakc, very interesting point here... I've looked it up, and it seems that Ubuntu Wiki has the most info on that:
https://help.ubuntu.com/community/UsingUUID
However, it's still complicated - the first paragraph there says that UUIDs are generally better, but what do they mean by saying "all physical devices should be specified by a symlink, like /dev/cdrom for a cd drive and /dev/disk/by-id/... for each physical hard drive"? Also, the fact that you can use labels is very interesting as well, but can you use it for hard drives? It would be very intuitive to use.
UUIDs would be nice, but don't they change for partitions, if they get moved/expanded/shrunk?

cmdr, the F: letter was assigned by Windows 7 automatically somehow. First I had Windows XP only, it was on C:, and when I installed Windows 7, it automatically set itself as F:, retaining C: for Windows XP and other drives from Windows XP configuration. I guess it read the configuration when I launched the installation program from Windows XP. And now, when I reinstalled it, Win7 saw that there was nothing mounted as C:, so it took the letter for itself. Another strange thing that I should note is that I now have two options from Windows 7 BCD every time I boot - Windows 7 and Windows 7, with the lower one still giving me the same "boot selection failed" error.
I tried Checkdisk, and it reported no problems. During the reinstall, the system ran Checkdisk by itself, and didn't find anything bad as well.

So, to sum up, Windows 7 didn't want to boot because of me not paying attention to MountedDevices, PageFile and maybe having it set as disk F:, while Linux didn't boot because fstab had non-UUID links set, right? So if I now want to add some more space from the front of my first partition to the first partition, I would just have to move the partition, then expand it, and in theory nothing bad should happen this time, since I won't be deleting any partitions?

9

Re: Resizing/moving Windows 7 partitions

Hello GreatEmerald,

Another strange thing that I should note is that I now have two options from Windows 7 BCD every time I boot - Windows 7 and Windows 7, with the lower one still giving me the same "boot selection failed" error.

The explanation is, that the new installation detected the old one as predecessor and dutyfully integrated it into its boot menu. Now, we have the chance to look, where the wrong link points to. You might use "BCDEdit" to give us the knowledge ... and to delete the wrong item.


So, to sum up, Windows 7 didn't want to boot because of me not paying attention to MountedDevices, PageFile and maybe having it set as disk F:

You summarized it clearly ! Respect it with resizing ! Be sure to uncheck "align to cylinder border", when resizing the first primary partition; an unintended move of the lower border might occur or you loose some space ( one cylinder ).

It's a good idea to store a fdisk -lu print-out of the present state before you resize, to see the "Hidden Sector" size, which might be a problem afterwards.

BTW, why didn't you delete the old installation and reinstall Win7 immediately on a new created bigger first partition ?

I would just have to move the partition, then expand it, and in theory nothing bad should happen this time, since I won't be deleting any partitions?

Yes, in principle ... but its NTFS ! A mismatch between file system size and device size as result isn't rare. Run "ntfsresize" simulation (independent from "GParted") to get appropriate values and give enough space for the second MFT, which is OUTSIDE the filesystem.

Regards
cmdr

10

Re: Resizing/moving Windows 7 partitions

cmdr wrote:

Now, we have the chance to look, where the wrong link points to. You might use "BCDEdit" to give us the knowledge ... and to delete the wrong item.

Hmm, how do I actually use BCDEdit? When opened without any arguments, it says "The boot configuration data store could not be opened."

BTW, why didn't you delete the old installation and reinstall Win7 immediately on a new created bigger first partition ?

I wanted to keep the data on the old Win7 partition. But since it was a no-go, I reinstalled it.

Run "ntfsresize" simulation (independent from "GParted") to get appropriate values and give enough space for the second MFT, which is OUTSIDE the filesystem.

Which values should I note?

11

Re: Resizing/moving Windows 7 partitions

Hmm, how do I actually use BCDEdit? When opened without any arguments, it says "The boot configuration data store could not be opened."

Use "EasyBCD" (Windows Vista version) instead. Download it here. But "BCDEdit" should have been able to open BCD !

ntfsresize: Which values should I note?

You simulate a resizing operation with wanted values and the program tells you, if its possible or which values should be used instead. Use a "verbose" output to get all details. You may redirect output to a file ( ntfsresize ... > /root/ntfsresize.log). Look here for a ntfsresize "man" page. Do simulations only.

Regards
cmdr

12

Re: Resizing/moving Windows 7 partitions

I tried EasyBCD as well, but it says this when launched:

"Valid BCD Registry not Detected.
EasyBCD has detected that your BCD boot data and MBR are either not from the latest version of Windows Vista, or don't yet exist.
If you'd like EasyBCD to correct these issues, press OK. This will modify the MBR and requires that you have Windows Vista installed on this machine. You can cancel at any time. Press 'No' to exit EasyBCD now."
So I have two options - cancel and do nothing or accept and be in danger of deleting a boot option or worse... Any ideas?

13 (edited by GreatEmerald 2009-10-30 11:54:45)

Re: Resizing/moving Windows 7 partitions

FDisk output:

dainius@SuseMain:~> sudo /sbin/fdisk -lu

Disk /dev/sda: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x000cfd8e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1          385560    47456009    23535225    7  HPFS/NTFS
/dev/sda2   *    47456010    47632724       88357+  83  Linux
/dev/sda3        47632725   625137344   288752310    f  W95 Ext'd (LBA)
/dev/sda5        47648790   440470169   196410690    7  HPFS/NTFS
/dev/sda6       440470233   532731464    46130616   83  Linux
/dev/sda7       532731528   536940494     2104483+  82  Linux swap / Solaris
/dev/sda8       536940558   578356064    20707753+  83  Linux
/dev/sda9       578356128   625137344    23390608+   c  W95 FAT32 (LBA)

Note how sda1 has a rather big Start value, and that sda5 doesn't start at the same place as sda3 - for some reason there is like 8MB of unpartitioned space there, and I can't get rid of it for some reason...

And this is what ntfsresize gives me:

dainius@SuseMain:~> sudo /usr/sbin/ntfsresize /dev/sda1 -inv
ntfsresize v1.13.1 (libntfs 9:0:0)
Device name        : /dev/sda1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 24100065792 bytes (24101 MB)
Current device size: 24100070400 bytes (24101 MB)
Checking for bad sectors ...
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 22100 MB (91,7%)
Collecting resizing constraints ...
Estimating smallest shrunken size supported ...
File feature         Last used at      By inode
$MFT               :     23266 MB             0
Multi-Record       :     23649 MB        128092
$MFTMirr           :      8744 MB             1
Compressed         :     23649 MB        139248
Sparse             :     23263 MB         57522
Ordinary           :     23650 MB        136884
You might resize at 22099841024 bytes or 22100 MB (freeing 2001 MB).
Please make a test run using both the -n and -s options before real resizing!

So, what should I do with this data?

EDIT: Also, changed the fstab to boot only by labels (and swap by UUID - no sense in labelling it I guess). For some reason, though, openSUSE's YaST2 doesn't want to automatically add NTFS partitions by label, but when done manually it works correctly. I always thought labels were only for convenience, but fancy that, they are also very useful big_smile