I've got a laptop with a SSD and HDD. Right now, everything is on the SSD but as I'm starting to need some more place I wanted to move one of my directory to the HDD.

All my heavy files are under /data. So I want to mount /data on my HDD. The thing bothering me is that my linux is encrypted, so I'm not sure how I could move all those files on my HDD without wrecking everything.

Here are some informations :

/0/1/0.0.0     /dev/sda    disk           1TB HGST HTS721010A9
/0/1/0.0.0/1   /dev/sda1   volume         931GiB Linux filesystem partition


lrwxrwxrwx. 1 root root 10 Jul 19 09:06 d4a8fa1c-04ff-4597-a75d-81e827b380aa -> ../../sda1


$ lsblk

sda                                                                                       8:0    0 931.5G  0 disk  
└─sda1                                                                                    8:1    0 931.5G  0 part  
  └─luks-d4a8fa1c-04ff-4597-a75d-81e827b380aa                                           253:2    0 931.5G  0 crypt 
nvme0n1                                                                                 259:0    0 238.5G  0 disk  
├─nvme0n1p3                                                                             259:3    0   228G  0 part  
│ └─luks-2ee64f3a-72ee-453a-aa17-e33d557968fa                                           253:0    0   228G  0 crypt /
├─nvme0n1p1                                                                             259:1    0   500M  0 part  /boot
└─nvme0n1p2                                                                             259:2    0    10G  0 part  
  └─luks-69cc9d3c-1b66-4491-b6bf-58456df7d4ac                                           253:1    0    10G  0 crypt [SWAP]

- $ vi /etc/fstab

/dev/mapper/luks-2ee64f3a-72ee-453a-aa17-e33d557968fa /                       ext4    defaults,x-systemd.device-timeout=0,discard,noatime,nodiratime 1 1
UUID=453db572-fd28-4fa6-aa3d-1e97890a2977 /boot                   ext4    defaults        1 2
#/dev/mapper/luks-d4a8fa1c-04ff-4597-a75d-81e827b380aa /data                   ext4    defaults,x-systemd.device-timeout=0 1 2
/dev/mapper/luks-69cc9d3c-1b66-4491-b6bf-58456df7d4ac swap                    swap    defaults,x-systemd.device-timeout=0 0 0

So as you see it, I thought about adding /data in /etc/fstab to the right disk, but I guess I still have to move things before ?


Yes, you will have to move the data in addition to updating /etc/fstab. The most reliable option is to set up the new partition with a filesystem (on top of the LUKS volume), and then use something along the lines of:

rsync -vahogSHAXOP /data/ /new-data/

To copy things over. Rsync with those options will copy pretty much everything except the block layout and inode numbers (neither of which should matter for any modern software), and will give you a reasonably nice progress display. Copying like this also has the advantage that it will functionally defragment the files, and will not delete the files in the source directory (so you can make sure the new setup works before committing completely to it).

  • Don't use rsync to copy entire partitions, it will run out of memory and leave a mess behind. Don't use tar / pax either, since it has a limitation on the maximum length of paths. Don't use cp or cpio, since they can't handle hardlinks. Don't use dd either, unless you actually know what you're doing. Use dump / restore, they work reliably in the vast majority of cases. Jul 19 '17 at 14:59
  • 1
    He said he's moving things out of a folder on one partition onto another partition, rsync is perfect for that, dump and restore are overly complicated for such a situation. Also, unless you've got a tiny system, rsync will have zero issues with memory usage. Jul 19 '17 at 15:02
  • dump and restore are overly complicated for such a situation - dump -0af - /some/dir | (cd /some/other/dir; restore -rf -). unless you've got a tiny system, rsync will have zero issues with memory usage - Not if you want to handle hardlinks. You don't have to take my word for it though, try it yourself. Jul 19 '17 at 15:18
  • I do this type of thing regularly with rsync, including handling of hardlinks. Most recent example involved copying approximately 2TB of data including 10k+ hardlinks on a system with only 4GB of RAM, it works just fine. Jul 19 '17 at 15:22
  • Well, then either you have unusually good luck, or I have unusually bad luck with rsync. shrug Jul 19 '17 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.