Lighthouse      Zap's Digital Lighthouse
   


About
Zap's Digital Lighthouse is
a Blosxom weblog for our digital outpost on the Internet

For info
info@rax.org


Useful links:
Google
Cyberpresse
The Reg
Slashdot
FreeBSD
LinkedIn
Twitter
Boursorama
RAX
zap
Soekris
xkcd
AirFrance
Wiki soekris
Wikipedia
Wiktionary
ACME
blosxom

Categories:
/FreeBSD (24)
/admin (1)
/blosxom (6)
/games (3)
/hardware (17)
/inet (4)
/misc (37)
/notwork (2)
/software (11)
/tech (1)

Archives:
 2019 (1)   
 | July (1)
 2018 (6)   
 | December (1)
 | November (3)
 | January (2)
 2017 (4)   
 | December (2)
 | January (2)
 2016 (3)   
 | November (1)
 | October (1)
 | January (1)
 2015 (9)   
 | December (2)
 | November (1)
 | October (1)
 | June (1)
 | May (2)
 | February (1)
 | January (1)
 2014 (9)   
 | December (1)
 | October (1)
 | September (1)
 | August (3)
 | May (2)
 | April (1)
 2013 (20)   
 | October (3)
 | June (4)
 | May (2)
 | April (7)
 | March (1)
 | January (3)
 2012 (60)   
 | December (4)
 | October (1)
 | July (5)
 | June (7)
 | May (1)
 | April (6)
 | March (3)
 | February (14)
 | January (19)
 2011 (3)   
 | December (1)
 | November (2)
 2008 (1)   
 | October (1)


Blosxom

       

Sun, 08 Nov 2015

Adding a new USB disk to my FreeBSD 10.2 server

(I think that the stuff below is accurate, but do proceed with care if you're going to try it out... I could have made a mistake writing down the list of steps. Let me know if you spot any issue.)

I would like to add a new USB disk to my FreeBSD 10 machine. In the olden days, I used to use sysinstall, but that doesn't seem to be the modern way to do things these days.

Notably, I would like to "label" the drive, so that I can mount it with its logical name rather than its physical device name... this is particularly important for USB disks, as plugging and unplugging USB device ports may cause changes in device names, which could cause really annoying issues if fstab mounts the wrong device (as I've already written about on Feb 20th, 2012).

So, here is what one must do to set up a new disk for use on FreeBSD...

1) First of all, decide how you're going to name your device. Using volume names instead of just raw device names is highly desirable if you're in a dynamic environment (e.g. if you're going to be adding disks to the computer in the future -- including USB storage, devices may end up being renamed).

For USB disks, choosing good label names is important: you may want to replace a disk at some point if one crashes (so do not use the /dev/ufsid/... names) and/or you may have a CPU crash and you'd like to mount your disk onto some other FreeBSD system (so do not use the same names for your bootdisks on all computers, unless they are truly meant to be considered identical clones). This means that 'bootdisk' is probably not a great label, in case you ever need to mount it on another machine that also boots from a 'bootdisk'... 'myhostname-bootdisk' might be better, albeit a bit verbose.

I'm not sure if there are canonical policies for that sort of thing, but I'd be interested in hearing about recommendations in this area.

Now, getting to the actual set up of the drive.

2) connect the disk to the USB port, and check out the dmesg log to find out the correct device name, something like da0 or da1 (depending on whether it's your first USB or SCSI disk, or your second one, or ...)

# dmesg | tail
da0 at umass-sim0 bus 0 scbus6 target 0 lun 0
da0: <WD My Book 1230 1050> Fixed Direct Access SCSI-6 device
da0: 400.000MB/s transfers
da0: 1907697MB (3906963456 512 byte sectors: 255H 63S/T 243197C)
da0: quirks=0x2<NO_6_BYTE>
#

In this case, it's da0 and it's connected to a USB3 port (so it can do 400 MB/s rather than 40 MB/s for USB2).

As always: make sure you select the right device name, because formatting the wrong drive is bad and will cause your data to go away. If you want to check out which disks are present, you can type:

# camcontrol devlist

You can also use the usbconfig command to see what USB hubs and devices are present on your system:

# usbconfig

You may also want to use the 'mount' command to check which disks are currently mounted, but with volume labels being used instead of phycical device names, you may not see the 'real' devices names in there (e.g. /dev/ufs/bootdisk instead of /dev/da1 or something similar).

3a) Once certain which disk to use, if a UFS filesystem is desired, proceed thusly (if a ZFS filesystem is desired, move on to step 3b):

(note: /dev/XXX represents the new disk, such as /dev/da0 or /dev/ada1)

# dd if=/dev/zero of=/dev/XXX bs=1k count=2
# gpart create -s gpt XXX
# gpart add -t freebsd-ufs XXX
# newfs -U -L myvolume /dev/XXXp1   ; create a UFS filesystem with label myvolume on partition p1
# mkdir -p /mnt/newmountpoint
# mount /dev/ufs/myvolume /mnt/newmountpoint

This creates a whole disk for FreeBSD (such as a data disk). If you want to set up a disk with multiple filesystems, you can do something like:

(This creates a 'USB boot disk')

# dd if=/dev/zero of=/dev/XXX bs=1k count=2
# gpart create -s gpt XXX
# gpart add -t freebsd-boot -s 512k -a4k -l usbboot XXX
# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i1 XXX
# gpart add -t freebsd-ufs -l usbrootfs -b 1m -s 2g XXX
# gpart add -t freebsd-ufs -l usbvarfs -a 1m -s 2g XXX
# gpart add -t freebsd-ufs -l usbusrfs -a 1m XXX
# gpart show -l XXX         ; check out the partitions that we're created
# newfs -U -t /dev/gpt/usbrootfs
# newfs -U -t /dev/gpt/usbvarfs
# newfs -U -t /dev/gpt/usbusrfs

Et voilą, finished. You may want to add a line to /etc/fstab to have /dev/ufs/myvolume mounted automatically at boot time. Always use volume label names instead of physical disk drive names, especially for USB drives where the disk drive name may change across reboots depending on what USB devices are plugged into the computer's ports and USB hubs.

3b) If a ZFS filesystem is desired instead, skip step 3a and proceed thusly (with /dev/XXX representing the new disk, such as /dev/da0 or /dev/ada1 once again):

(Once again, this creates a 'USB boot disk')

# dd if=/dev/zero of=/dev/XXX bs=1k count=2
# gpart create -s gpt XXX
# gpart add -t freebsd-boot -s 512k -a4k -l usbboot XXX
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 XXX
# gpart add -t freebsd-zfs -l usb0 XXX
    ...one can verify with 'gpart show XXX'
# zpool create -m /mnt zroot /dev/gpt/disk-main

Et voilą, finished.

4) At this point, your disk is up and running. Do not forget to use mount to make it available under FreeBSD, and to umount it before unplugging it.

Good luck!

Supplementary reading

You may want to check out http://www.macfreek.nl/memory/FreeBSD9withZFSbootdisk for more info. Furthermore, http://www.macfreek.nl/memory/FreeBSD9onSoekrisnet6501 may also be pertinent. And about ZFS, do check out: http://nex7.blogspot.ca/2013/03/readme1st.html and of course this: http://www.solarisinternals.com/wiki/index.php/ZFSEvilTuning_Guide

/FreeBSD | Posted at 01:02 | permanent link