# mhvtl Installation and Configuration Guide

This guide details the steps to install and configure the `mhvtl` (Virtual Tape Library) on this system, including compiling from source and setting up custom paths.

## 1. Prerequisites

Ensure the necessary build tools are installed on the system.

```bash
sudo apt-get update
sudo apt-get install -y git make gcc
```

## 2. Download and Compile Source Code

First, clone the `mhvtl` source code from the official repository and then compile and install both the kernel module and the user-space utilities.

```bash
# Create a directory for the build process
mkdir /src/calypso/mhvtl_build

# Clone the source code
git clone https://github.com/markh794/mhvtl.git /src/calypso/mhvtl_build

# Compile and install the kernel module
cd /src/calypso/mhvtl_build/kernel
make
sudo make install

# Compile and install user-space daemons and utilities
cd /src/calypso/mhvtl_build
make
sudo make install
```

## 3. Configure Custom Paths

By default, `mhvtl` uses `/etc/mhvtl` for configuration and `/opt/mhvtl` for media. The following steps reconfigure the installation to use custom paths located in `/opt/calypso/`.

### a. Create Custom Directories

Create the directories for the custom configuration and media paths.

```bash
sudo mkdir -p /opt/calypso/conf/vtl/ /opt/calypso/data/vtl/media/
```

### b. Relocate Configuration Files

Copy the default configuration files generated during installation to the new location. Then, update the `device.conf` file to point to the new media directory. Finally, replace the original configuration directory with a symbolic link.

```bash
# Copy default config files to the new directory
sudo cp -a /etc/mhvtl/* /opt/calypso/conf/vtl/

# Update the Home directory path in the new device.conf
sudo sed -i 's|Home directory: /opt/mhvtl|Home directory: /opt/calypso/data/vtl/media|g' /opt/calypso/conf/vtl/device.conf

# Replace the original config directory with a symlink
sudo rm -rf /etc/mhvtl
sudo ln -s /opt/calypso/conf/vtl /etc/mhvtl
```

### c. Relocate Media Data

Move the default media files to the new location and replace the original data directory with a symbolic link.

```bash
# Move the media contents to the new directory
sudo mv /opt/mhvtl/* /opt/calypso/data/vtl/media/

# Replace the original media directory with a symlink
sudo rmdir /opt/mhvtl
sudo ln -s /opt/calypso/data/vtl/media /opt/mhvtl
```

## 4. Start and Verify Services

With the installation and configuration complete, start the `mhvtl` services and verify that they are running correctly.

```bash
# Load the kernel module (this service should now work)
sudo systemctl start mhvtl-load-modules.service

# Start the main mhvtl target, which starts all related daemons
sudo systemctl start mhvtl.target

# Verify the status of the main services
systemctl status mhvtl.target vtllibrary@10.service vtltape@11.service
```
