# Need help replacing boot drive



## JornZ (Dec 26, 2011)

Hello everyone,

I'm quite the newbie when it comes to FreeBSD and understand alot more about windows when it comes to computers. Despite that I chose to use FreeBSD 8.1 (most recent release version at the time) to build a home NAS, since it just seemed to offer me a lot better options. I managed to get everything up and running and keep learning more and more each time I run into some trouble. But now I am faced with a problem unsure how to solve, even after googling around and I hope to get some help on this forum. I will explain the setup of the NAS first (and I hope I use all the correct terminology):

The NAS has 4 drives installed at this moment and only offers 4 SATA ports. So basically it is full hardware wise. There are 3 x 1TB HDD's and these are all used with ZFS RAID-Z and are in 1 big pool and only used for storage. Then there is 1 x 8GB SSD which I use to boot the system from and has the standard filesystem setup (UFS2?).

The problem is that this SSD has been getting inconsistencies regularly lately and it just seems that replacing it would be a good idea. So I went ahead and got a shiney new ocz 30GB SSD to replace the other SSD. I'm looking for some advice what the best strategy is to approach this replacement.

There's are a number of options I can think of that might work:
- Take out the old SSD. Insert the new SSD and reinstall latest release version 8.2 and simply reinstall the programs I use and only copy configuration files from the old SSD.

- Try to use dump over the network to my windows pc in order to backup the SSD. Switch out SSD's and boot from freebsd live/recovery CD/USB and try to restore the dump to the new drive. This seems annoying that windows comes into play. Not really sure how to do this.

- Dump the contents of the SSD to the ZFS filesystem. Switch drives. Boot using recovery CD/USB and mount the ZFS filesystem and restore the dump from that to the new drive. Is this possible?

I would really appreciate any thoughts on this subject and pointers. I'm not really sure of my FreeBSD skills up to this point and this is a challenge for me. Thank you!


Some extra info that might help you to help me:

```
[root@Thuis /tank/home/Jorn]# df
Filesystem           1K-blocks       Used      Avail Capacity  Mounted on
/dev/ad10s1a             367790    285608      52760    84%    /
devfs                         1         1          0   100%    /dev
/dev/ad10s1e             297326        50     273490     0%    /tmp
/dev/ad10s1f            4677960   3707496     596228    86%    /usr
/dev/ad10s1d             526510    204620     279770    42%    /var
tank                 1614404838        27 1614404811     0%    /tank
tank/home            1614404851        40 1614404811     0%    /tank/home
tank/home/Jorn       1870009503 255604692 1614404811    14%    /tank/home/Jorn
tank/home/Jorn/foto  1622449343   8044532 1614404811     0%    /tank/home/Jorn/foto
tank/home/Jorn/video 1650223709  35818898 1614404811     2%    /tank/home/Jorn/video

[root@Thuis /tank/home/Jorn]# zpool list
NAME   SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
tank  2.72T   429G  2.30T    15%  ONLINE  -

[root@Thuis /tank/home/Jorn]# bsdlabel ad10s1
# /dev/ad10s1:
8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a:   759808        0    4.2BSD        0     0     0
  b:  3523514   759808      swap
  c: 15649137        0    unused        0     0         # "raw" part, don't edit
  d:  1087488  4283322    4.2BSD        0     0     0
  e:   614400  5370810    4.2BSD        0     0     0
  f:  9663927  5985210    4.2BSD        0     0     0
```


----------



## gkontos (Dec 26, 2011)

