Tutorials:FreeBSD: Setup a small kimsufi (ovh) server (non-zfs) on FreeBSD 10.1 (disk setup ufs, vanilla freebsd, ipv6)

From Knowledge base
Revision as of 11:12, 12 March 2018 by Celogeek (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This tutorial is for OVH Kimsufi server, the small one, where you cannot setup ZFS. They are delivered with a wrong partition scheme by default and a custom kernel that break after the first freebsd-update. It is almost impossible to repair after reboot.

As a bonus, I give you a way of setting a working IPV6, which is not very obvious with OVH.

In this topic we will :

Default install FreeBSD 10

I strongly suggest to add an ssh key, it allows a passwordless connection to your server and in rescue mode.

First of all, you need to get your network configuration. Install a default FreeBSD 10.1. Do not care about the partitioning; we will reset this in rescue later.

Get your RC file from the server and adapt it this way:

/etc/rc.conf:

sshd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
local_unbound_enable=yes

# IPv4 configuration
ifconfig_em0="inet YOURIPV4 netmask 255.255.255.0 broadcast YOURIPV4_BROADCAST"
defaultrouter="YOURIPV4_ROUTER"

# IPv6 configuration
ipv6_activate_all_interfaces="YES"
ipv6_network_interfaces="auto"
ip6addrctl_policy="ipv6_prefer"
ifconfig_em0_ipv6="inet6 accept_rtadv YOURIPV6 prefixlen YOURPREFIX"
ipv6_defaultrouter="YOUR_DEFAULT_IPV6_ROUTER"

hostname="YOUR_IPV4_HOSTNAME"

In this case, your ethernet card name is "em0". You may have something else. Use the name of your ethernet configuration.

Reinitialize disk (ufs for small server)

Now you need to restart in rescue. Go to your interface, NetBoot, Rescue, select bsd10_64-rescue-pro and validate. Then reboot your server.

OVH send the remote information as soon as the server is ready.

Connect with ssh, and be ready to prepare your disk.

I follow the GPT version of this tutorial : Disk Setup

The GPT setting is straightforward, and the OVH server is fresh enough to support it! The mbr version is far more complicated and pointless in this case.

Retrieve your disk information with gpart:

$ gpart show
       34  976773101  ada0  MBR  (466G)

In my case, it is "ada0".

The first partition is the bootable one. It has to contain the /boot. Otherwise, your server will not start.

To simplify, I create a big root partition and let enough swap at the end. You need at least 2GB for the root, but 4GB may be better. It eases future updates.

Prepare the partition:

$ gpart destroy -F ada0
$ gpart create -s gpt ada0
$ gpart add -t freebsd-boot -l gpboot -b 40 -s 512K ada0
$ gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0

You need now to do some math to get your swap at the end.

Let's show again what left of the partition :

$ gpart show
     34  8388541  ada0  GPT  (4.0G)
     34        6        - free -  (3.0K)
     40     1024     1  freebsd-boot  (512K)
     1064  8387511        - free -  (4.0G)

     34  8388541  diskid/DISK-VB01f2c048-170e4432  GPT  (4.0G)
     34        6                                   - free -  (3.0K)
     40     1024                                1  freebsd-boot  (512K)
     1064  8387511                                   - free -  (4.0G)

We can see in my case than we have "8387511" sectors free. It is equivalent to 4GB of free space. The sector size seems to be 512 = 4 * 1024 * 1024 * 1024 / 8387511

So let say I want a swap partition with 256MB: 256 * 1024 * 1024 / 512 = 524288 sectors.

I put the partition at position 1M to be aligned at sector number 2048. The free space left is : 8387511 - (2048 - 1064) = 8386527 The root partition size is : 8386527 - 524288 = 7862279 (3839MB)

Now we can create a partition of 3839M and it will left 256M for the swap partition :

$ gpart add -t freebsd-ufs -l gprootfs -b 1M -s 3839M ada0
$ gpart add -t freebsd-swap -l gpswap ada0

You can readjust the partition size if it is not exactly what you want this way:

$ gpart delete -i 3 ada0
$ gpart delete -i 2 ada0
$ gpart add -t freebsd-ufs -l gprootfs -b 1M -s 3838M ada0
$ gpart add -t freebsd-swap -l gpswap ada0

Now you can format your root partition:

$ newfs -U /dev/gpt/gprootfs

Mount it to /mnt:

$ mount /dev/gpt/gprootfs /mnt
$ cd /mnt

Install vanilla FreeBSD

The vanilla FreeBSD is the official kernel, ideal for future update without issues.

Now you can fetch the latest release.

Go to the freebsd ftp and find the release you want : FreeBSD FTP

In my case, I take the 10.1-RELEASE.

The minimum is to take those files:

  • base.txz
  • kernel.txz

I fetch everything, feel free to keep what you need:

$ fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.1-RELEASE/base.txz
$ fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.1-RELEASE/kernel.txz

# not mandatory
$ fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.1-RELEASE/doc.txz
$ fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.1-RELEASE/games.txz
$ fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.1-RELEASE/lib32.txz
$ fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.1-RELEASE/ports.txz
$ fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.1-RELEASE/src.txz

Unpack them in your /mnt directory:

$ ls *.txz | xargs -n1 tar -Jxvf
$ rm *.txz

Setup the "fstab" file in the "etc" directory:

/etc/fstab:

# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/gpt/gpswap         none            swap    sw              0       0
/dev/gpt/gprootfs       /               ufs     rw              1       1

Setup the "rc.conf" in the "etc" directory. You should use the RC config you have saved at the beginning of this tutorial. Use this setup below with your network configuration to ensure ipv6 works:

/etc/rc.conf:

sshd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
local_unbound_enable=yes
ifconfig_em0="inet YOURIPV4 netmask 255.255.255.0 broadcast YOURIPV4_BROADCAST"
defaultrouter="YOURIPV4_ROUTER"

# IPv6 configuration
ipv6_activate_all_interfaces="YES"
ipv6_network_interfaces="auto"
ip6addrctl_policy="ipv6_prefer"
ifconfig_em0_ipv6="inet6 accept_rtadv YOURIPV6 prefixlen YOURPREFIX"
ipv6_defaultrouter="YOUR_DEFAULT_IPV6_ROUTER"
hostname="YOUR_IPV4_HOSTNAME"

SSH

First be sure you can login with the root user:

/etc/ssh/sshd_config:

PermitRootLogin yes

Then add your id_rsa.pub or id_dsa.pub in /root/.ssh/authorized_keys. You can find it in your "home" in the ".ssh" directory. If you do not have one, use "ssh-keygen" to create one.

$ mkdir root/.ssh
$ cat > root/.ssh/authorized.keys
PASTE YOUR id_rsa.pub or id_dsa.pub
CTRL + D

If you prefer a root password instead, you need to enter in chroot and run "passwd":

$ mount -t devfs devfs dev
$ chroot .
$ passwd
enter a password then hit ENTER
CTRL + D
$ umount dev

Setup cron rtsol for ipv6

Add the "rtsol" cron for ipv6, or it will stop working after few minutes:

/etc/crontab:

# ipv6
*/5 *   *   *   *   root    rtsol em0

Update your distribution

You are now ready to boot on your new FreeBSD server.

Before this, in your OVH interface, go to Network, HardDrive, Save.

You can restart your server:

$ reboot

After few minutes, you can now go to your server and test ipv4 / ipv6:

$ pkg install curl
$ curl monip.org
$ curl -s monipv6.org | grep geoloc

Update your server

$ freebsd-update fetch
$ freebsd-update install
$ reboot
after reboot and reconnect
it should have nothing, but sometimes it is a 2 step process
$ freebsd-update install

Conclusion

You got on your server:

  • a clean FreeBSD distribution
  • ipv6 support
  • an easily upgradable system


Share your opinion