1

At work, we have an iMac (running OS X) that shares a partitioned hard drive over the network. I'd like to back up to my partition from my Linux machine. I've attempted connecting via cifs, then attempted to back up using backintime onto an encfs-encrypted volume. This throws up a whole lot of errors, and I assume that it is because cifs is unhappy with hard-links and other unix wizardry.

I seem to remember on OS X that you can create monolithic, encrypted disk images that you could then mount as a "local" (and hence file-system–agnostic) volume. This seems ideal. Hence, I'd connect to the remote volume via cifs, then "locally" mount the encrypted volume as ext4. Is there an equivalent in Linux?

Sparhawk
  • 19,561
  • 18
  • 86
  • 152

1 Answers1

4

Would be strange of that was possible in OS X but not with Linux. It's exactly the same:

cd /cifs/dir
dd if=/dev/zero of=encbackup.img bs=1M count=100 # 100 MiB size
sudo losetup /dev/loop0 /cifs/dir/encbackup.img # assuming loop0 is free
sudo cryptsetup luksFormat /dev/loop0
sudo cryptsetup luksOpen /dev/loop0 cr_cifs_backup
sudo mke2fs -j /dev/mapper/cr_cifs_backup
sudo mount -t ext3 /dev/mapper/cr_cifs_backup /where/ever

It probably makes sense from a performance perspective to create a second (much smaller) image locally (non-encrypted) and put the journal there (see man tune2fs, options -j and -J).

Edit 1:

The existing device is mounted the same way (just leaving out dd, luksFormat, and mke2fs):

sudo losetup /dev/loop0 /cifs/dir/encbackup.img # assuming loop0 is free
sudo cryptsetup luksOpen /dev/loop0 cr_cifs_backup
sudo mount -t ext3 /dev/mapper/cr_cifs_backup /where/ever

Edit 2:

To unmount:

sudo umount /where/ever
sudo cryptsetup luksClose cr_cifs_backup
sudo losetup -d /dev/loop0
Sparhawk
  • 19,561
  • 18
  • 86
  • 152
Hauke Laging
  • 88,146
  • 18
  • 125
  • 174
  • Thanks. I'll give it a go in the next few days and accept if it works. I think I understand most of it, except the losetup part. What do I need to do to check if loop0 is free? – Sparhawk May 19 '13 at 12:06
  • @Sparhawk `losetup -a` gives you all used loop devices. `losetup /dev/loop` tells you whether loop0 is free. You can use `losetup --find` to get a free one. – Hauke Laging May 19 '13 at 18:42
  • Okay, so I got up to `sudo cryptsetup luksOpen /dev/loop0 cr_cifs_backup` and was told `Device /dev/loop0 is not a valid LUKS device.` – Sparhawk May 23 '13 at 01:24
  • @Sparhawk That is very strange if the `luksFormat` command before did not return an error. You can also try `isLuks` and `luksDump` on the device. – Hauke Laging May 23 '13 at 02:39
  • 2
    Sorry, my (stupid) mistake. `luksFormat` asked me to confirm with "uppercase yes", and I missed the "uppercase". I might file a bug report to make it clearer with "uppercase YES", though. :p – Sparhawk May 23 '13 at 04:08
  • @Sparhawk If the suggestion works for you now then you may (upvote and) accept it to "close" this question... – Hauke Laging May 23 '13 at 05:13
  • Sorry, I made some errors and accidentally disconnected from the server, so I'm starting again from scratch. (I'm making a ~300 GB volume, so it's a bit slow.) I'll certainly accept the answer once it works. (Although I'll upvote it now :-) Thank you for your help so far. – Sparhawk May 23 '13 at 05:17
  • Also, I have two other questions. Is it possible to make the file system ext4? Is that as simple as changing the mount argument from `ext3` to `ext4`? Also, which commands should I use to mount the volume after I've set it up initially? – Sparhawk May 23 '13 at 05:33
  • @Sparhawk That's a completely different question and most probably answered here elsewhere in detail. Short version: You don't get (all) the ext4 advantages when remounting ext3 as ext4. If you turn on the ext4 features then the volume cannot be mounted as ext3 any more. Some features affect newly created files only. Thus if you create a file system anyway and there are no good reasons to stay with ext3 then create it as ext4. – Hauke Laging May 23 '13 at 05:47
  • Okay, thanks. I was just unsure about backing up my ext4 drive to an ext3 volume. – Sparhawk May 23 '13 at 05:54
  • @Sparhawk Your don't lose information when backing up ext4 to ext3; most ext4 advantages are not visible to the VFS. But ext3 is slower. Problems arise in extreme situations only: If you have files or directories which exceed the ext3 limits (file size / number of subdirectories). – Hauke Laging May 23 '13 at 05:58
  • Thanks again. (Also, which commands should I use to mount the volume after I've set it up initially?) – Sparhawk May 23 '13 at 06:11
  • @Sparhawk I am not sure whether I understand the question correctly as I have already given such a command (the "normal" one without any fancy stuff) in my answer. – Hauke Laging May 23 '13 at 06:31
  • Sorry, I think I'm confused now. I'm not sure what you mean by "normal" one. I'll rephrase my question though… I've followed the commands listed, which created and mounted an encrypted volume. I'll go home now, and turn off the computer. When I come back, how do I mount the volume again? (e.g. I presume I won't `dd` again.) – Sparhawk May 23 '13 at 06:34
  • @Sparhawk See my edit. – Hauke Laging May 23 '13 at 10:12