Dropbox on Linux with encrypted home directory

Dropbox dropped support for all files systems except ext4 on Linux. This is a problem for everybody using an encrypted home directory since those are usually mounted via ecryptfs or similar. The following workaround makes use of an ext4 formatted file system image that is mounted via a loopback device upon login.

Step 1: create a mount point and make it read-only if not mounted

mkdir remote/Dropbox
sudo chattr +i remote/Dropbox

Change the “remote” part of the paths if you prefer to place your Dropbox folder at a different location.

Step 2: create an image file and format it

Change 10G to something that corresponds to the space that you need in order to sync your Dropbox files:

truncate -s 10G remote/.Dropbox.ext4

Alternative way of creating the image using dd:

dd if=/dev/zero of=remote/.Dropbox.ext4 count=10240 bs=1048576

Format the image with ext4:

mkfs.ext4 -F remote/.Dropbox.ext4

Step 3: create an entry in /etc/fstab

/home/<username>/remote/.Dropbox.ext4 /home/<username>/remote/Dropbox ext4 user,noauto,rw,loop,x-gvfs-hide 0 0

We use the parameter x-gvfs-hide to avoid showing the folder in sidebar of the file manager.

Step 4: use a systemd user service to mount the Dropbox image upon user login

Create the file .config/systemd/user/mountdropbox.service with the following content:

[Unit]
Description=Mounts a Dropbox ext4 image in the home directory of a user
After=home-username.mount
Requires=home-username.mount

[Service]
ExecStart=/bin/mount %h/remote/Dropbox
ExecStop=/bin/umount %h/remote/Dropbox
RemainAfterExit=yes

[Install]
WantedBy=default.target

Now lets enable and start the service. Slashes must be replaced by dashes if used as systemd parameters.

systemctl --user enable mountdropbox.service
systemctl --user start mountdropbox.service

After executing the commands above the service will be started (i.e., the Dropbox folder will be mounted) automatically upon user login.

Note for Ubuntu 18.04 or newer: for some reason systemd seems to “forget” the user service after reboot. Please check the comments of this blog post for a solution to this.

We also make sure that we own the mounted folder:

sudo chown <username>:<username> remote/Dropbox

Step 5: tell Dropbox to move your files to the new location

You can use the Dropbox GUI to move the Dropbox folder location to the newly created one.

The way how Dropbox detects the file system in use is a bit awkward as it does not let you choose the mount point itself as Dropbox folder location, instead you need to sync to a subfolder. So if you mount point is remote/Dropbox you need to sync to remote/Dropbox/<username> or something like that as Dropbox does not believe that the mount point is an ext4 file system.

Optional: grow the Dropbox image if you need more space

On the command line run the following commands (change 15G to something appropriate for your needs, but never change it to a lower size than your existing image as this cuts of the image which may lead to data loss):

dropbox stop
systemctl --user stop mountdropbox.service
truncate -s 15G remote/.Dropbox.ext4
fsck.ext4 -f remote/.Dropbox.ext4
resize2fs remote/.Dropbox.ext4
systemctl --user start mountdropbox.service
dropbox start

Fixing IntelliJ IDEA font glitch on Ubuntu

This post is mostly for myself to remember what changes to make in IntelliJ IDEA. The problem is that fonts are ugly and not antialized in stock-IDEA. In my case it affects IDEA 13 and 13.1 so far.

The problem is still not completely solved, the fonts are looking better, but still not as good as in Eclipse. Don’t ask me why, I just don’t know.

After googling for a good while I came up with the following additions that improve how fonts are rendered:

In idea64.vmoptions add the following lines:

-Dawt.useSystemAAFontSettings=on
-Dswing.aatext=true
-Dsun.java2d.xrender=true

At the very end of idea.sh exchange the following line

eval "$JDK/bin/java" $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME "$@"

for

eval "/usr/lib/jvm/jdk-7-oracle-x64/bin/java" $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME "$@"

This is to make sure that Oracles JDK is used as there seems to be a problem with OpenJDK and fonts in IDEA (even though this works in Eclipse). Make sure you use the path that is correct for your JDK.

While at it I also increased the default memory settings and my complete idea64.vmoptions looks like this now:

-server
-Xms256m
-Xmx2048m
-XX:MaxPermSize=512m
-XX:ReservedCodeCacheSize=256m
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-XX:+UseCodeCacheFlushing
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-Dawt.useSystemAAFontSettings=on
-Dswing.aatext=true
-Dsun.java2d.xrender=true

Recap of OKFestival sustainability stream and recorded sessions

The sustainability stream (in which I was involved) published a detailed recap of the OKFestival, don’t miss this!

At the same time, videos of most of the sessions have been added to the web page of the streams. Look out for the keyword “video documentation” that have been added to the original description of the sustainability stream.

Green Hackathon at OKFestival in Helsinki

And so it was time again! We are going to run a two-days Green Hackathon at the OKFestival in Helsinki. The conference will last for the whole week with the Green Hackathon happening on September 19 and 20. I will not write so much more in this blog, I link instead to other sites where event information and press releases have been published.

