Moving root / from one drive to another (better, faster, stronger)

So I had a 15kRPM drive and an Ultra 160 SCSI controller gathering dust, and decided to install both into the PIII 600 machine.  The onboard controller is only ATA/33, and so I’m thinking this might provide a performance boost.

Most of the manuals (including an article in the FreeBSD FAQ) said you really should reinstall the OS completely when you migrate from one disk to another.  I really didn’t feel like digging through /etc and figuring out what I missed later on, so I decided to just clone the disk.

There’s a handful of things I learned during this process…  First, RTFM (read the friendly manual), but use your head.  The FAQ (section 9.2) gives the following steps to migrate from one disk to another.

How do I move my system over to my huge new disk?

  1. newfs the new partition.
  2. mount it on a temporary mount point.
  3. cd to that directory.
  4. dump the old partition, piping output to the new one.
A couple of things:
-I forgot what ought to be step 0 above, to partition the drive.  Oddly enough, it still booted fine, but the machine was booting from a combination of the new drive and the old one.  Interesting…   Also, I edited /etc/fstab to make sure the new drive was mounted as /
-I forgot to switch the BIOS to boot to the SCSI controller.  So I fixed that (it was just a boot order issue.  Most BIOSes will have an option to boot off a different controller, usually on the boot order page.)
So I fixed that, and got “Invalid partition, no boot/loader” errors.  Reading and thinking about it a little bit,  I figured out that even though the drive had imaged successfully using the dump command in the FAQ, I hadn’t partitioned it!
And so it was addressing the drive directly, and I’d set it up in /etc/fstab to mount directly as da0.  Oddly enough this worked, kind of.

What I did to fix all this:
I ran sysinstall, and I went through the fdisk and drive labeling menu items.  I made sure that I set the boot flag on the partition.  I then imaged the disk as mentioned in the FAQ using the dump command, editing the fstab file to let the new drive boot up.
Here’s what I’d recommend if you’ve ever got to move your root partition:
1. before you do anything, make a backup, and download and burn the FreeBSD LiveFS CD. It wasn’t entirely clear from reading the FreeBSD download site which CD image would boot up and give the utilities I needed.  I’m sure it’s documented someplace.
The one marked “FreeBSD LiveFS CD” is probably the one you want.  I used that disc for booting at least half a dozen times to fix various things throughout the process.  I went into “Fix It” mode.  Mostly I used this for editing the /etc/fstab file with vi after I’d made a typo.
2. Use sysinstall to do the partitioning and formatting of the disk. Don’t forget to enable softupdates if that’s what you want.
3.  Use sysinstall to make your disk slices.  I learned the hard way that freebsd really wants its root directory (/) to be mounted from the “a” slice.  For example, if you’re using an IDE (ATA) disk, this might be ad0s1a.  For SCSI, it might be da0s1a.
4.  Mount your new drive to a temporary location.  (for example, mkdir /mnt/scsi; mount da0s1a /mnt/scsi.
5. Follow the procedure listed in the FAQ to dump data from the existing partition to the new drive:
# cd /mnt/scsi
# dump 0af - / | restore rf -

6. Edit the /etc/fstab file, replacing the old drive letter(s) with the new one(s).   Before you reboot, try and be sure you have it right.  You might need to ensure everything’s cool with the Master Boot Record (MBR).  Make sure you’ve got the boot disc handy, and that the BIOS settings are the way you want them (you want the boot disk to be booting first., somtimes this can get tricky when you’ve got multiple controllers.

7. Don’t neglect your swap partitions.  If any of these were on other disks before, you may need to change those in /etc/fstab too.  The system will probably still boot without swap, but you can run swapinfo to check the status of the swap.

Here are some other tools I used:
diskinfo:  a built in benchmarking utility.
disklabel: I didn’t use it directly, but more for listing the results of the changes made through sysinstall.
iostat: reports stats about your disk usage.

Posted by Scott in Uncategorized

Leave a Reply

 
  • jacob: Thanks for a great post. I had one issue with your command: #nice -n 10 portupgrade -aRr. you will get...
  • Pan: Do you have any problem printing from a windows machine? I have an Samsung ML1610 and I can print once from...
  • Scott: One other item. CUPS. To get this working right, I edited /usr/local/etc/cups/cupsd.conf , and added the line...
  • Scott: Follow-up item: after disabling nmbd as the Section 6 wiki mentioned, I found that I could no longer access...
  • Scott: Dan, that’s a great point. I experienced exactly what you’re saying today when I realized...