Scripting : useful disk commands

Scripting : useful disk commands

  • mdo  DigitalBox
  •   Scripting
  •   May 27, 2025

This week we will review how to use commands relative to disk management.

They can be very useful in case you need to handle BFS volumes or any other kind of file systems.

Command Description
df Displays disk space usage for mounted file systems
dd Copies and converts raw data, often used to write disk images
mkfs Creates a new file system on a device or partition
diskimage Manipulates Haiku disk image files
mountvolume Mounts a volume by name or device path, using Haiku's volume management
unmount Unmounts a mounted volume by name or path
mount Manually mounts a file system, requires specifying the mount point and parameters
mount_nfs Mounts a remote NFS share onto the local file system
makebootable Installs Haiku boot code onto a partition or disk

df

Let's start by the df command which stands for "disk free".

If you would like to display each mounted file system with its size and its free space, type:

df -h

Please note on Haiku, the packagefs file system is also displayed, for more information on that part, you can check Haiku package management on Mark Round's website.

dd

The dd command - which mean data duplicator - is a powerful command to copy raw data.

We will use it to create an empty image of 10 Mb.

For that type:

dd if=/dev/zero of=./test.image bs=1M count=10

In the next commands, we will continue to use that test image.

mkfs

What about initializing our test image with the BFS file system?

For that type in the Terminal:

mkfs -t bfs -o 'block_size 4096; noindex' ./test.image MyImage

To confirm, type "yes" in the Terminal and validate by return key.

We have now initialized the test image with BFS under the name "MyImage".

diskimage

When you have a disk image available and would like to recognized it under Haiku, the diskimage command must be used.

In a Terminal type:

diskimage register ./test.image 

If you open DriveSetup, you will notice the addition of a new entry:

MyImage volume is now available:)

mountvolume

Last step: let's mount this new volume with the mountvolume command.

For that, type:

mountvolume /dev/disk/virtual/files/2/raw

The device raw name is the one which is displayed in the DriveSetup application.

As you can see in the above screenshot, when you open MyImage, the volume is empty.

Copy a ".cpp" file or any other kind of file into this volume:

As you can see, the BFS file system is well recognized, and you can attach -if you want to check- new attributes to this file.

Now let's verify the mounted volumes:

mountvolume -l

Everything is working as expected:)

unmount

If you don't need anymore MyImage volume, you can unmount it.

For that type:

unmount /MyImage

You can also unregister it:

diskimage unregister ./test.image

If you check in DriveSetup, the entry is now removed:

mount

If you need to mount any kind of volumes, you can also use the mount command.

This command will require to have the kind of file system to mount but also a mount point.

For instance to mount a NFS4 volume (in my case a NAS Synology), in a Terminal type:

mount -t nfs4 -p 192.168.1.79:/volume1/documents /boot/home/NAS/documents/

Once mounted, the NAS shared folder will be visible in the Tracker:

And you can use it under Haiku to transfer file from / into it:

If you would like more information on mount for NFS4 volumes, you can check the article named "Mount NFS volumes".

mount_nfs

Another command exists for NFS mount named "mount_nfs".

If you want to proceed with the same NAS connection than with the previous "mount" command, just type:

mount_nfs 192.168.1.79:/volume1/documents/ /boot/home/Desktop/NAS/documents/ 0 0

However I advice you to use the "mount" command instead of the "mount_nfs".

Indeed I noticed that this last command is having a poor transfer rate for big files.

makebootable

The last command can be used when you want to write Haiku boot code onto a partition or a disk.

For that type in a Terminal:

makebootable /Haiku

Any other disk command you would like to share for Haiku?

You can put your findings in the comments below.


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider