# FreeBSD on USB using NetBSD



## gpatrick (Sep 24, 2013)

I have steps to create a USB stick using FreeBSD, but I only have Solaris and NetBSD installed right now.  I tried creating it using NetBSD with `fdisk -u` and `disklabel` followed by `newfs` and finally `dd` but it failed to boot.  Steps anyone?


----------



## wblock@ (Sep 24, 2013)

To write a FreeBSD memory stick image, you mean?  dd(1) should work the same on NetBSD, although the device names may differ.  See http://www.freebsd.org/doc/en_US.IS...ml#bsdinstall-installation-media-memory-stick.


----------



## J65nko (Sep 24, 2013)

Most of the time I use OpenBSD to write the FreeBSD memory stick images with dd. You do not need to do the fdisk, disklabel and newfs at all.

To find out the device name run `$  tail -f /var/log/messages` and insert the USB stick:


```
Sep 24 09:59:18 hercules /bsd: umass0 at uhub0
Sep 24 09:59:18 hercules /bsd:  port 5 configuration 1 interface 0 "Kingston 
                                DataTraveler 2.0" rev 2.00/1.00 addr 2
Sep 24 09:59:18 hercules /bsd: umass0: using SCSI over Bulk-Only
Sep 24 09:59:18 hercules /bsd: scsibus3 at umass0: 2 targets, initiator 0
Sep 24 09:59:19 hercules /bsd: sd0 at scsibus3 targ 1 lun 0: <Kingston,
                               DataTraveler 2.0, 1.00> SCSI2 0/direct removable
                               serial.09511665FD71AA132448
Sep 24 09:59:19 hercules /bsd: sd0: 7388MB, 512 bytes/sector, 15131636 sectors
```
Here it is sd0, so to write the image:


```
[cmd=#] dd if=Downloads/FreeBSD-9.2-RC4-amd64-memstick.img of=/dev/rsd0c bs=32k[/cmd]
22369+1 records in
22369+1 records out
733003776 bytes transferred in 199.649 secs (3671461 bytes/sec)

[cmd=#] fdisk sd0[/cmd]
Disk: sd0       geometry: 941/255/63 [15131636 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: 00      0   0   0 -      0   0   0 [           0:           0 ] unused      
 1: 00      0   0   0 -      0   0   0 [           0:           0 ] unused      
 2: 00      0   0   0 -      0   0   0 [           0:           0 ] unused      
*3: A5      0   0   1 -      3  28  41 [           0:       50000 ] FreeBSD 

[cmd=#]disklabel sd0[/cmd]
# /dev/rsd0c:
type: unknown
disk: 
label: 
duid: 0000000000000000
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 32
sectors/cylinder: 2016
cylinders: 710
total sectors: 15131636
boundstart: 0
boundend: 15131636
drivedata: 0 

8 partitions:
#                size           offset  fstype [fsize bsize  cpg]
  a:          1431648                0  4.2BSD      0     0    0 
  c:         15131636                0  unused                   
disklabel: super block size 0

[cmd=$]sudo mount -o ro /dev/sd0a U[/cmd]
[cmd=$] ls -l U[/cmd]
total 1158
-r--r--r--   1 root  wheel    6196 Sep 11 07:49 COPYRIGHT
-r--r--r--   1 root  wheel    9867 Sep 11 07:50 ERRATA.HTM
-r--r--r--   1 root  wheel    5179 Sep 11 07:50 ERRATA.TXT
-r--r--r--   1 root  wheel  245599 Sep 11 07:50 HARDWARE.HTM
-r--r--r--   1 root  wheel  120346 Sep 11 07:50 HARDWARE.TXT
-r--r--r--   1 root  wheel   22980 Sep 11 07:50 README.HTM
-r--r--r--   1 root  wheel   13364 Sep 11 07:50 README.TXT
-r--r--r--   1 root  wheel   82900 Sep 11 07:50 RELNOTES.HTM
-r--r--r--   1 root  wheel   35902 Sep 11 07:50 RELNOTES.TXT
drwxr-xr-x   2 root  wheel    1024 Sep 11 07:48 bin
drwxr-xr-x   7 root  wheel    1024 Sep 11 07:49 boot
-rw-r--r--   1 root  wheel      35 Sep 11 07:50 cdrom.inf
dr-xr-xr-x   2 root  wheel     512 Sep 11 07:47 dev
-r--r--r--   1 root  wheel    5847 Sep 11 07:50 docbook.css
drwxr-xr-x  20 root  wheel    2048 Sep 11 07:52 etc
drwxr-xr-x   3 root  wheel    1536 Sep 11 07:48 lib
drwxr-xr-x   3 root  wheel     512 Sep 11 07:49 libexec
drwxr-xr-x   2 root  wheel     512 Sep 11 07:47 media
drwxr-xr-x   2 root  wheel     512 Sep 11 07:47 mnt
dr-xr-xr-x   2 root  wheel     512 Sep 11 07:47 proc
drwxr-xr-x   2 root  wheel     512 Sep 11 07:47 rescue
drwxr-xr-x   2 root  wheel     512 Sep 11 07:49 root
drwxr-xr-x   2 root  wheel    2560 Sep 11 07:49 sbin
lrwxr-xr-x   1 root  wheel      11 Sep 11 07:47 sys -> usr/src/sys
drwxrwxrwt   2 root  wheel     512 Sep 11 07:47 tmp
drwxr-xr-x  15 root  wheel     512 Sep 11 07:49 usr
drwxr-xr-x  24 root  wheel     512 Sep 11 07:47 var
```

