# Problem to integrate a second harddisk



## HL1234 (Sep 20, 2012)

Hello,
before I try some things and destroy my data I would like to ask some question:

On an old i386 PC I have 2 hard drives (HD). The second HD2 has the 'data' and on the first HD1 was the system FreeBSD 6.0 installed.
Because of a HD-crash of HD1 I buy a new one and installed successfully FreeBSD 9.0 on the first HD. Now I want to integrate HD2 again into the system. How can I do that, without to clear all the data on it, when using the new "bsdinstall" partition utility. (I could do it on command line but I don't know the exact commands)

I like to give more technical information:
I found in /dev before installing the new system:


> /dev/ad0
> /dev/ad0s1
> /dev/ad0s2
> /dev/ad0s2a
> ...


with "ad0" was hard drive 1 and "ad1" was hard drive 2
ad1s1b = swap
ad1s1d = /home and my data...

Now I see in /dev


> lrwxr-xr-x  1 root  wheel            4 20 Sep 10:49 /dev/ad0 -> ada0
> lrwxr-xr-x  1 root  wheel            6 20 Sep 10:49 /dev/ad0s1 -> ada0s1
> lrwxr-xr-x  1 root  wheel            6 20 Sep 10:49 /dev/ad0s2 -> ada0s2
> lrwxr-xr-x  1 root  wheel            7 20 Sep 10:49 /dev/ad0s2a -> ada0s2a
> ...



So my first question is: 
 - How can I make ada1a to ada1sb (swap) + ada1sd (home) ?

and second:
 - what is this, with this links in /dev like "lrwxr-xr-x ... /dev/ad0s2b -> ada0s2b" which was not seen before?


----------



## SirDice (Sep 20, 2012)

HL1234 said:
			
		

> So my first question is:
> - How can I make ada1a to ada1sb (swap) + ada1sd (home) ?


Remove the a and b partition and create a new one covering the empty space. Assign the new partition as swap. Edit /etc/fstab and mount /dev/ada1sd on /usr/home/. 



> - what is this, with this links in /dev like "lrwxr-xr-x ... /dev/ad0s2b -> ada0s2b" which was not seen before?


http://www.freebsd.org/releases/9.0R/relnotes-detailed.html#AEN1308


----------



## wblock@ (Sep 20, 2012)

The links from the old drive notation (ad0) to the new (ada0) are there for compatibility, and can be ignored.

Please make a backup of everything before continuing.  One drive failed, and that is a warning that the next could be near failure.  See Backup Options For FreeBSD.

Don't use bsdinstall(8) to do anything with the data drive.  Disconnect it, install FreeBSD 9 on the first drive.  Then shut down, reconnect the old drive, and edit /etc/fstab to mount it.


----------



## HL1234 (Sep 22, 2012)

@SirDice: thankx for the link, I will have a closer look to it.


> Remove the a and b partition and create a new one covering the empty space.


this will destroy all my data on the second hard drive. The question was, how can I integrate it in the system *without* new partioning it.

@wblock: I had make a backup - but is there no way to use the second hard drive in freeBSD 9.0 again, without create a new patition from scratch and restore the data?



> Don't use bsdinstall(8) to do anything with the data drive. Disconnect it, install FreeBSD 9 on the first drive. Then shut down, reconnect the old drive


That was exactly what I have done, but disconnect the old drive from the cable.

The manual for fstab says "The file fstab contains descriptive information about the various file systems...". But in /dev I see no filesystems like /dev/ada1s1b, /dev/ada1s1d.

*How can I change the system entry from /dev/ada1a, which has been identified, to 

/dev/ada1s1b #the old swap space an hard drive 2 and

/dev/ada1s1d #the old /home space an hard drive 2 

without deleting all in /dev/ada1 ?*

```
[server] =>bsdlabel /dev/ada0
bsdlabel: /dev/ada0: no valid label found

[server] =>bsdlabel /dev/ada0s2
# /dev/ada0s2:
8 partitions:
#          size     offset    fstype   [fsize bsize bps/cpg]
  a:    2097152          0    4.2BSD        0     0     0
  b:    1048576    2097152      swap                    
  c:  150994935          0    unused        0     0     # "raw" part, don't edit
  d:    4194304    3145728    4.2BSD        0     0     0
  e:  126877696    7340032    4.2BSD        0     0     0
  f:   16777206  134217728    4.2BSD        0     0     0

[server] =>bsdlabel /dev/ada1 #the second drive that has to integrate
# /dev/ada1:
8 partitions:
#          size     offset    fstype   [fsize bsize bps/cpg]
  a:  156301472         16    unused        0     0   
  c:  156301488          0    unused        0     0     # "raw" part, don't edit

[server] =>bsdlabel /dev/ada1a
bsdlabel: /dev/ada1a: no valid label found
```
 Would bsdlabel destroy some data?


----------



## wblock@ (Sep 22, 2012)

Don't use bsdlabel(8).  It is for creating partitions, which you already have.

Normally, what you are asking just needs new entries to /etc/fstab.  Please show the output of
`# gpart show`


----------



## HL1234 (Sep 22, 2012)

Hello, thank you for help.
Here ist the output from gpart

```
[server] =>gpart show
=>       63  156301425  ada0  MBR  (74G)
         63    4188177     1  !6  (2G)
    4188240  150994935     2  freebsd  [active]  (72G)
  155183175    1118313        - free -  (546M)

=>        0  156301488  ada1  BSD  (74G)
          0         16        - free -  (8.0k)
         16  156301472     1  !0  (74G)

=>        0  150994935  ada0s2  BSD  (72G)
          0    2097152       1  freebsd-ufs  (1.0G)
    2097152    1048576       2  freebsd-swap  (512M)
    3145728    4194304       4  freebsd-ufs  (2.0G)
    7340032  126877696       5  freebsd-ufs  (60G)
  134217728   16777206       6  freebsd-ufs  (8G)
  150994934          1          - free -  (512B)
```
Because now the time is 21:15, I will come back tomorrow.
Again, thank you for any suggestion.


----------



## wblock@ (Sep 22, 2012)

That shows that ada0 uses MBR partitioning.  The first partition is for 2G for DOS (type 6), the second is for FreeBSD, and is further divided with BSD labels (ada0s2).

ada1 appears to have just a bare BSD label, the type of thing that is known as "dangerously dedicated".  It has no MBR or FreeBSD partitions.


----------



## HL1234 (Sep 23, 2012)

You are right with ada0: first I installed an MS-DOS Partition (slice1) on this old PC - to remember the old days  And second there is a new BSD 9.0 partition (slice2) which will be configured to be an home-web-server.

ada1 is completly used for BSD. It was some years ago I had created it. I think I had decided to use BSD without DOS-MBRs. The handbook says: "BSD Labels without an MBR, sometimes called "dangerously dedicated mode". 

On this hard drive ada1 (earlier called ad1) there should be this BSD-Partitions inside:

```
/dev/ad1 
/dev/ad1s1 
/dev/ad1s1b 
/dev/ad1s1c 
/dev/ad1s1d
```

How can I recreating the slices, or the labels for the slices, without loosing the data in it?


----------



## wblock@ (Sep 23, 2012)

sysutils/scan_ffs is all that comes to mind.  Well, other than restoring from backups.  Printing out a copy of the partition tables is not a bad idea.


----------



## HL1234 (Sep 24, 2012)

the manual for scan_ffs says:


> 5.    Use disklabel(8) to reconstruct the disklabel on the affected disk,
> using all the information you gathered from scan_ffs and other
> sources.


Does that mean I can with "disklabel" command reconstruct the disklabels without destroying some data (when I know the exact size of the old partitions)?

On the other hand, have I not to use "gpart" now, to label a disk, instead of disklabel, because I now using the new freeBSD 9.0 system?


----------



## HL1234 (Sep 24, 2012)

I've get now the output of scan_ffs:

```
scan_ffs -lv /dev/ada1 
block 376575 id 4a60bfd3,f03dc5d4 size 39074080
block 524479 id 4a60c340,436b1346 size 38943008
block 524511 id 4a60c340,436b1346 size 38943008
X: 155772032 524351 4.2BSD 2048 16384 0 # /home
block 536383 id 3a3800,5040170 size 38943008
...
block 156186303 id 4a60bfd3,f03dc5d4 size 39074080
scan_ffs: read: Input/output error
```

it found:
X: 155772032 524351 4.2BSD 2048 16384 0 # /home

Bevore installing the new 9.0 freeBSD I discovered:

```
bsdlabel /dev/ad1s1
# /dev/ad1s1:
8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  b:   524288        0      swap
  c: 156296322        0    unused        0     0         # "raw" part, don't edit
  d: 155772034   524288    4.2BSD     2048 16384 28552
```

When compare both outputs it seems the old partition is right there.

So the question remain: can I  do bsdlabe or some gpart commands without destroying the data in the partition - and how are these commands exactly written?

That is what I'm looking for. I got less experience with gpart.


----------



## wblock@ (Sep 24, 2012)

If you have a binary backup of the ada1 drive, sure, it's safe to try writing a new disklabel to it.  Either bsdlabel(8) or gpart(8) should only write to the bsdlabel blocks.  See the bsdlabel(8) man page, it can restore the label from a file, and your output shown in message 11 could be used as input.

My suggestion would be to boot the old system, back up the missing filesystem with dump (see message #3), boot into FreeBSD 9, and reformat that old drive.  Use GPT, use MBR/BSDlabel, but don't ever use dangerously dedicated again.  Then newfs and restore.

Note that none of this should be required.  If that drive is undamaged, FreeBSD 9 should handle it fine.  My guess is that something got written to it when installing FreeBSD.


----------



## HL1234 (Oct 5, 2012)

Hello,
so now its done. I had tried to write back the bsdlabel, but the data was gone. I think you are rigth:





> My guess is that something got written to it when installing FreeBSD



I have used the new bsdinstall because my first try - go in Shell-Modus and do try the old /usr/sbin/sysinstall - has not work. Later  I see sysinstall is no more a option to install freeBSD 9.0. So then I play around with the bsdinstall Manual-Modus. I can not remeber that I habe done something wrong but may be I habe write changes for hard disk 2 back or the bsdinstall script has destroyed automatically the second hard disk, because I have forgotten do take it from the cabel. Maybe bsdinstall in right know unsure to use.

I have then create the scond hard disk new, by hand, and write the backup back. Here also; first I try to do this bsdinstall. But in bsdinstall all my labels of my partitions from the fist hard disk was missed - so I want go sure and closed this tool and do it by command line.

For those who are interested was I have done, here are my command (sugestions by a how to I had used)


```
First zero out the target MBR (!!!) Destroying all the data on the target.
[color="RoyalBlue"][server] =>dd if=/dev/zero of=/dev/ada1 count=2[/color]
	count=2 #Copy only n=2 input blocks
-->	2+0 records in
	2+0 records out
	1024 bytes transferred in 0.000563 secs (1819131 bytes/sec)

(1)Create a GPT partition scheme on /dev/ada1
[color="royalblue"][server] =>gpart create -s gpt /dev/ada1[/color]
          'create'  	#a new partitioning scheme on a provider given by provider.
	 -s       	#The -s scheme option determines the scheme to use.
	          	#The kernel needs to have support for that particular scheme
	 -n entries	#The number of entries - By default, partition tables are created
	            #with the minimum number of entries.
	 -f flags   #Additional operational flags
-->ada1 created

(2)Create a boot partition to hold the loader, size of 512K.
Give it a GPT label of "gpboot", which will show up in /dev/gpt when the device is discovered:
[color="royalblue"][server] =>gpart add -t freebsd-boot -l gptboot -s 512K /dev/ada1[/color]
    add			#Add a new partition to the partitioning scheme given by 'geom'
    -s			#It's size - SI unit suffixes are allowed
    -t			#the type of the partition
    -l			#The label attached to the partition (when partion scheme support that)
-->ada1p1 added

(2b)Install the GPT bootcode into the boot partition:
[color="royalblue"][server] =>gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 /dev/ada1[/color]
	-b			#specifies a file of the the bootcode
	-p partcode #specifies a file that contains the bootstrap code intended to be written 
            to a partition
	-i index    #The partition is specified by the -i 'index' option.
-->bootcode written to ada1

(3) Create partition for /. - the first - It should start at the 1M boundary for proper sector
alignment on 4K sector drives. This is compatible with GPT drive layout for many other systems.
Because fo my second disk I decide to create a swap area as first partiton after boot partition.
[color="royalblue"][server] =>gpart add -t freebsd-swap -l gptswap -b 1M -s 512MB /dev/ada1[/color]
-->ada1p2 added

(4) Create partitions for swap, /var, /tmp, /usr. etc...
Leaving the -s size option off the last uses the rest of the disk.
As long as these are even sizes in M or G, the alignment will remain correct.

[color="royalblue"][server] =>gpart add -t freebsd-ufs  -l gpthomefs /dev/ada1[/color]
-->ada1p3 added

[color="royalblue"][server] =>gpart show -l /dev/ada1[/color]
=>       34  156301421  ada1  GPT  (74G)
         34       1024     1  gptboot   (512k)
       1058        990        - free -  (495k)
       2048    1048576     2  gptswap   (512M)
    1050624  155250831     3  gpthomefs  (74G)
==>OK

also you can try 
[color="Blue"][server] =>gpart list[/color]

(5) Format the new filesystems, enabling soft updates for performance.
    Filesystem labels can be added here, but probably (wahrscheinlich)
    should not be the same as the GPT labels already assigned...

first take a look:
[color="blue"][server] =>ls -l /dev/gpt/[/color]
	crw-r-----  1 root  operator    0, 116  2 Okt 20:45 gptboot
	crw-r-----  1 root  operator    0, 126  2 Okt 20:56 gpthomefs
	crw-r-----  1 root  operator    0, 122  2 Okt 20:53 gptswap

[color="blue"][server] =>ls -la  ad*[/color]
	 89 0 lrwxr-xr-x  1 root  wheel     -       4B  2 Okt 20:12 ad2 -> ada1
	108 0 lrwxr-xr-x  1 root  wheel     -       6B  2 Okt 20:36 ad2p1 -> ada1p1
	115 0 lrwxr-xr-x  1 root  wheel     -       6B  2 Okt 20:53 ad2p2 -> ada1p2
	125 0 lrwxr-xr-x  1 root  wheel     -       6B  2 Okt 20:56 ad2p3 -> ada1p3

than format:
[color="blue"][server] =>newfs -U /dev/gpt/gpthomefs[/color]
		-U      #Enable soft updates on the new file system.
		-J      #Enable journaling on the new file system via gjournal.See gjournal(8)
        -j      #Enable soft updates journaling on the new file system
	/dev/gpt/gpthomefs: 75806.1MB (155250824 sectors) block size 32768, fragment size 4096
			using 103 cylinder groups of 740.00MB, 23680 blks, 47360 inodes.
			with soft updates
	super-block backups (for fsck -b #) at:
	 192, 1515712, 3031232,...................154583232

(7) Restore data from backup. Labels are used in the mount command here because 
    theyâ€™re easier to identify, but device names like /dev/ada1p3 will work.

[color="blue"][server] =>mount /dev/gpt/gpthomefs /mnt/home[/color]

([color="blue"]cd /mnt/home && gzcat "?????.gz" | restore -ruf -[/color])

(8) [color="blue"]Modify /etc/fstab:[/color]
# what is in the fstab depends on what you have - this is just an example:
	# Device                Mountpoint      FStype  Options         Dump    Pass#
	/dev/gpt/gptswap          none            swap    sw              0       0
	#/dev/gpt/gptrootfs       /               ufs     rw              1       1
	#/dev/gpt/gptmpfs         /tmp            ufs     rw              2       2
	#/dev/gpt/gptusrfs        /usr            ufs     rw              2       2
	#/dev/gpt/gptvarfs        /var            ufs     rw              2       2
	/dev/gpt/gpthomefs        /home           ufs     rw              2       2

(9) Create the Mountpoint /home  #that was needed in my case or anytime i the mountpoin form
                                 #/etc/fstab isn't there
[color="blue"][server] =>cd / && mkdir home[/color]

[color="blue"][server] => reboot[/color]
```

After all, all things are fine. 

I took the "How To" from: http://www.wonkity.com/~wblock/docs/html/disksetup.html

Thanks a lot to support me.


----------



## jb_fvwm2 (Dec 13, 2012)

I followed the most recent post above this one as a guide. Everything worked perfect. Upon reboot, the older ad10.journal can be mounted, but the new /dev/gpt labels are not there.  fdisk shows a GPT scheme.  gpart show again shows "no such geom".
edit::::
gjournal stop /dev/ada0, or some such similar command, caused the label(s) to reappear.  May or may not be adequate in the long term to get the disk bootable by itself after rsync...


----------



## jb_fvwm2 (Dec 14, 2012)

New disk is up and running. GOOD.. The only error encountered is "invalid backup gtp header" Not so good.. Howsoever, it seems to freeze or reboot, an AMD Phenom while doing things every other install on that machine was able to complete easily, numerous times... three times in a row, so it is reproducible.
EDIT...

```
gpart recover /dev/ada0
cpuset -l 0 -s 1
```
One or both of those commands just fixed *probably* both of those anomalies...


----------

