On Sat, Sep 27, 2008 at 7:22 PM, Aryeh M. Friedman
wrote:
> I have a disk that is laid out with partion 0 being NTFS and 1 being
> FreeBSD. I want to remove the NTFS partition and grow the FreeBSD one but
> all the docs I have seen only talk about how to do this if the new part of
> the partition is at the end of the partition you wish to grow. How do I go
> about this?


Assuming that there is no (free) software that will do it for you, and
you are unable for some reason to move the data to another place and
repartition the drive, you have to manually move your FreeBSD
partition back and then extend it. I've never done this before, but if
I had to try it the first time I would do the following:

1. Try very hard to find some other hard drive where I can just dump
the data and avoid this whole thing to begin with.
2. Boot from a FreeBSD livecd, attach a usb drive for storing some
temporary files and mount it under /mnt.
3. Create a back-up of your master boot record (dd if=/dev/ad0
of=/mnt/mbr-backup bs=512 count=1). Assuming here that your drive is
ad0.
4. Use fdisk to get the start and size values of your two partitions
(in sectors).
5. Erase the ntfs partition (dd if=/dev/zero of=/dev/ad0s1 bs=2m).
6. Copy your FreeBSD partition to the former start location of ntfs
(dd if=/dev/ad0 of=/dev/ad0 bs=512 iseek=
oseek= count=). Using
bs=512 is slow, but it makes it easier for you to just take the
numbers that fdisk gives you and plug them in.
7. Once this is done you will need to edit your mbr sector to
overwrite the first partition entry with the second, but certain
fields will need to be updated...

I recommend you use a hex editor and work on the file that you saved
in step 3. You can try the same thing with a partition editor, but you
may not get the desired results.

For the manual (and more fun) method, the partition table begins at
offset 0x01BE, and each entry is 16 bytes long. That means that you
need to copy 16 bytes starting at address 0x01CE to address 0x01BE.
However, before you do this, you need to set the correct values for
cylinder-head-sector of first and last sectors in the FreeBSD
partition, as well as the logical address of the first sector.

First, take 3 bytes starting at address 0x01BF and copy them to
0x01CF. This takes care of CHS start, which is unchanged. Next, take 4
bytes at address 0x01C6 and copy them to 0x01D6. This is the logical
sector start. The tricky bit is the CHS last sector value. If your two
partitions were of identical size, then you can copy 3 bytes from
0x01C3 to 0x01D3. Otherwise, you'll need to calculate the new values
by hand. If your NTFS partition was marked as active before, then set
byte 0x01CE to be 0x80.

One this is done, copy that second record over the first and zero-out
the 16 bytes at 0x01CE. Use dd again to copy the updated mbr sector to
your drive. At this point your master boot record will have the
correct entry for your FreeBSD partition, which was moved over the
NTFS one. See if you can mount /dev/ad0s1a while still in the livecd
environment (actually, you will need to reboot first). If ad0s1a is
under /dev and you can mount it, then your mbr is fine. Use growfs
from here and then boot from the hard drive.

As you can see, it's not a trivial thing to do, but it's possible if
you are careful. Once again, I've never done this and am basing the
whole thing on some of my previous experience in messing with the
master boot record. There may be some other things that I missed. I
also don't know if there is existing software that might make this
whole process much easier, the directions here are a worst-case
scenario for moving your partition by hand.

- Max
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/lis...reebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"