Skip to content

Instantly share code, notes, and snippets.

@hasezoey
Created May 30, 2023 13:55
Show Gist options
  • Save hasezoey/3de792a21699b12754f031821a476092 to your computer and use it in GitHub Desktop.
Save hasezoey/3de792a21699b12754f031821a476092 to your computer and use it in GitHub Desktop.
A Guide on how to setup a Qemu VM for Adobe Digital Editions and Calibre with DeDRM

Adobe Digital Edition and Calibre DeDRM in a VM

This guide shows how to have a ADE Setup with Calibre DeDRM via wine in qemu VM with Linux Mint.

This guide may not fully apply to your use-case, but i wanted to make it so i remember all the steps & download links in case i need to re-do the VM.

Pre-Download / Requirements

This section will list all the host requirements and files that will be downloaded throughout the guide, if wanting to download them beforehand.

Host requirements:

  • qemu
  • qemu-system-x86_64

Files to download throughout the guide:

Install the Linux VM

In this Guide i will use the distro Linux Mint because it is easiy to setup and maintain.
I had also tried Manjaro (kde), but there Adobe Digital editions could not connect to the "fulfillment server".

# Create a 20G image file - actual size will be lower thanks to compression and because the file is sparse
qemu-img create -f qcow2 img.qcow2 20G

# Start qemu with a ISO to install from
/usr/bin/qemu-system-x86_64 \
  -bios /usr/share/edk2/x64/OVMF.fd \
  -drive file=./img.qcow2,format=qcow2 \
  -enable-kvm -vga virtio -cpu host -smp 4 -m 4096 \
  -netdev user,id=mynet0,hostfwd=tcp::8080-:80 -device e1000,netdev=mynet0 \
  -virtfs local,path=./shared,mount_tag=ihc,security_model=mapped \
  -display default,show-cursor=on \
  -cdrom ./linuxmint-21.1-cinnamon-64bit.iso \
  -boot order=c,menu=on

Note: dont forget to modify the -cdrom argument to the iso that was downloaded.

Then once the VM is booted into the installed, go through all the steps the installer requires (like disk setup, copy, reboot).
I personally recommend to go with btrfs if available, because of the compression and reflinking (qcow2 is compressed already, but btrfs can optimize more inside), i use the btrfs volume with the following options (subvolumes from the linux mint installer):

subvol=/@,defaults,noatime,compress-force=zstd:10,datacow,datasum
subvol=/@home,defaults,noatime,compress-force=zstd:10,datacow,datasum

Also personally i run the VM without a swapfile, because from my experience it does not require it.

Then to start the VM again normally and conveniently without the ISO output it into a start script:

# Write the start script file
cat - <<EOF | tee start.sh
#!/bin/sh

/usr/bin/qemu-system-x86_64 \\
  -bios /usr/share/edk2/x64/OVMF.fd \\
  -drive file=./img.qcow2,format=qcow2 \\
  -enable-kvm -vga virtio -cpu host -smp 4 -m 4096 \\
  -netdev user,id=mynet0,hostfwd=tcp::8080-:80 -device e1000,netdev=mynet0 \\
  -virtfs local,path=./shared,mount_tag=ihc,security_model=mapped \\
  -display default,show-cursor=on
EOF
# Give the start file permissions to be executed
chmod +x start.sh

# Start the VM without the ISO
./start.sh

Setup system

This section is not required, but contains things i did to make the resulting system cleaner and smaller for the use-case it is meant for.

The following are all the steps i took to get the cleaner system and set it up for the specific purpose of running ADE.

# Add some things to the bashrc to make life easier
cat - <<EOF | tee -a ~/.bashrc
set -k # set bash to ignore comments
bind -s 'set completion-ignore-case on' # QOL to make bash complete even if the input is not the correct case
EOF

# And reload the bashrc
source ~/.bashrc

# Add the shared folder auto-mount to fstab
mkdir /media/shared
echo "ihc /media/shared 9p trans=virtio,nobootwait,rw,_netdev 0 0" | sudo tee -a /etc/fstab

# Remove applications that are not needed in this VM
sudo apt remove -y celluloid baobab "hexchat*" warpinator hypnotix nvidia-prime-applet blueman bluez "libreoffice-*" redshift timeshift thunderbird "transmission-*" rhythmbox pix webapp-manager "mint-*-legacy"

# Remove all auto-installed packages that were not removed with the above command
sudo apt autoremove -y

# Remove files from previously install applications in /etc
sudo rm -rf /etc/skel/.config/caja /etc/skel/.config/hexchat /etc/thunderbird

# Remove files from previously installed applications in HOME
rm -rf ~/Warpinator ~/.config/{warpinator,caja,hexchat}

# Remove links for uninstalled systemd services
sudo systemctl unmask bluetooth.service blueman-mechanism.service
sudo systemctl disable blueman-mechanism.service
sudo rm -rf /etc/systemd/system/bluetooth.target.wants/bluetooth.service

# Disable services that are not required in the VM
sudo systemctl disable cups.service cups-browsed.service apt-daily.timer apt-daily-upgrade.timer motd-news.service
# Mask those services so updates dont restore them
sudo systemctl mask cups.service cups-browsed.service apt-daily.timer apt-daily.service apt-daily-upgrade.timer apt-daily-upgrade.service motd-news.service

# Dont use plymouth for startup
sudo sed -i -e "/GRUB_CMDLINE_LINUX_DEFAULT/s/quiet//" /etc/default/grub
sudo sed -i -e "/GRUB_CMDLINE_LINUX_DEFAULT/s/splash//" /etc/default/grub
sudo sed -i -e "/GRUB_CMDLINE_LINUX_DEFAULT/s/ //" /etc/default/grub