If you want to install FreeBSD to an USB stick or drive, you need another of those USB thingies. Copy the installation image as described above to the first stick.The other one will be used as for as destination drive for the "real" install.

Boot the FreeBSD installation stick you just created, choose the FreeBSD live CD option, login as "root" (no password is needed) to get a shell. Run `# tail -f /var/log/messages` and only now insert the second USB stick to see which device name the FreeBSD kernel assigns.


```
[cmd=root@:~#] tail -f /var/log/messages[/cmd]
Sep 24 10:16:36  kernel: ugen1.5: <vendor 0x13fe> at usbus1
Sep 24 10:16:36  kernel: umass1: <vendor 0x13fe USB DISK 2.0, class 0/0, rev 2.00/1.10, addr 5> on usbus1
Sep 24 10:16:36  kernel: umass1:  SCSI over Bulk-Only; quirks = 0x4100
Sep 24 10:16:36  kernel: umass1:5:1:-1: Attached to scbus5
Sep 24 10:16:36  kernel: da1 at umass-sim1 bus 1 scbus5 target 0 lun 0
Sep 24 10:16:36  kernel: da1: < USB DISK 2.0 PMAP> Removable Direct Access SCSI-0 device 
Sep 24 10:16:36  kernel: da1: 40.000MB/s transfers
Sep 24 10:16:36  kernel: da1: 3824MB (7831552 512 byte sectors: 255H 63S/T 487C)
Sep 24 10:16:36  kernel: da1: quirks=0x3<NO_SYNC_CACHE,NO_6_BYTE>
```
So in this case you would have to use da1 as device to install to.

To exit from the Live CD, run [cmd=root@:~#]bsdinstall[/cmd] to proceed with the "real" install.


----------



## SirDice (Sep 24, 2013)

No need to fdisk(8) or newfs(8). Just dd(1) the image directly to the device, not to a partition or slice on that device.


----------



## wblock@ (Sep 25, 2013)

gpatrick said:
			
		

> Thanks.  Ran a `dd if=/dev/zero of=/dev/rsd2d bs=32k` and then a `dd if=FreeBSD-10.0-ALPHA2-ia64-memstick.img of=/dev/rsd2d bs=32k` and it worked perfectly.



The first one is not necessary.  It will erase the entire flash drive, but the second dd(1) will overwrite all of the drive that needs it.


----------

