🔗FreeBSD zfs disk image

Use VirtualBox to install FreeBSD using UFS.

After having FreeBSD installed, update your sources and build a custom world and kernel based on your needs for the new image to be created:

# cd /usr/src
# make -j4 buildworld buildkernel

adjust -j4 to the number or cpu cores

Use this script to create the image: https://github.com/nbari/freebsd/blob/master/zfs/zfs.sh

$ mkdir /raw && cd /raw
$ fetch --no-verify-peer https://raw.githubusercontent.com/nbari/freebsd/master/zfs/zfs.sh
$ ./zfs.sh

If everything runs fine, on new files of 1GB size called disk.raw will be created.

To test your image in virtualbox, download the disk.raw and convert it to VDI format:

$ VBoxManage convertfromraw disk.raw ec2.vdi --format VDI

Since the disk is only 1GB, you may want to increase the size, this can be done like this:

$ VBoxManage modifyhd disk.vdi --resize 8192

After booting the pool need to be increased:

$ gpart show da0

Example of output:

root@/:~ # gpart show
=>       40  503316400  da0  GPT  (240G)
         40       1024    1  freebsd-boot  (512K)
       1064    2097152    2  freebsd-swap  (1.0G)
    2098216        984       - free -  (492K)
    2099200    2093056    3  freebsd-zfs  (1.0G)
    4192256  499124184       - free -  (1.0M)

Then type gpart recover da0:

$ gpart recover da0
da0 recovered

And next resize gpart resize -i 3 da0:

$ gpart resize -i 3 da0
da0 resized

-i 3, 3 is the freebsd-zfs

After resizing:

root@/:~ # gpart show
=>       40  503316400  da0  GPT  (240G)
         40       1024    1  freebsd-boot  (512K)
       1064    2097152    2  freebsd-swap  (1.0G)
    2098216        984       - free -  (492K)
    2099200  501217240    3  freebsd-zfs  (239G)

Get zpool information by typing:

$ zdb

Find the children guid from the output:

zroot -> vdev_tree -> children[0] -> guid
root@:/raw # zdb
zroot:
    version: 5000
    name: 'zroot'
    state: 0
    txg: 422
    pool_guid: 5388488397555579451
    hostid: 4037738314
    hostname: ''
    com.delphix:has_per_vdev_zaps
    vdev_children: 1
    vdev_tree:
        type: 'root'
        id: 0
        guid: 5388488397555579451
        create_txg: 4
        children[0]:
            type: 'disk'
            id: 0
            guid: 2304114010935459478
            path: '/dev/gpt/disk0'
            whole_disk: 1
            metaslab_array: 37
            metaslab_shift: 24
            ashift: 12
            asize: 8584429568
            is_log: 0
            create_txg: 4
            com.delphix:vdev_zap_leaf: 35
            com.delphix:vdev_zap_top: 36
    features_for_read:
        com.delphix:hole_birth
        com.delphix:embedded_data

Resize the pool:

$ zpool online -e zroot 2304114010935459478

Check the pool:

root@:/raw # zpool list
NAME    SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
zroot  7.98G   258M  7.73G         -     2%     3%  1.00x  ONLINE  -

🔗readonly=off

Set the / to readonly off:

$ zfs set readonly=off zroot/ROOT/default