Skip to content

Instantly share code, notes, and snippets.

@liweitianux
Last active December 17, 2023 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liweitianux/547652a3dd3a853afed71ba50410ffb5 to your computer and use it in GitHub Desktop.
Save liweitianux/547652a3dd3a853afed71ba50410ffb5 to your computer and use it in GitHub Desktop.
DragonFly BSD Installation (UEFI & HAMMER2)

DragonFly BSD Installation

Date: 2023-04-22

Setup:

  • Disk: /dev/da3 (500GB)
  • Use full disk
  • UEFI boot
  • GPT disk type (don't use disklabel64(8))
  • HAMMER2 filesystem

1. Format Disk

$ gpt create -f da3
$ gpt add -t efi -s 262144 da3  # ESP (128MB)
$ gpt add -t ufs -s 4194304 da3  # UFS /boot (2GB)
$ gpt add -t swap -s 33554432 da3  # swap (16GB)
$ gpt add -t hammer2 da3  # all remaining space

NOTE: Generally, 1GB is enough for the /boot partition, which is also the default setting in DragonFly's installer. It's enough to hold the following 3 kernels:

  • /boot/kernel: the main kernel, unstriped with debug info, ~600-700MB
  • /boot/kernel.old: the old kernel, striped, ~100MB
  • /boot/kernel.bak: the backup kernel, striped, ~100MB

I made the /boot partition 2GB, because I want to keep the old kernel unstriped, e.g., by setting NO_KERNEL_OLD_STRIP=yes in /etc/make.conf.

2. Create Filesystems

$ newfs_msdos -F 16 -L EFI /dev/da3s0
$ newfs -n BOOT /dev/da3s1
$ newfs_hammer2 -L ROOT /dev/da3s3

$ mount /dev/da3s3@ROOT /mnt

$ mkdir /mnt/boot
$ mount -t ufs /dev/da3s1 /mnt/boot

$ mkdir /mnt/boot/efi
$ mount -t msdos /dev/da3s0 /mnt/boot/efi

$ hammer2 -s /mnt pfs-create HOME
$ mkdir /mnt/home
$ mount /dev/da3s3@HOME /mnt/home

$ hammer2 -s /mnt pfs-create BUILD
$ mkdir /mnt/build
$ mount /dev/da3s3@BUILD /mnt/build

Create nullfs mounts in /build:

$ cd /mnt
$ mkdir -p   build/usr.obj   usr/obj
$ mount_null build/usr.obj   usr/obj
$ mkdir -p   build/var.cache var/cache
$ mount_null build/var.cache var/cache
$ mkdir -p   build/var.crash var/crash
$ mount_null build/var.crash var/crash
$ mkdir -p   build/var.log   var/log
$ mount_null build/var.log   var/log
$ mkdir -p   build/var.spool var/spool
$ mount_null build/var.spool var/spool

3. Create Filesystem Layout

$ mtree -deU -f /etc/mtree/BSD.root.dist    -p /mnt
$ mtree -deU -f /etc/mtree/BSD.var.dist     -p /mnt/var
$ mtree -deU -f /etc/mtree/BSD.usr.dist     -p /mnt/usr
$ mtree -deU -f /etc/mtree/BSD.include.dist -p /mnt/usr/include

4. Copy System

$ cpdup -vI /        /mnt
$ cpdup -vI /boot    /mnt/boot
$ cpdup -vI /var/log /mnt/var/log

$ cd /mnt
$ rm -rf README* autorun* dflybsd.ico index.html
$ rm -rf etc
$ mv etc.hdd etc

5. Configurations

NOTE: Recommend to use the fixed serial number in /dev/serno instead of da3.

Booting:

$ cat > /mnt/boot/loader.conf << _EOF_
vfs.root.mountfrom="hammer2:/dev/da3s3@ROOT"
_EOF_

$ mkdir -p /mnt/boot/efi/EFI/BOOT
$ cp /boot/boot1.efi /mnt/boot/efi/EFI/BOOT/BOOTX64.efi

# (optional)
$ mkdir -p /mnt/boot/efi/dragonfly
$ cp /boot/boot1.efi /mnt/boot/efi/dragonfly/

Filesystems:

$ cat > /mnt/etc/fstab << _EOF_
# Device			Mountpoint	FStype	Options		Dump	Pass#
/dev/da3s3@ROOT			/		hammer2	rw		1	1
/dev/da3s3@HOME			/home		hammer2	rw		2	2
/dev/da3s3@BUILD		/build		hammer2	rw		2	2
/dev/da3s1			/boot		ufs	rw		2	2
/dev/da3s0			/boot/efi	msdos	rw,noauto	2	2
/dev/da3s2			none		swap	sw		0	0
/build/usr.obj			/usr/obj	null	rw		0	0
/build/var.cache		/var/cache	null	rw		0	0
/build/var.crash		/var/crash	null	rw		0	0
/build/var.log			/var/log	null	rw		0	0
/build/var.spool		/var/spool	null	rw		0	0
proc				/proc		procfs	rw		0	0
_EOF_

System settings:

$ cat >> /mnt/etc/rc.conf << _EOF_
dumpdev="/dev/da3s2"
hostname="???"
tmpfs_tmp="YES"
tmpfs_var_run="YES"
dhcpcd_enable="YES"
sshd_enable="YES"
dntpd_enable="YES"
powerd_enable="YES"
_EOF_

User and password:

$ pwd_mkdb -p -d /mnt/etc /mnt/etc/master.passwd
$ pw -V /mnt/etc userdel installer
$ chroot /mnt passwd

Timezone:

$ ln -s ../usr/share/zoneinfo/???/??? /mnt/etc/localtime

6. Finish Up

$ umount /mnt/boot/efi /mnt/boot /mnt/build/* /mnt/build /mnt
$ reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment