LinkedIn Sourceforge

Vincent's Blog

Pleasure in the job puts perfection in the work (Aristote)

My journey in the DragonflyBSD world

Posted on 2024-09-01 21:34:00 from Vincent in DragonflyBSD

This blog post will be a bit different than the others.

Indeed, days after days, but because my limited free time I should say weeks after weeks, this page will be completed based on progress I do with DragonflyBSD

My final goal is to better understand the usage of HammerFS.

I will explain what I did to learn HammerFS, which is Hammer2 at the time of this blog.


1. Installation of DrangonflyBSD

First thing first, let's check how to install this OS which is based on FreeBSD, so there are lot of similarities between both.

I will not repeat what we can find elsewhere. You can follow the instructions documented on the DrangonflyBSD website, but I recommend you a well documented installation process written by cyruslab
The instruction for DragonflyBSD 6.4 are strictly the same as he describes.

  1. Download an USB img file : USB: dfly-x86_64-6.4.0_REL.img.bz2
  2. Uncompress it: bunzip2 dfly-x86_64-6.4.0_REL.img.bz2
  3. Insert an usb key in your PC and copy the img on it (I did that on my OpenBSD machine): dd if=dfly-x86_64-6.4.0_REL.img of=/dev/rsd1c
    Please note that in your case this could be an another reference than /dev/rsd1c !!! If you do it incorrectly you can erase one of your disk.
  4. Plug your USB key in the targeted machine and boot it
  5. Follow the instruction on the cyruslab (here)
    In my personal case, I've not follow his installation of xorg, xfce, ... Moreover with DrangonflyBSD 6.4 is will not work ;)

Indeed, I do not know why, but you have to perform few modifications to have the system correctly working:

1)
If you want to use ssh, please modify /etc/ssh/sshd_config and make sure you have this:

PasswordAuthentication yes

Once done, you can restart sshd via this command:

root@:~ # service sshd restart

Now you can ssh to your brand new DragonflyBSD ;)

2)
In /usr/local/etc/pkg/repos, do this:

root@:~ # cp df-latest.conf.sample df-latest.conf

In my case https url were not successful because of time issue. So I select too the one called TWAREN which is based on http. Just change the "enable" variable from "no" to "yes"
To solve this time effect, I've enable dntpd by adding the following line in /etc/rc.conf

dntpd_enable="YES"

Once this done, you can update your package repository:

root@:~ # pkg update
Updating Avalon repository catalogue...
Fetching meta.conf: 100%    163 B   0.2kB/s    00:01
Fetching packagesite.pkg: 100%    6 MiB 790.7kB/s    00:08
Processing entries: 100%
Avalon repository update completed. 31890 packages processed.
Updating TWAREN repository catalogue...
TWAREN repository is up to date.
All repositories are up to date.

In this case the times were aligned and certificates were OK. Other else, you have a nice error with "Avalon", and update will start with TWAREN.

Now that this is updated, you can upgrade all existing packages:

root@:~ # pkg upgrade
Updating Avalon repository catalogue...
Avalon repository is up to date.
Updating TWAREN repository catalogue...
TWAREN repository is up to date.
All repositories are up to date.
Checking for upgrades (34 candidates): 100%
Processing candidates (34 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.

In my specific case, I do not have packages to upgrade, but this would be different in your case. Just follow the instructions. Normally, "pkg" will propose the list of packages and ask you a confirmation.

Finally, installing DragonflyBSD is not a complex process, but I've lost some time to figure out what was wrong with "pkg update".

2. Basic commands concerning Hammer File System

First think first, you have to understand that DrangonflyBSD comes now with Hammer2 by default. And most of the documentation you will find on internet is related to Hammer, which is version 1. Differences are huge !!.
Both cohexists, but they are not the same.

If you aks to ChatGPT to help you, he will perform a big mess by using commands of Hammer with Hammer2. So, be very careful when you read documentation that they refer to Hammer2.

2.1 Let's do our first snapshot

For example, we will perform a snapshot of our "/" directory. Which is, if you follow the default installation instruction, where reside all the OS.

root@:~ # hammer2 snapshot /root
created snapshot ROOT.20240901.210700

Congratulation, you have your first snapshot. What we also can call a PFS (pseudo File System).

To check all existing snapshots you can do:

root@:~ # hammer2 pfs-list /root
Type        ClusterId (pfs_clid)                 Label on /root
MASTER      95136440-6708-11ef-9d2c-d53d7e980dd5 LOCAL
MASTER      9513649d-6708-11ef-9d2c-d53d7e980dd5 ROOT
SNAPSHOT    5e06a551-6895-11ef-889a-d53d7e980dd5 ROOT.20240901.210700

The last line if the one linked to your previous command. Since we have not provided a label to the snapshot command, Hammer has decided to call it "ROOT.20240901.210700".

2.2 Browse the content of a snapshot.

Now that we have this wonderfull snapshot, how to check what we have in it ?
With Hammer2, you just have to perform a mount command:

root@:~ # mount -t hammer2 @ROOT.20240901.210700 /mnt

This snapshot is just like any other mount point ;)