dump / restore is good way to backup and restore UFS2 filesystems. On the other hand, a new drive is always a good reason for an upgrade and a new install.
You can consider installing FreeBSD 9.0-RELEASE or FreeBSD 8.3-RELEASE when they are available. (it shouldn't take that long) Both use ZFS v28 and have a lot  improvements compared to FreeBSD 8.1-RELEASE.
If you decide to perform a new installation, backing up your /usr/local directory will retain most of your configuration data.


----------



## JornZ (Dec 26, 2011)

I'm leaning towards the third option at the moment.

Is it possible to boot from a FreeBSD installation USB and then mount the ZFS filesystem with a command like:

```
zfs mount tank/home/Jorn
```
and then after creating the filesystems for root, var, tmp and usr on the new disk place the contents of the dumps in there? Dumps of root, var, tmp and usr I stored at /tank/home/Jorn.


----------



## gkontos (Dec 26, 2011)

JornZ said:
			
		

> I'm leaning towards the third option at the moment.
> 
> Is it possible to boot from a FreeBSD installation USB and then mount the ZFS filesystem with a command like:
> 
> ...



You will have to import the pool first.

[CMD=""]# zpool import <pool>[/CMD]

Then you can specify an alternative mount point

[CMD=""]# zfs set mountpoint=/mnt <pool>[/CMD]


----------



## wblock@ (Dec 26, 2011)

In that situation, I would use dump(8)/restore(8) to avoid having to deal with different ZFS versions.  *Before you start any of these, make a full backup to some other media.*

It's not necessary to involve Windows.  On the Windows computer, disconnect all drives for safety, then connect the new SSD.  Boot that system with mfsBSD.  Partition and format the new SSD; make sure to use at least 4K alignment, and remember to set permissions to 1777 on /tmp.  Run dump(8) on the NAS system, dumping the filesystems to a restore on the mfsBSD system.  Backup Options For FreeBSD shows examples, although not a direct restore.  These would be run on the NAS computer, and mfsbsd is the DNS name or IP address of the computer running mfsBSD.

```
# dump -C16 -0uanL -h0 -f - /usr | ssh -c blowfish root@mfsbsd (mount /dev/ad0p6 /mnt && cd /mnt && restore -rf - && cd && umount /mnt )
# dump -C16 -0uanL -h0 -f - /var | ssh -c blowfish root@mfsbsd (mount /dev/ad0p4 /mnt && cd /mnt && restore -rf - && cd && umount /mnt )
# dump -C16 -0uanL -h0 -f - /    | ssh -c blowfish root@mfsbsd (mount /dev/ad0p2 /mnt && cd /mnt && restore -rf - && cd && umount /mnt )
```
Copy /tmp also if needed.


----------



## JornZ (Dec 26, 2011)

Thanks gkontos and wblock for the replies.

@wblock I guess I could leave the windows box out of the equation by dumping to a USB stick and installing the new SSD in the NAS and restoring from the stick and booting from another stick or CD?


----------



## wblock@ (Dec 27, 2011)

JornZ said:
			
		

> Thanks gkontos and wblock for the replies.
> 
> @wblock I guess I could leave the windows box out of the equation by dumping to a USB stick and installing the new SSD in the NAS and restoring from the stick and booting from another stick or CD?



Yes, that should work.  Or even attach the new SSD to the old system, partition and format it, and use dump/restore to copy the filesystems directly.  That always makes me a little nervous because it's a little too easy to format the wrong disk.


----------



## JornZ (Dec 27, 2011)

@wblock@ I can't add the new drive to the NAS unfortunately, there are no free SATA ports (see the OP).

I just wanted to report my succes and share the problems I encountered, it might help others at some point.

I started by dumping the filesystems (root, var and usr) to a USB stick and to the raidz pool with some help of this guide: http://forums.freebsd.org/showthread.php?t=185. The stick died one me and I didn't have another USB stick big enough, so I had to use the raidz pool dumps now.

Used a USB image of FreeBSD 8.1 to create a bootable stick

Exported the raidz pool [CMD="zpool export tank"][/CMD]

Switched the old SSD for the new one

Booted from the USB image

Made a slice and partitions using fdisk and the disklabel tool from sysinstall and set the disk as bootable

Then chose the fixit option to get a shell

I wanted to import the raidz pool but this failed as the zfs module wasn't loaded. I got that up by some linking and kldload:
[CMD="Fixit# ln -s /dist/boot/kernel /boot/kernel
Fixit# ls -s /dist/lib /lib
Fixit# kldload zfs"][/CMD]
Also mentioned in this thread: http://forums.freebsd.org/showthread.php?t=17560

Restored root, var and usr from the dump files in the pool using the earlier mentioned guide. Got a bunch of errors. Then I remembered I dumped from live filesystems r), probably should have used single user mode!

Rebooted and didn't work, had to set the proper boot drive in the bios since it just picked another after having removed the old SSD (doh!)

Works properly sofar even though I had made dumps from live filesystems (not much was going on, just seeding some torrents). If I get anything really weird, I still have the old drive so I could go through the process again I guess and dump from single user mode...


----------



## wblock@ (Dec 28, 2011)

Unless it gives errors while running, dumping again from single-user is not necessary.  Do use -L when dumping from live filesystems in the future.


----------



## JornZ (Dec 28, 2011)

wblock@ said:
			
		

> Unless it gives errors while running, dumping again from single-user is not necessary.  Do use -L when dumping from live filesystems in the future.



Hmmm I used -0Lauf as paramaters. Still got some errors that seem to relate to the mapping not being equal to the actual backup: 
	
	



```
expected next file <inumber>, got <inumber>.
```

Also I forgot to mention I exported the raidz pool again in the fixit shell after I was done to be on the safe side and not having to import using -f at a later time, but I can't edit my posts .


----------



## wblock@ (Dec 28, 2011)

Those errors were from files that were being written during the backup.  Depends on the file; things like log files aren't relevant on the new system anyway and can be ignored.


----------



## JornZ (Dec 29, 2011)

Ok cool, I understand. That makes me feel better 

I guess this thread can be marked as solved as I have seen other threads with that indication (still kindof new to these forums as you can see by my number of posts!).

Thanks for all the help wblock@ and gkontos, everything went quite smoothly because of it!:beer


----------



## monkeyboy (Dec 30, 2011)

I did basically this same thing a couple of days ago, with 8.2.
What I did was create copies of the system disk on a USB hard drive of the same size. Then exchanged the system drive with the new drive and booted FreeBSD from CDROM using a LiveFS CD. Then restored the system drive using the USB hard drive as the source.

I also created a dump tape of the system drive just in case, but it's much slower, so I went with the USB drive first as the restore source. All worked fine.


----------

