2

I have a system which completely resides on a (relatively small) single harddrive (/dev/sda). Now I am expecting to /var/lib/ to become populated with more and more files (due to using lxd containers) and therefore I want to shift that to another hard drive or partition which I am adding to the system.

2 methods come to mind and I'd like to get some advice from a little more experienced people which one to favor

METHOD A - symlink

  1. sudo cp -a -r /var/lib/ /mnt/new-hd/
  2. sudo mv /var/lib /var/old-lib
  3. sudo ln -s /mnt/new-hd/lib
  4. reboot

METHOD B - mounting new folder over existing /var/lib

  1. sudo mnt /dev/new-hd
  2. /mnt/temp sudo
  3. cp -a -r /var/lib/* /mnt/temp
  4. sudo umount /mnt/temp
  5. create fstab entry for /dev/new-hd (to be mounted to /var/lib)
  6. sudo mount -a

looking at it now. I'm in favor of METHOD B slightly. Any comments?

In my usecase it's about lxd, so I am also wondering whether shifting the entire /var/lib is the best choice for this or should I only move the relevant parts? Mocing the entire /var/lib has the advantage to have a structure which is very similar to the default (and therefore less custom things to be aware of)

Elder Geek
  • 35,476
  • 25
  • 95
  • 181
vrms
  • 481
  • 2
  • 11
  • 23
  • Related: http://askubuntu.com/questions/691039/adding-a-shared-host-directory-to-an-lxc-lxd-container – Elder Geek Mar 30 '17 at 23:11
  • Also related: http://askubuntu.com/questions/833267/lxd-moving-containers-snapshots-to-another-drive – Elder Geek Mar 30 '17 at 23:32
  • method c: 1. turn off power 2. conect hdd to another pc/laptop (or run any live-usb/cd version of linux) 3 . move the /var/lib to another location 4. update /etc/fstab 5. connect hdd 6. turn pc/;aptop on – psad Mar 31 '17 at 00:01

2 Answers2

1

If you were building the system from scratch, you'd probably use method B because that's the proper way to spread your file system over multiple physical devices. So if you can do B, I think thats the more-sound approach. I'd only use method A if you were planning to exchange different copies frequently, or needed one copy to exist in two places.

James
  • 1,063
  • 2
  • 13
  • 27
0

Is it really necessary to perform this operation on a running machine? Why dont you download a livecd of any linux distro, and run the system from cd/usb? You should be able to move the /var/lib to any other location without any problem. Dont forgett to copy/move file permissions.

psad
  • 121
  • 8
  • no, not necessary to do this on a running system at all. would you then just mv /var/lib to the right place? I mean 'mv', not 'cp' – vrms Mar 31 '17 at 05:34
  • yes. boot from a cd, move the /var/lib to the desired destination. The advantage of this is - if anything goes wrong (like wrong permissions) - you will still be able to reboot, start the livecd linux and correct the settings. This is rather simple operation, but sometimes there is little devil hidden in "simple task" ;) Remeber to check permision on /var/lib after you mout the additional drive. – psad Mar 31 '17 at 09:24