Archives For BSD

Another self-reference short post that can be useful for any OpenBSD newbie and because I love to go through the basics from time to time just to don’t lose my expertise :-)

Also I’ll explain the basics about how disks and partitions are managed in OpenBSD

Identify and prepare the disk:

There are two types of disks common to most platform where OpenBSD can run:

  • IDE disks. Identified as wdX
  • SCSI disks and devices that use SCSI commands. Identified as sdX. This category includes also the USB and SATA disks.

Our disk for this example will be a SCSI one, sd3. Using dmesg check that the system has recognized the device.

[root@obsd ~]# dmesg |grep SCSI
sd0 at scsibus1 targ 0 lun 0: <VMware,, VMware Virtual S, 1.0> SCSI2 0/direct fixed
sd1 at scsibus1 targ 1 lun 0: <VMware,, VMware Virtual S, 1.0> SCSI2 0/direct fixed
sd2 at scsibus1 targ 2 lun 0: <VMware,, VMware Virtual S, 1.0> SCSI2 0/direct fixed
sd3 at scsibus1 targ 3 lun 0: <VMware,, VMware Virtual S, 1.0> SCSI2 0/direct fixed
[root@obsd ~]#

Next initialize the MBR of the disk using the default template. Use fdisk -i to perform the task.

[root@obsd ~]# fdisk -i sd3
Do you wish to write new MBR and partition table? [n] y
Writing MBR at offset 0.
[root@obsd ~]# fdisk sd3
Disk: sd3       geometry: 1044/255/63 [16777216 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: A6      0   1   2 -   1043 254  63 [          64:    16771796 ] OpenBSD    
[root@obsd ~]#

As it can be seen the partition number 3 has been initialize as OpenBSD. In the example we are using the whole disk for OpenBSD, if not you should enter in edition mode with fdisk -i <disk> and partition the disk appropriately.

Partition the disk using disklabel:

Here you can be confused, because really we are going to partition the partition. These partition are also known as Filesystem Partitions since is on top of them where the filesystems and swap devices are created. And the fdisk partitions are known as MBR Partitions.

In other BSD systems, like FreeBSD, these partitions are called slices however in OpenBSD historically have been called also partitions which have lead to some confusion.

Disklabel partitions are identified by appending a letter to the disk identifier, like sd3a which represents the first partition of the SCSI disk 3. There are some reserved letters:

  • a – represents always the root partition of the disk.
  • b – is always use a swap device.
  • c – represents the whole disk.

And finally here it is an example on how to create a filesystem partition. Use disklabel -E <disk> to edit the disk.

[root@obsd ~]# disklabel -E sd3
Label editor (enter '?' for help at any prompt)
> p
OpenBSD area: 64-16771860; size: 16771796; free: 16771796
#                size           offset  fstype [fsize bsize  cpg]
  c:         16777216                0  unused                  
> a a
offset: [64]
size: [16771796]
FS type: [4.2BSD]
> p
OpenBSD area: 64-16771860; size: 16771796; free: 20
#                size           offset  fstype [fsize bsize  cpg]
  a:         16771776               64  4.2BSD   2048 16384    1
  c:         16777216                0  unused                  
> q
Write new label?: [y] y
[root@obsd ~]#
[root@obsd ~]# disklabel sd3
# /dev/rsd3c:
type: SCSI
disk: SCSI disk
label: VMware Virtual S
uid: 2462f082e9092afc
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 1044
total sectors: 16777216
boundstart: 64
boundend: 16771860
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize  cpg]
  a:         16771776               64  4.2BSD   2048 16384    1
  c:         16777216                0  unused                  
[root@obsd ~]#

Create the file system:

Use newfs against the special raw device file to create the file system. By default OpenBSD uses the 4.3BSD file system to build file systems with backward compatibility with older boot ROMS, however it also support Fast File System (FFS) as the default format for filesystem smaller that 1TB and Enhanced Fast File System (FFS2) for file systems larger than 1TB.