# Change timeout from 0 to 1, so that  qemu boot warnings do not stay (and confuse why it isnt starting)
sudo sed -i -e "/GRUB_TIMEOUT=/s/0/1/" /etc/default/grub
# Add "RECORDFAIL" variable, because otherwise grub will somehow not respect the timeout
echo 'GRUB_RECORDFAIL_TIMEOUT=$GRUB_TIMEOUT' | sudo tee -a /etc/default/grub

# Disable grub OS-Prober
echo "GRUB_DISABLE_OS_PROBER=true" | sudo tee -a /etc/default/grub
# Keep GFX mode, to lessen screen-size changes
echo "GRUB_GFXMODE=auto" | sudo tee -a /etc/default/grub
echo "GRUB_GFXPAYLOAD_LINUX=keep" | sudo tee -a /etc/default/grub

# Update grub
sudo update-grub

# Update the system
sudo apt update
sudo apt upgrade -y

# Remove residual config files from uninstalled packages
dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo apt-get purge --yes

# Change systemd's resolver to use actual configuration instead of stub
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

# Compress (& defragment) btrfs
# needs to be done, because mint-installer created btrfs, but without compression
# also note that currently btrfs does not support setting compression level on defrag, so the default is used (for zstd its 3)
sudo btrfs fi defrag -vrczstd /

# Install compsize and htop, just for fun
sudo apt install -y btrfs-compsize htop

# change /tmp to be tmpfs
sudo systemctl enable tmpfiles.mount

# Reboot, so that all mounts are applied properly and running the latest install of the apt upgrade (kernel, libs, etc)
poweroff --reboot

# Mount original disk
sudo mount /dev/sda2 /mnt -o subvol=@

# Delete contents of "/tmp" because tmpfs is now used
sudo rm -rf /mnt/tmp/*
sudo rm -rf /mnt/tmp/.*

sudo umount /mnt

For me those changes removed about ~5GB of installed size, thanks to the removal of unused packages and re-compression by btrfs

Install & run wine

This section installs wine and all applications that run inside wine, also setting those applications up.

Important note: dont execute wine on the shared ihc(virtio) folder, otherwise you will run into this wine issue.

(skip the "wget" commands when having downloaded the files already on the host, but move / copy those files to somewhere that is not the shared folder)

# Add the wine-repository key
sudo mkdir -pm755 /etc/apt/keyrings
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key

# Add the wine-repository itself
# dont forget to update the URL when nothing using linux mint 21.1
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources

# Update the sources
sudo apt update

# Install wine
sudo apt install winehq-stable

# Create the wineprefix, without starting anything
wine wineboot
# Note that you will have to manually select "Install" for "Wine Mono"

# set to windows xp 64, otherwise weird errors may arise
wine winecfg -v winxp64

# Download DotNet 35 SP1
# note that winetricks's dotnet35sp1 does NOT install correctly
wget https://download.microsoft.com/download/2/0/E/20E90413-712F-438C-988E-FDAA79A8AC3D/dotnetfx35.exe

# Install DotNet 35 SP1
# Will likely end the install with "Setup Error", but it is installed correctly anyway
wine dotnetfx35.exe

# Download ADE 2.0, which is not listed anywhere, but the download still works
wget https://adedownload.adobe.com/pub/adobe/digitaleditions/ADE_2.0_Installer.exe

# Install ADE 2.0
wine ADE_2.0_Installer.exe

# Download the key-grabbing DeDRM_tools, when not also wanting to install python and pip inside wine
wget https://github.com/hasezoey/ade-key-extractor-rust/releases/download/v0.2.0/binaries.tar.gz

# Extract the archive
tar -xvf ./binaries.tar.gz

###
# Authorize ADE at this point
###

# Run binary to extract the ADE key
# If the following fails, consult https://github.com/hasezoey/ade-key-extractor-rust#usage
./ade-extract-key
# The key is now at "./ade_key.der"

Install Calibre and the DeDRM plugin

Install Calibre and the DeDRM plugin and set-up the plugin.
For this case i have chosen to use the calibre flatpak version because it is just easier to install and can be easier matched to what the plugin may require.

(skip the "wget" command when having downloaded the file already on the host)

# Install calibre as a flatpak
flatpak install com.calibre_ebook.calibre

# Download the plugin (update the plugin version if needed)
wget https://github.com/noDRM/DeDRM_tools/releases/download/v10.0.3/DeDRM_tools_10.0.3.zip

# Extract the archive
unzip ./DeDRM_tools_10.0.3.zip

###
# Start calibre
# setup the library folder
# install the plugin (use "DeDRM_plugin.zip" from the extracted archive, dont confuse it with directly downloade file "DeDRM_tools_10.0.3.zip")
# click "Customize plugin" (while having the DeDRM plugin selected)
# navigate to "Adobe Digital Editions ebooks"
# click "Import Existing Keyfiles"
# select the previously generated "ade_key.der"
# try to add a book to ADE and then in calibre (ADE stores the downloaded encrypted versions at "~/Documents/My Digital Editions/*.epub")
###

Final Notes

After following all the sections & steps above you should have a VM that has Adobe Digital Editions and Calibre with DeDRM setup and working, this section will list some related notes.

  • The VM can be re-used on other systems, but then you will have to logout and re-login inside ADE and also go through the full key extract and setup again, because the key is based on the CPU.
  • Other distors than Linux Mint (and maybe Ubuntu) you may run into ADE saying "unable to reach the fulfillment server", i encountered this while having tried to still with Manjaro.
  • The Key extraction tool used in this guide named ade-extract-key was written by me (but the original extraction code it is based on was written in DeDRM python), because i couldnt get python and the python ssl / crypto module to correctly install inside wine, this tool only requires that ADE is install inside wine (no python required)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment