Juanito
Group: Members
Posts: 1601
Joined: Sep. 2005 |
|
Posted: Jan. 11 2007,18:58 |
|
After much Google searching I managed to find out how to use ntfsprogs to shrink the partition on a hd with a single ntfs partition in order to make room for a second partition to be formatted for a DSL hd install.
This was run from a combination floppy, usb stick boot using DSL 3.2RC3
First install ntfsprogs:
# apt-get install ntfsprogs
Get ntfs info on the drive you wish to partition - note that I tried this on four ntfs hd and only one did not have errors (that windows had not reported), luckily it was the one I wanted to partition:
# ntfsresize --info /dev/sdc1 ntfsresize v1.9.4 NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 36701164032 bytes (36702 MB) Current device size: 36701167104 bytes (36702 MB) Checking filesystem consistency ... 100.00 percent completed Accounting clusters ... Space in use : 8025 MB (21.9%) Collecting shrinkage constrains ... Estimating smallest shrunken size supported ... File feature Last used at By inode $MFT : 608 MB 0 Multi-Record : 7944 MB 3712 You might resize at 8024940544 bytes or 8025 MB (freeing 28677 MB). Please make a test run using both the -n and -s options before real resizing!
Next make a test run - in this case I emulated shrinking the 36GB single partition to 25GB:
# ntfsresize --no-action --size 25000M /dev/sdc1 ntfsresize v1.9.4 NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 36701164032 bytes (36702 MB) Current device size: 36701167104 bytes (36702 MB) New volume size : 24999993856 bytes (25000 MB) Checking filesystem consistency ... 100.00 percent completed Accounting clusters ... Space in use : 8025 MB (21.9%) Collecting shrinkage constrains ... Needed relocations : 0 (0 MB) 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 ... The read-only test run ended successfully.
Assuming you made a back-up, take a deep breath and go for the real thing:
# ntfsresize --size 25000M /dev/sdc1 ntfsresize v1.9.4 NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 36701164032 bytes (36702 MB) Current device size: 36701167104 bytes (36702 MB) New volume size : 24999993856 bytes (25000 MB) Checking filesystem consistency ... 100.00 percent completed Accounting clusters ... Space in use : 8025 MB (21.9%) Collecting shrinkage constrains ... Needed relocations : 0 (0 MB) WARNING: Every sanity check passed and only the DANGEROUS operations left. Please make sure all your important data had been backed up in case of an unexpected failure! 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) Updating $BadClust file ... Updating $Bitmap file ... Updating Boot record ... Syncing device ... Successfully resized NTFS on device '/dev/sdc1'. You can go on to shrink the device e.g. with 'fdisk'. IMPORTANT: When recreating the partition, make sure you 1) create it with the same starting disk cylinder 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 may lose your data or can't boot your computer from the disk!
Read the ntfs info again to check that the expected happened:
# ntfsresize --info --force /dev/sdc1 ntfsresize v1.9.4 NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 24999993856 bytes (25000 MB) Current device size: 36701167104 bytes (36702 MB) Checking filesystem consistency ... 100.00 percent completed Accounting clusters ... Space in use : 8025 MB (32.1%) Collecting shrinkage constrains ... Estimating smallest shrunken size supported ... File feature Last used at By inode $MFT : 608 MB 0 Multi-Record : 7944 MB 3712 You might resize at 8024584192 bytes or 8025 MB (freeing 16975 MB). Please make a test run using both the -n and -s options before real resizing!
Make a back-up of the partition table and master boot record:
# sfdisk -d /dev/sdc > /path-to-file/sdc.pt # dd if=/dev/sdc of=/path-to-file/sdc.mbr bs=512 count=1 1+0 records in 1+0 records out 512 bytes transferred in 0.015464 seconds (33109 bytes/sec)
Take a deeper breath and make a new partition table:
# fdisk /dev/sdc
The number of cylinders for this disk is set to 4462. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): m Command action d delete a partition m print this menu n add a new partition p print the partition table t change a partition's system id w write table to disk and exit
[list the existing partition - actually the one before resizing]
Command (m for help): p
Disk /dev/sdc: 36.7 GB, 36703934464 bytes 255 heads, 63 sectors/track, 4462 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdc1 1 4462 35840983+ 7 HPFS/NTFS
[delete the existing partition table since ntfsprogs changed it]
Command (m for help): d Selected partition 1
[create a new partition table entry, Google suggested to make it slightly larger than the ntfsprogs resize, hence +25140M instead of +25000M]
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-4462, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (1-4462, default 4462): +25140M
[set the fs type to ntfs - note it must be ntfs]
Command (m for help): t Selected partition 1 Hex code (type L to list codes): 7 Changed system type of partition 1 to 7 (HPFS/NTFS)
[Check things look OK]
Command (m for help): p
Disk /dev/sdc: 36.7 GB, 36703934464 bytes 255 heads, 63 sectors/track, 4462 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdc1 1 3057 24555321 7 HPFS/NTFS
[Write the new partition table]
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks.
Check ntfs info one final time
# ntfsresize --info --force /dev/sdc1 ntfsresize v1.9.4 NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 24999993856 bytes (25000 MB) Current device size: 25144648704 bytes (25145 MB) Checking filesystem consistency ... 100.00 percent completed Accounting clusters ... Space in use : 8025 MB (32.1%) Collecting shrinkage constrains ... Estimating smallest shrunken size supported ... File feature Last used at By inode $MFT : 608 MB 0 Multi-Record : 7944 MB 3712 You might resize at 8024584192 bytes or 8025 MB (freeing 16975 MB). Please make a test run using both the -n and -s options before real resizing!
Now reboot under Windows - ntfsprogs set the ntfs chkdsk flag so windows checks the disk integrity during the first boot. If everything went OK, in my case it did, the Windows disk management service saw a 23.42GB ntfs partition and a 10.76GB unallocated partition.
Hope this helps.
|