Thursday, January 26, 2012

HowTo: Mounting NTFS partition in write mode on FreeBSD

My brother's old laptop died and I got to keep its hard-drive. Being a Windows machine, it had a bunch of NTFS partitions. So this post explains how to identify a NTFS partition, mount it as read-only and finally learn how to mount it in write mode. I should mention that FreeBSD 7.4 was used but the same steps should apply to latter versions of the OS.

Physically attached the hard-drive (in my case I plugged an USB HDD) and have a look at /var/log/messages to identify the harddrive.
% su
# tail -n 20 /var/log/messages
Jan 26 21:40:03 flumen kernel: da0: Fixed Direct Access SCSI-4 device
Jan 26 21:40:03 flumen kernel: da0: 40.000MB/s transfers
Jan 26 21:40:03 flumen kernel: da0: 114473MB (234441648 512 byte sectors: 255H 63S/T 14593C)
Similar information can be collected from dmesg.
# dmesg
umass0: on uhub4
da0 at umass-sim0 bus 0 target 0 lun 0
da0: Fixed Direct Access SCSI-4 device
da0: 40.000MB/s transfers
da0: 114473MB (234441648 512 byte sectors: 255H 63S/T 14593C)
Let's find out which is the NTFS partition:
# fdisk /dev/da0
******* Working on device /dev/da0 *******
parameters extracted from in-core disklabel are:
cylinders=14593 heads=255 sectors/track=63 (16065 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=14593 heads=255 sectors/track=63 (16065 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:

The data for partition 1 is:
sysid 18 (0x12),(Compaq diagnostics)
start 63, size 16611147 (8110 Meg), flag 0
beg: cyl 0/ head 1/ sector 1;
end: cyl 1023/ head 254/ sector 63
The data for partition 2 is:
sysid 7 (0x07),(OS/2 HPFS, NTFS, QNX-2 (16 bit) or Advanced UNIX)
start 16611210, size 117194175 (57223 Meg), flag 80 (active)
beg: cyl 1023/ head 0/ sector 1;
end: cyl 1023/ head 254/ sector 63
The data for partition 3 is:
sysid 15 (0x0f),(Extended DOS (LBA))
start 133805385, size 100631160 (49136 Meg), flag 0
beg: cyl 1023/ head 0/ sector 1;
end: cyl 1023/ head 254/ sector 63
The data for partition 4 is:
Issuing the following command will mount a NTFS partition in read-only mode:
# mount -t ntfs /dev/da0s2 /mnt/
To be able to write into a NTFS partition it is required to install the sysutils/fuse-ntfs port:
# cd /usr/ports/sysutils/fusefs-ntfs/ && make install clean
If you use, as described in the man page, mount -t ntfs-3g an error will occurr:
# mount -t ntfs-3g /dev/da0s2 /mnt/
mount: /dev/da0s2 : Operation not supported by device
To mount the NTFS partition in write mode issue:
# ntfs-3g /dev/da0s2 /mnt/
Let's make sure that the partition is mounted:
#mount
/dev/ad4s1a on / (ufs, local)
devfs on /dev (devfs, local)
/dev/ad4s1e on /tmp (ufs, local, soft-updates)
/dev/ad4s1f on /usr (ufs, local, soft-updates)
/dev/ad4s1d on /var (ufs, local, soft-updates)
/dev/ad5s1d on /mnt/1 (ufs, local, soft-updates)
/dev/fuse0 on /mnt/2 (fusefs, local, synchronous)
man ntfs-3g contains some Linuxisms and as such read the man page with a grain of salt ;)