[root@obsd ~]# newfs /dev/rsd3a
/dev/rsd3a: 8192.0MB in 16777216 sectors of 512 bytes
41 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each
super-block backups (for fsck -b #) at:
 32, 414688, 829344, 1244000, 1658656, 2073312, 2487968, 2902624, 3317280, 3731936, 4146592, 4561248, 4975904, 5390560, 5805216, 6219872, 6634528, 7049184, 7463840, 7878496, 8293152, 8707808, 9122464,
 9537120, 9951776, 10366432, 10781088, 11195744, 11610400, 12025056, 12439712, 12854368, 13269024, 13683680, 14098336, 14512992, 14927648, 15342304, 15756960, 16171616, 16586272,
[root@obsd ~]#

Next you can mount your newly created file system like any other Unix system.

[root@obsd ~]# mkdir /data
[root@obsd ~]# mount /dev/sd3a /data
[root@obsd ~]#
[root@obsd ~]# df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/sd0a      5.8G   43.1M    5.4G     1%    /
/dev/sd0d      508M   10.4M    472M     2%    /home
/dev/sd0f     1001M    6.0K    951M     0%    /tmp
/dev/sd0g     25.3G    625M   23.4G     3%    /usr
/dev/sd0e      1.9G    5.1M    1.8G     0%    /var
/dev/sd3a      7.9G    2.0K    7.5G     0%    /data
[root@obsd ~]#

And of course you can add it to the /etc/fstab file to provide persistence through a reboot of the system.

Juanma.

Network interface trunking is the OpenBSD equivalent of HP-UX Auto-Port Aggregation feature. It allows to combine two or more physical interfaces into a virtual one that will send the outgoing traffic through the physical ports with an algorithm that depends on the trunking protocol configured.

The trunk driver has been available since OpenBSD 3.8, then it only supported the roundrobin protocol, and in the current version, OpenBSD 4.7,  it supports the following protocols:

  • Broadcast: Sends frames to all ports of teh trunk and equally receives frames from any port.
  • Roundrobin: Distributes outgoing traffic through all active ports and accepts incoming traffic from any active port.
  • Failover: Sends and receives traffic only through the master port. If the master port becomes unavailable, the next active port is used. The first interface added is the master port; any interfaces added after that are used as failover devices.
  • Loadbalance: The Loadbalance protocol balances the outgoing traffic across the active ports based on hashed protocol header information and accepts incoming traffic from any active port. The hash includes the Ethernet source and destination address, and, if available, the VLAN tag, and the IP source and destination address.
  • LACP: Used to provide redundancy and increase link speed, it uses the IEEE 802.3ad Link Aggregation Control Protocol (LACP) and the Marketer Protocol. It requires a LACP capable switch.
  • None: This protocol disables any traffic without disabling the trunk interface itself.

Lets create a failover trunk interface as an example. First we are going to activate the physical interfaces and add them to the trunk0 interface.

[obsd47]/# ifconfig em1 up
[obsd47]/# ifconfig em2 up
[obsd47]/# ifconfig trunk0 trunkport em1
[obsd47]/# ifconfig trunk0 trunkport em2
[obsd47]/# ifconfig trunk0
trunk0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
        lladdr 00:0c:29:24:b7:c6
        priority: 0
        trunk: trunkproto roundrobin
                trunkport em2 active
                trunkport em1 master,active
        groups: trunk
        media: Ethernet autoselect
        status: active
[obsd47]/#

Secondly configure the trunking protocol and the IP address of the interface.

[obsd47]/# ifconfig trunk0 trunkproto failover 192.168.126.5 netmask 255.255.255.0 up [obsd47]/# ifconfig lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33200 priority: 0 groups: lo inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5 em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 lladdr 00:0c:29:24:b7:bc priority: 0 media: Ethernet autoselect (1000baseT full-duplex,master) status: active inet 192.168.126.4 netmask 0xffffff00 broadcast 192.168.126.255 inet6 fe80::20c:29ff:fe24:b7bc%em0 prefixlen 64 scopeid 0x1 em1: flags=8b43<UP,BROADCAST,RUNNING,PROMISC,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500 lladdr 00:0c:29:24:b7:c6 priority: 0 trunk: trunkdev trunk0 media: Ethernet autoselect (1000baseT full-duplex,master) status: active inet6 fe80::20c:29ff:fe24:b7c6%em1 prefixlen 64 scopeid 0x2 em2: flags=8b43<UP,BROADCAST,RUNNING,PROMISC,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500 lladdr 00:0c:29:24:b7:c6 priority: 0 trunk: trunkdev trunk0 media: Ethernet autoselect (1000baseT full-duplex,master) status: active inet6 fe80::20c:29ff:fe24:b7d0%em2 prefixlen 64 scopeid 0x3 enc0: flags=0<> mtu 1536 priority: 0 trunk0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 lladdr 00:0c:29:24:b7:c6 priority: 0 trunk: trunkproto failover trunkport em2 trunkport em1 master,active groups: trunk media: Ethernet autoselect status: active inet 192.168.126.5 netmask 0xffffff00 broadcast 192.168.126.255 inet6 fe80::20c:29ff:fe24:b7c6%trunk0 prefixlen 64 scopeid 0x6 pflog0: flags=141<UP,RUNNING,PROMISC> mtu 33200 priority: 0 groups: pflog [obsd47]/#

At this point we have a configured trunk interface in failover, but of course we want to make these changes persistent through a reboot of the server. We need to create a configuration file for each of the physical interfaces and another one for the trunk interface.

[obsd47]/# echo "up" >hostname.em1
[obsd47]/# echo "up" >hostname.em2
[obsd47]/# echo "trunkproto failover trunkport em1 trunkport em2 192.168.126.5 netmask 255.255.255.0" > hostname.trunk0
[obsd47]/#
[obsd47]/# cat hostname.trunk0
trunkproto failover trunkport em1 trunkport em2 192.168.126.5 netmask 255.255.255.0
[obsd47]/#

Now reboot and check that everything went well and the trunk0 interface is up and running. Of course the same procedure can be used to create a trunk interface for any of the supported protocols.

Juanma.

Because a picture is worth a thousand words.

This is my laptop, an HP 6730b with a  Core 2 Duo 2.53GHz processor and 2GB of RAM, running 5 VMs with different flavors of BSD along with other applications. The VMs are running OpenBSD 4.6 (two of them, one with XDM), NetBSD 5.0.1, FreeBSD 7.2 and DragonflyBSD 2.4.1 and some of the other applications are AIMP2, TweetDeck, MS Outlook and Console2 with a Powershell tab.

The System Information window from Sysinternals Process Explorer is showing the amount of RAM consumed, still 300MB free :-D

Like I said BSD… don’t you love it?

Juanma.

OpenBSD and VirtualBox

December 14, 2009 — 6 Comments

I’ve been using OpenBSD since the 3.0 version as desktop, in my home servers and even in production systems, some time ago I decided to virtualize my OpenBSD infrastructre first with VMware Server and later with VirtualBox (both of them with Linux as the host system) which is much more powerfull; but when I started to use VirtualBox a year or so ago I discovered that installing OpenBSD in VirtualBox can be a pain in the ass.

The installation went smothly until I got the following error:

uid 0 on /: file system full
/: write failed, file system is full
Segmentation fault

Sometimes the installation started despite of the error but it did not finish correctly, others  the installation process hung up and had to forcely shutdown the VM or simply the installation aborted. I tried several times and got some weird errors and the previous error not always at the same step.

I did a small research and found a couple of solutions for this issue.  The first solution was to enable VT-x/AMD-V virtualiztion extensions, but my processor didn’t have those extensions so this solution didn’t solve my problem.

The second workaround finally allowed me to install OpenBSD without errors. The virtual machine has to be started from the command line with the -norawr0 option:

jmr@wopr:~# VirtualBox -startvm <uid_or_name_of_the_vm> -norawr0

jmr@wopr:~# VBoxSDL -norawr0 -vm <uid_or_name_of_the_vm>

One final note, with OpenBSD 4.6 I didn’t get the error, even with a processor without the VT-x extensions.

Juanma.