Hello,
I am trying to move my volatile.img files to another location. There are two (three) reasons for it:
1. Some additional secrecy; the filesystem is encrypted by a password from /dev/random, so no one can read the volatile.img files after reboot.
2. Performance (+ reduces wear when used with SSD): The filesystem for is tuned for performance at the cost of consistency when computer is forcibly turned off. This is undesirable for main FS, but OK for a dedicated filesystem for this purpose.
I have prepared such a temporary filesystem to be mounted under /largetmp. (Well, I might change it just to /tmp.) There is nothing I have problem with, so I'll share the details below.
Now, I would like to move all the volatile imgs there. I have grepped for volatile.img in Qubes sources. The easiest (though somewhat hacky) way to do this seems to be adding the following line before truncate command to /usr/lib/qubes/prepare-volatile-image.sh:
ln -s "/largetmp/volatile-$(printf %s "$FILENAME" | base64 -w0 | sed 's#/#:#g')" "$FILENAME"
HOWEVER, there seems to be a potential security issue with that. When one looks at /usr/libexec/qubes/udev-block-add-change, it seems to blacklist those volatile.img files in order to prevent parsing the file by dom0's kernel (partition table etc.). I obviously could modify that file in order to exclude all /largetmp/volatile-* files (and maybe I could even test that), but I am not sure if this can be done securely without being merged by Qubes. If this is not merged by Qubes and some dom0 update is applied, it may revert the udev script change without reverting the /qubes/prepare-volatile-image.sh file, which is obviously some risk.
Is there a better (secure) way to do this? Is there some chance of implementing this by Qubes in future?Now, I'll include my config for /largetmp. It is basically an implementation of
http://shnatsel.blogspot.cz/2012/05/tmpfs-for-real-life-write-buffering.html with encryption by a random key. The partition is ext4 on dm-crypt (plain) on LVM.
1. LVM: The LVM is optional, but I recommend this for MBR partitioning table. The LVM basically works as a stable way for referring the partition for dm-crypt. On GPT, they AFAIK have stable UUIDs in the partition table. On MBR, they may have a stable UUID inside the partition only, which is not usable in this case (for plain dm-crypt). Having a stable identifier is very important for safety: You destroy all data of the referred partition on every boot. If you use unstable identifier like /dev/sdaX and the identifier is changed (e.g. you modify your partitions or swap HDD<->SSD*), it may accidentally match another partition and destroy all its data. So, this is my reason for using LVM. You may use GPT instead.**
My LVM partition is pretty simple. It is a volume group (VG) that consists of one physical volume (PV). It may contain just one or two logical volumes (LVs). In my case, the second LV is used for swap.
2. dm-crypt with ext4: I added following line to /etc/crypttab:
dom0-largetmp /dev/<PV name>/<encrypted largetmp LV name> /dev/random tmp,cipher=aes-cbc-essiv:sha256
This causes an empty ext4 filesystem (notice the tmp option) to be created on /dev/<PV name>/<encrypted largetmp LV name> encrypted by a random key. I've verified that default options for the filesystem are pretty decent for this purpose (e.g. no metadata journal and no superblock backups). It seems it does not initialize the inode table lazily, which might be desirable for reducing boot time.
After adding the line to crypttab, you will probably want to regenerate daemons and restart the cryptsetup:
$ sudo /usr/lib/systemd/system-generators/systemd-cryptsetup-generator
$ sudo systemctl daemon-reload
$ sudo systemctl restart cryptsetup.target
3. fstab: This is pretty easy, but you might want to tune some parameters for performance. For example, commit=36000 (i.e. 10 hours) will make it a bit like tmpfs with HDD fallback. Some options might be redundant, but they should do no harm. There is my /etc/fstab entry:
/dev/mapper/dom0-largetmp /largetmp ext4 defaults,barrier=0,delalloc,data=writeback,commit=36000,noatime,nodiratime,norecovery,noacl,nouser_xattr,noauto_da_alloc,noinit_itable 0 0
You can also see some cryttab/fstab lines (with bonus – cryptswap) there:
https://gist.github.com/v6ak/d5d49375d59cfae8e455Regards,
Vít Šesták 'v6ak'
*) Swapping SSD <-> HDD might sound unlikely, but even that might have a good reason: My BIOS does not allow booting from SSD when the SSD is a second drive. (No, choosing CD boot does not the job.) However, removing the first drive (originally HDD) requires much more disassembling of my laptop than removing the second drive (originally optical drive, later SSD). So, I didn't have the swap done until recently. (I recently disassembled the laptop for another reason.)
**) My BIOS prevented me from using GPT, because it is such a crap and can't boot from that. This was my only reason for choosing LVM over GPT.