Category Archives: IT

Background Process

I am just a user,

And to me you are the root.

Won’t you chmod your heart?

Give me permission to execute.

My stdout won’t be scripted,

I’ll pipe to you fresh input every time.

You could stay a daemon in my memory,

A process too strong for kill -9.

Making Audiobooks for iPhone (in Linux/MacOS)

If you have audiobooks on CD that you want to have on your iPod or iPhone, here are some rough steps to turn them into iDevice-compatible files. Along the way, I’ll show you what I learned about how those files are constructed, i.e. what works and doesn’t.

The first step, of course, is to rip the CD to audio files. I prefer to rip using abcde to FLAC files. This preserves the full fidelity of the audio file (for now, anyway–we will compress the audio later).

$ abcde -o flac /dev/disk2

In my case above, the disc drive is /dev/disk2, but if you don’t know which one yours is, you can use drutil to check, as per the instructions here.

The next step is to combine the audio files into one file. For whatever reason, the option in abcde to rip a CD as one file isn’t working for me and I haven’t had time to dive into why. So, instead, I use sox to concatenate the files into one audio stream. You can do this by running sox and passing in as the first parameters the input files, in order. The last parameter is the output file.

sox 01.flac 02.flac 03.flac 04.flac 05.flac Disc1.flac

The next step is to update the metadata on the FLAC files that were the Discs. The reason for this is that we want the metadata to be up-to-date before we convert the file to the format that the iDevice is expecting. The metadata will be carried into the new file, so it is important to get it right at this stage.

  1. The ARTIST tag should be the book’s author, and should be consistent across all files
  2. The TRACKTOTAL should be the number of discs
  3. The TRACKNUMBER should be the disc number for each file
  4. The TITLE should be descriptive, I use “Disc x”, replacing x with each disc number
  5. The ALBUM should be the name of the book, and should be consistent across all files

Below is an example of me editing one disc file. I start by listing the information (I’ve trimmed a lot of the output), then I use metaflac --remove-tag to remove each tag and metaflac --set-tag to replace it with a new tag. I do this for each disc in the collection.

metaflac --list Disc4.flac
METADATA block #2
  type: 4 (VORBIS_COMMENT)
  is last: true
  length: 177
  vendor string: reference libFLAC 1.3.3 20190804
  comments: 7
    comment[0]: ARTIST=Brené Brown
    comment[1]: ALBUM=Rising Strong [Disc 4]
    comment[2]: TITLE=Track 1
    comment[3]: DATE=2015
    comment[4]: TRACKNUMBER=01
    comment[5]: TRACKTOTAL=13
    comment[6]: CDDB=b011fb0d
$ metaflac --remove-tag=ALBUM Disc4.flac 
$ metaflac --set-tag=ALBUM="Rising Strong" Disc4.flac 
$ metaflac --remove-tag=TITLE Disc4.flac 
$ metaflac --set-tag=TITLE="Disc 4" Disc4.flac 
$ metaflac --remove-tag=TRACKNUMBER Disc4.flac 
$ metaflac --set-tag=TRACKNUMBER=04 Disc4.flac 
$ metaflac --remove-tag=TRACKTOTAL Disc4.flac 
$ metaflac --set-tag=TRACKTOTAL=07 Disc4.flac 

Once the metadata is set, it’s time to convert the files so that the iDevice can read them. Here are the important points:

  1. The file must be MPEG-4 audio. I use the AAC format and that seems to work fine
  2. The filename extension MUST be .m4b which stands for “MP4 Book” (it won’t work otherwise)

I use ffmpeg to convert the audio files.

$ ffmpeg -i Disc1.flac -c:a aac Disc1.m4b

Once the files are all converted, place them into one directory. Then, open the Books app on your Mac, import the directory (File > Add to Library), and you should see a new book in the collection.

You can sync the book to your iDevice through the Finder app once your iDevice is connected to your Mac via USB.

  1. Follow the prompts on your Mac and/or your iDevice to establish “Trust” between the devices
  2. Open the Finder
  3. Click on the iDevice
  4. Click “Audiobooks” in the top row of options
  5. Select “Sync audiobooks onto <devicename>”
  6. Choose what books (or all books) you would like to sync
  7. Apply

FreeNAS and SMBv1 Woes

I recently upgraded my primary FreeNAS to the latest patches (of course, only after double-checking that my data was properly replicated to my secondary!). Afterward, I started having issues with other machines not being able to mount the shares on the FreeNAS via SMB. The issues are outlined below (with the solutions).

From Nautilus (file browser) in Ubuntu, if I clicked on the saved share (the credentials are saved also) I would instantly get a message “Oops! Something went wrong. Unhandled error message: Failed to mount Windows share: Connection timed out.” This made no sense to me. If it were an actual timeout, then it should at least take several seconds between the attempt and the failure, but this was 100% instant.

Another server that had the share in its /etc/fstab would not mount the share, either. In dmesg, the error was “CIFS VFS: cifs_mount failed w/return code = -95”

On that same server, if I ran smbclient interactively, like smbclient -L [IP of FreeNAS], the error message returned was “protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE”

I found some posts around that seemed to indicate that it was likely to be an issue with the SMB version. As it turns out, in a recent patch for FreeNAS, they disabled SMBv1 support by default. As a troubleshooting step, I enabled SMBv1 support on the SMB service on my FreeNAS box, and I was able to mount the share from my other systems again. However, that wasn’t the true fix. The fine people that maintain FreeNAS disabled SMBv1 support by default for some good reasons. So, I needed to figure out how to get a newer version of SMB working.

In some of the posts mentioned above, people talked about setting client min version and client max version explicitly in smb.conf, but (1) it was not clear to me from their posts if they were doing this on the server or the client and (2) I tried it on my client (since the server is the FreeNAS box and is BSD-based and I’m not about to start mucking with the config files if I don’t have to–and I believed it was a client-side issue anyway) and the workaround didn’t seem to work correctly for me. After a bunch more experimentation and trying it on other clients, I realized that the fix was working…kind of. It fixed my Nautilus/GVFS issues, but it did not fix my issues with mounting from /etc/fstab.

(Conclusion 1) On the client side, you must specify client min protocol = SMB2 and client max protocol = SMB3 (or otherwise sane values) in /etc/samba/smb.conf to alleviate the issue, but doing so only fixes the smb command-line tools such as smbclient and also GVFS/Nautilus, but will not fix any shares being mounted via /etc/fstab

After some more Googling, reading, and experimentation, I came across this post which held the gem I needed.

(Conclusion 2) If you have a share being mounted in /etc/fstab, you must specify the SMB version you want to use (I used 3.0) in the options in the line for the mount in /etc/fstab, which will look like this: vers=3.0 (or 2.0 if you prefer). Here’s an example:

//samba-server-name/share-name/  /path/to/mount/point    cifs    rw,auto,user,credentials=/etc/samba/creds.file,uid=user-to-use,gid=group-to-use,vers=3.0