You do not need a ticket for the OKFestival in order to participate in the Green Hackathon, however, you have to sign up at http://lanyrd.com/2012/okfestival-green-hackathon/ to get your name onto the guest list.

See you in Helsinki!

Links

Green Hackathon at OKFestival
Post by OKFN
Post by EIT ICT Labs
Post by CESC

The oldest Swedish university – a fact check with SPARQL and DBpedia

This morning I started to read a newspaper article about Gotland University College being merged into Uppsala University, but I stopped after the second sentence which basically stated that Uppsala University was the oldest university in Sweden. I remembered a discussion between some friends of mine years ago in which they disagreed on which Swedish university was established first. I don’t quite remember which universities they talked about, but I think it was Lund and Uppsala.

Not remembering to which conclusion they came I just wanted to do a quick fact check. The easiest and probably least time-consuming approach would have been to just click through a couple of Wikipedia pages about Swedish universities or just look at the Wikipedia list of universities in Sweden which also happens to include the dates of establishment.

Well, googling and clicking on a few links is neither the most exciting thing to do on an average Thursday morning nor does it solve a general problem, so I decided to get an answer with a SPARQL query against DBpedia Live. As an absolute minimum I needed the names of all Swedish universities and their date of establishment. A quick check at the DBpedia page about Uppsala University revealed which properties I possibly can use, so I drafted a first query:

SELECT DISTINCT ?name ?established
WHERE {
  [] dbpprop:country dbpedia:Sweden;
     rdf:type dbpedia-owl:University;
     dbpprop:nativeName ?name;
     dbpprop:established ?established.
}
ORDER BY ?established
LIMIT 50

(You can use prefix.cc to expand the namespaces in the query above.)

Nice, this worked! But was Umeå University really established in the year 17? Let’s check what went wrong by taking a look at the DBpedia page of Umeå University. There are two values for “established”, one as xsd:integer (the wrong one), the other one is an xsd:date (and correct). All other universities use integers. Well, there is not so much I can do about this, except for perhaps falling back to the dbpedia-owl:foundingDate property (which is given for Umeå but no other university).

What about university colleges? They are not included in the query result because they are not of the University type. Let’s see how we can include those: perhaps rdf:type yago:UniversitiesAndCollegesInSweden? I dislike several things about this: universities and colleges are summarized in the same property, this should better be a handled by a UNION in the query itself. The country is included too, but I already have a property stating the country in the query. The same applies to rdf:type http://schema.org/CollegeOrUniversity (even though is quite interesting to see that schema.org properties are being used).

So let’s give rdf:type dbpedia-owl:EducationalInstitution a try, this should cover all organizations we want (given there is sufficient information in Wikipedia and the transition into DBpedia went well). It also seems that sometimes we get multiple values for the number of students. As a dirty hack we just average the number of students with the avg() function in the first line of the query. If we also add some other information such as website,  amount of students, and a fallback to the literal "Sweden" (in addition to the resource dbpedia:Sweden) then we end up with the following query:

SELECT DISTINCT str(?name) as ?name, ?url, xsd:integer(?established) as ?established, avg(?students) as ?students
WHERE {
  { ?s dbpprop:country dbpedia:Sweden } UNION { ?s dbpprop:country "Sweden"@en }
  ?s dbpprop:nativeName ?name;
     dbpprop:established ?established;
     rdf:type dbpedia-owl:EducationalInstitution.
  OPTIONAL { ?s dbpedia-owl:numberOfStudents ?students }
  OPTIONAL { ?s foaf:homepage ?url }
  FILTER (datatype(?established) != xsd:integer && ?established > 500)
}
ORDER BY ?established
LIMIT 100

Done! You can take a look at the result yourself. (Side note: I used the datatype functions to make the output more pleasant for human eyes.)

Let’s double-check with the list of Swedish universities on Wikipedia to see whether we got the same result… there seems to be a difference between “established as a university” and “first establishment” which is not reflected by the data in DBpedia. Checking the information about Lund University tells us:

“The university […] traces its roots back to 1425 […] making it the oldest institution of higher education in Scandinavia followed by studium generales in Uppsala in 1477 and Copenhagen in 1479. The current university was founded in 1666.”

So, depending on your definition of “establishment” the winner is either Uppsala or Lund. You decide…

We saw that SPARQL queries on DBpedia are powerful and can be used for checking some simple facts, but it takes some attempts to build a query that returns the results we need and want. This is mostly caused by the heterogeneity of the queried data (e.g. some deviating properties, see the date of establishment vs founding date), even though it originates from the same repository.

One could now of course continue, grab sgvizler and try to visualize an eventual correlation between date of establishment and number of students on a scatter chart…

New release of Java 1.5

Sun released Java 1.5.0_17 today. This release fixes (among other things) the regression bug of Java 1.5.0_16 which made it impossible to view and edit metadata in Conzilla. I wrote about this in a previous blog post.

Generally I recommend to use Java 1.6, but if you have to use 1.5 for some reason you can get the new version directly from Sun.