Calibre

Calibre
Photo by Kimberly Farmer / Unsplash

Over the past few years I have kept hearing how great it can be to run a Calibre server for your personal eBooks. Any time I have looked into it, Calibre's documentation has just never made sense to me as far what I actually need to do. Yesterday I stumbled upon a guide from Digital Ocean. And it makes sense what I am working with now, so I am going to give it a try.

Verify System Requirements

All the guide lists for requirements is the following:

A server running Ubuntu 20.04 with a sudo user and a firewall.

Well OK then. I'll start with 1vCPU and 2GB of memory, with a 30GB virtual disk. I will plan to mount the library of books from my fileserver.

Create Virtual Machine

Steps performed on HV-03 via Windows Admin Center

  • Navigate to Virtual Machines
  • Click on Add then New
    • Name: CALIBRE-01
    • Generation: Generation 2 (Recommended)
    • Virtual Processors Count: 1
    • Startup Memory: 2 GB
    • Virtual Switch: Default External Switch
    • Storage:
      • New Disk 1 Size (GB): 30
    • Click on Create
  • Select Calibre-01
  • Click on Settings
    • Navigate to Disks
      • Add my Ubuntu 22.04 ISO
      • Click Save disk settings
    • Navigate to Boot order
      • DVD
      • Hard Disk
      • Network Adapter
      • Click Save boot order
    • Navigate to Security
      • Enable Secure Boot: Yes
      • Template: Microsoft UEFI Certificate Authority
      • Click Save security settings
  • Power on CALIBRE-01

Install the Operating System

Steps performed on CALIBRE-01

  • I open the console
    • Failed to Power on with Error 'General access denied error'. Hyper-V Virtual Machine Management service Account does not have permission to open attachment 'c:\Images\Ubuntu\ubuntu-22.04-live-server-amd64-iso'

Well this is a new one for me. Looking online I came up with very little useful information that I haven't already tried. When I check the permissions on the folder and files themselves I found a whole bunch of permissions assigned to Account Unknown. This seems odd to me since I have not messed around much with permissions on HV-03. Maybe they were originally there when I copied the files to HV-03? To get this fixed I had to add the Domain Admins Group to a number of local groups on HV-03. Specifically:

  • Remote Management Users
  • Device Owners
  • Certificate Services DCOM Access
  • Access Control Assistance Operators

With the permission issue fixed I re-attach the Ubuntu ISO and it works just fine this time. The system boots without error and loads the Ubuntu 22.04 ISO.

I walk through the Ubuntu installation wizard on CALIBRE-01. While it is working I jump over to DC-02 in Windows Admin Center and create the A record CALIBRE.domain.local

Configure the Operating System

Configure SSH Key

Steps performed on my desktop via Windows Terminal

  • ssh-keygen -t ed25519
  • Move-Item -Path c:\Users\david\filename* -Destination c:\Users\david\.ssh -Force
  • I open Windows Terminal Settings
  • I open the JSON file and add the following:
            {
                "colorScheme": "Ubuntu-ColorScheme",
                "commandline": "ssh -i \"~/.ssh/example\" [email protected]",
                "experimental.retroTerminalEffect": false,
                "font": 
                {
                    "face": "Cascadia Code"
                },
                "guid": "{0caa0dad-35be-5f56-a8ff-XXXXXXXXXXXX}",
                "hidden": false,
                "name": "CALIBRE-01",
                "tabTitle": "CALIBRE-01"
            },
  • I verify the GUID is unique and save the JSON file

Configure SSH

Steps performed on CALIBRE-01

  • mkdir /home/david/.ssh
  • nano /home/david/.ssh/authorized_keys
    • I paste in the public key and save the file
  • chmod 600 /home/david/.ssh/authorized_keys
  • sudo nano /etc/ssh/sshd_config
    • PermitRootLogin no
    • PubkeyAuthentication yes
    • PubkeyAcceptedKeyTypes ssh-ed25519
    • PasswordAuthentication no
    • AuthorizedKeysFile /home/david/.ssh/authorized_keys
  • I save the file
  • sudo sshd -t
  • sudo systemctl restart ssh

Configure Firewall

Steps performed on CALIBRE-01

  • sudo ufw allow OpenSSH
  • sudo ufw enable
  • sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)

Install Calibre Server

Step 1 - Downloading and Installing the Calibre Content Server

Steps performed on CALIBRE-01

  • sudo apt update && sudo apt install -y libfontconfig libgl1-mesa-glx
  • wget https://download.calibre-ebook.com/linux-installer.sh
  • sudo sh linux-installer.sh
    • Using python executable: /usr/bin/python3
    • You are missing the system library libEGL.so.1. Try installing packages such as libegl1 and libopengl0
  • sudo apt install libegl1 libopengl0
  • sudo sh linux-installer.sh
    • Downloading calibre-6.13-0-x86_64.txz
    • Run "calbire" to start calibre

Step 2 - Creating a Library and Adding Your First Book

This step has you make a library directory and download a book to this directory. This is basically just a test. I want to just skip this and move straight into using my mount to my fileserver. First thing I do is create a copy of my book directory on my fileserver for testing.
Steps performed on DC-02 via Windows Admin Center

  • Navigate to Active Directory
  • Navigate to Browse
  • Navigate to Managed Service ACcounts
  • Create a basic service account named _service_calibre

Steps performed on Fileserver via Windows Admin Center

  • I give _service_calibre access to the books directory

Steps performed on CALIBRE-01

  • sudo apt install cifs-utils
  • nano /home/david/.calibrecredentials
username=_service_calibre
password=XXXXXXXXXXXX
domain=domain.local
  • I save the .calibrecredentials file
  • sudo nano /etc/fstab
//10.10.10.XXX/Data/Files/Books /mnt/calibre-library cifs credentials=/home/david.calibrecredentials,iocharset=utf8 0 0
  • sudo mount -a
    • mount error(13): Permission denied

I corrected my typo but that changed it from dealing with a permission denied error to an Input/Output error. I was able to get the issue resolved with the following:

  • sudo nano /etc/fstab
//10.10.10.XXX/Data/Files/Books /mnt/calibre-library cifs credentials=/home/david/.calibrecredentials,uid=1000,gid=1000,iocharset=utf8 0 0

So next the guide tells me to add a book to my library with the command:

  • calibredb add .**.mobi --with-library /mnt/calibre-library
    • /mnt/calibre-library/**.mobi not found

Well that's strange. I try with mobi and epub, both of which I have and they both give the same error. I wonder if Calibre doesn't like my folder structure? So I delete all the books and sub-folders. Then I copy in one mobi file to test.

  • calibredb add **.mobi --with-library /mnt/calibre-library
    • apsw.BusyError: BusyError: database is locked

I try running the same command again and get:

  • PermissionError: [Errno 13] Permission denied: 'mnt/calibre-library/metadata.db'

Well I see it create the database inside the mount point? Hmmm....Seems like I may need to have two separate places? When trying to unmount I am unable to. It's acting like the mount is currently in use. Expect that I haven't started Calibre at this point, so what gives? I comment out the mount in /etc/fstab and reboot.

I'll take a step back and just follow along with the walkthrough until I get a better handle on things.

  • wget http://www.gutenberg.org/ebooks/46.kindle.noimages -O christmascarol.mobi
  • mkdir /home/david/calibre
  • calibredb add .mobi --with-library calibre/

This throws out a bunch of errors about being unable to import and no such file or directory.

I run the command again and it throws out the same errors but this time it says the book already exists in the database. So when adding it does make a copy of the .mobi file and places it in a subfolder of /home/david/calibre. My reading points to Calibre not supporting networking locations. Because they put the database in the same folder as the actual Ebooks. That is a weird way to do it in my opinion but I'm no developer. Ok fine. Considering how small the book files are I can handle all of them living on the Calibre server and just backing up the books with a script back to the fileserver.

Step 3 - Running the Calibre Content Server and Viewing Your Library

Steps performed on CALIBRE-01

  • sudo ufw allow 8080
  • calibre-server calibre-library
Failed to import PyQt module: PyQt6.QtGui with error: libxkbcommon.so.0: cannot open shared object file: No such file or directory
Traceback (most recent call last):
  File "runpy.py", line 196, in _run_module_as_main
  File "runpy.py", line 86, in _run_code
  File "site.py", line 47, in <module>
  File "site.py", line 43, in main
  File "calibre/srv/standalone.py", line 227, in main
  File "calibre/srv/standalone.py", line 69, in __init__
  File "calibre/srv/handler.py", line 200, in __init__
  File "importlib/__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "bypy-importer.py", line 279, in exec_module
  File "calibre/srv/ajax.py", line 15, in <module>
  File "bypy-importer.py", line 279, in exec_module
  File "calibre/srv/content.py", line 17, in <module>
  File "bypy-importer.py", line 279, in exec_module
  File "calibre/ebooks/covers.py", line 15, in <module>
ImportError: cannot import name 'QBrush' from 'qt.core' (/opt/calibre/lib/calibre-extensions/python-lib.bypy.frozen/qt/core.pyc)

Reading to find a solution to this error. Calibre's own download page points to this link that you have to install additional packages. Maybe? Supposedly there is a list, but I see nothing of the sort, just instructions to install one package. Ok then.

  • sudo apt install libxcb-xinerama0
  • sudo sh linux-installer.sh

That still wasn't enough. I find on Calibre's site where it says I need xdg-utils as well.

  • sudo apt install xdg-utils

My alarm just rang, I'm out of time for today, so I'll have to come back and finish this up tomorrow.