If an amd64 hardware has been initially installed in 32-bit mode (i.e. as a plain i386 machine), it might later be desired to turn it into a full 64-bit machine.
The recommended way to do this is to back up all personal and important data, and reinstall using an amd64 installation medium.
However, it's also possible to migrate the machine through a rebuild from source code.
Much of this description has been inspired by Peter Wemm's mailing list article.
/usr/src filesystem of whatever branch has been chosen/usr/src (just to be sure everything is consistent)make buildworld TARGET=amd64 TARGET_ARCH=amd64make buildkernel TARGET=amd64 TARGET_ARCH=amd64 swapinfo -h — make sure no swap is in use (if the swap is not free, reboot here)swapoff /dev/ad4s1b (or whatever your swap device is named — replace that name in the steps below if it is different)/etc/fstab to comment out the swap linenewfs -U -n /dev/ad4s1bmount /dev/ad4s1b /mntcd /usr/src && make installworld TARGET=amd64 TARGET_ARCH=amd64 DESTDIR=/mntfile /mnt/bin/echo — make sure this displays as ELF 64-bit LSB executablecd /usr/src/etc && make distribution TARGET=amd64 TARGET_ARCH=amd64 DESTDIR=/mntcp /etc/fstab /mnt/etc/fstabThis completes your miniroot in the swap volume.
/usr/obj tree for later installation:/usr/obj/amd64.amd64 now, so remove any leftover 32-bit stuff: rm -rf /usr/obj/usr/src.cd /usr/obj && ln -s amd64.amd64/* . — this should get symlinks for lib32 and usr (the original file location must still be retained by now)cp /usr/obj/amd64.amd64/usr/src/sys/$YOURKERNEL/kernel /boot/kernel.amd64/boot), too.unload to get rid of the (automatically loaded) 32-bit kernelload /boot/kernel.amd64, possibly followed by loading any essential 64-bit KLDs hereboot -as to boot into single-user mode, with the loader asking for the location of the root filesystem (rather than figuring it out from /etc/fstab)ufs:, followed by the name of the swap volume/partition; e.g. ufs:/dev/ad4s1b/, /var and /usr filesystems under /mnt; examine /etc/fstab to know which resources to mountchflags -R noschg /mnt/*bin /mnt/lib* /mnt/usr/*bin /mnt/usr/lib*cd / && find *bin lib* usr/*bin usr/lib* | cpio -dumpv /mntmount -t devfs devfs /mnt/devchroot /mnt so you can pretend living in the final target filesystem spacecd /usr/src && make installkernel installworld — this should work without any issuesexit so you're back in the miniroot environmentrebootfsck -p (just make sure all filesystems are allright)mount -a -t ufs/etc/fstab to re-enable the swapmkdir /usr/local/lib32cd /usr/local/lib && find . -type f \( -name "*.so*" -o -name "*.a" \) | cpio -dumpv ../lib32/etc/rc.conf:ldconfig32_paths="/usr/lib32 /usr/local/lib32"/usr/obj into its canonical form (optional):cd /usr/objrm * — just to remove the lib32 and usr symlinks (it will complain and not remove the amd64.amd64 directory)mv amd64.amd64/* . && rmdir amd64.amd64rm /boot/kernel.amd64Now the basic migration has been done.
Some 32-bit ports might not work, despite of the hackery to save their
shared libs in a separate place. It's probably best to reinstall all
ports. portupgrade -af doesn't work as it clobbers its own package
database in the course of this operation (when reinstalling ruby and/or
ruby-bdb).