root@:~ # mount
serno/WD-WMAWF1704636.s1d on / (hammer2, local)
devfs on /dev (devfs, nosymfollow, local)
/dev/serno/WD-WMAWF1704636.s1a on /boot (ufs, local)
/dev/serno/WD-WMAWF1704636.s1f@DATA on /build (hammer2, local)
/build/usr.obj on /usr/obj (null)
/build/var.crash on /var/crash (null)
/build/var.cache on /var/cache (null)
/build/var.spool on /var/spool (null)
/build/var.log on /var/log (null)
/build/var.tmp on /var/tmp (null)
tmpfs on /tmp (tmpfs, local)
procfs on /proc (procfs, local)
tmpfs on /var/run/shm (tmpfs, local)
@ROOT.20240901.210700 on /mnt (hammer2, local)

You can go to /mnt and browse files and folders like any other mount point. Except that in this case this is a copy of "/".

Imagine that you want to restore a file from this snapshot, you will have just to copy it. If you want, you can also perform a diff

To leave this mount point, just umount it like usual:

root@:~ # umount /mnt

2.3 Let's create automatic snapshots.

To perform regular and automatic snapshots, DrangonflyBSD uses periodic.

All elements linked to periodic are already existing in /etc/periodic.

root@:~ # ls -al /etc/periodic/
total 12
drwxr-xr-x  1 root  wheel  0 Sep  1 16:44 .
drwxr-xr-x  1 root  wheel  0 Sep  1 17:55 ..
drwxr-xr-x  1 root  wheel  0 Dec 30  2022 daily
drwxr-xr-x  1 root  wheel  0 Dec 30  2022 monthly
drwxr-xr-x  1 root  wheel  0 Dec 30  2022 security
drwxr-xr-x  1 root  wheel  0 Dec 30  2022 weekly

To decide in details, what periodic must do, you have to do the following:

root@:~ # cp /etc/defaults/periodic.conf /etc/

As a first instance, I've adapted 2 parameters of daily scripts for snaptshots

root@:~ # diff /etc/periodic.conf /etc/defaults/periodic.conf
91c91
< daily_snapshot_hammer2_enable="YES"           # HAMMER2 snapshots
---
> daily_snapshot_hammer2_enable="NO"            # HAMMER2 snapshots
93c93
< daily_snapshot_hammer2_keep=24                # snapshots history
---
> daily_snapshot_hammer2_keep="auto"            # snapshots history

In short, with those 2 changes, I'm asking to periodic to perform daily snapshots and I'm asking to only keep last 24 ones.

You can test periodic by doing:

root@:~ # periodic daily

It takes few seconds because it does lot of things. To have a better view on those tasks, you can check /var/log/messages:

Bulkfree actions like:

Sep  1 21:29:11  kernel: hammer2_bulkfree - range 0000000014400c00-0000000f05800000
Sep  1 21:29:11  kernel: bulkfree pass statistics (100.00% storage processed):
Sep  1 21:29:11  kernel: transition->free   16
Sep  1 21:29:11  kernel: transition->staged 87
Sep  1 21:29:11  kernel: ERR(00)->allocated 0
Sep  1 21:29:11  kernel: ERR(01)->allocated 0
Sep  1 21:29:11  kernel: staged->allocated  0
Sep  1 21:29:11  kernel: ~4MB segs cleaned  0
Sep  1 21:29:11  kernel: linear adjusts     2
Sep  1 21:29:11  kernel: dedup factor       12567
Sep  1 21:29:11  kernel: max saved chains   0

But also, creating snapshots:

Sep  1 21:29:11  kernel: SNAPSHOT LOCAL PFS (IOCTL): /.daily.20240901.21:29

To have this automatically done, the last step is to add it to the cron:

root@:~ # crontab -e
0   *   *   *   *   periodic daily

So every hours at 0minutes, the periodic daily will be executed.

2.4 How to make free space on disk after file deletion ?

stay tuned right here for the next part ;)



0, 0
displayed: 762



What is the last letter of the word Python?