LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Moving /var from a mirror to another disk (https://www.linuxquestions.org/questions/linux-newbie-8/moving-var-from-a-mirror-to-another-disk-4175477229/)

vasis 09-15-2013 03:05 PM

Moving /var from a mirror to another disk
 
Hello All,

I looked around a lot before posting here and I really hope you will be able to give me some advice on how to achieve this... (important: please do not assume I know, because chances are I don't as I am relatively new to the Linux world).

OS:
Debian wheezy

My setup:
2x8G USB2 mirrored (this is for the OS)
2x3T SATA disks mirrored (this is for my storage)

/proc/mdstat:
Personalities : [raid1]
md1 : active raid1 sda[0] sdb[1]
2930135360 blocks super 1.2 [2/2] [UU]

md0 : active raid1 sdd1[0] sdc1[1]
7514048 blocks super 1.2 [2/2] [UU]

/etc/fstab:
# / was on /dev/md0 during installation
UUID=1ff6b579-38f0-455c-a9c8-b486025adfd8 / ext4 discard,noatime,errors=remount-ro 0 1
/dev/sdc1 /media/usb0 auto rw,user,noauto 0 0
/dev/sdc2 /media/usb1 auto rw,user,noauto 0 0
/dev/sdd1 /media/usb2 auto rw,user,noauto 0 0
/dev/sde1 /media/usb3 auto rw,user,noauto 0 0

df -h:
Filesystem Size Used Avail Use% Mounted on
rootfs 7.1G 845M 5.9G 13% /
udev 10M 0 10M 0% /dev
tmpfs 387M 260K 386M 1% /run
/dev/disk/by-uuid/1ff6b579-38f0-455c-a9c8-b486025adfd8 7.1G 845M 5.9G 13% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 773M 0 773M 0% /run/shm
/dev/md1 2.7T 2.4G 2.6T 1% /media/md1_storage

Since I boot from USBs, I would like to move the /var to another disk. I don't know how to do this properly since /var is used at all times. Any ideas on how to achieve this? Please let me know if you need more information.

Thanks in advance!

jpollard 09-15-2013 04:20 PM

I believe the following will work, note: the shutdown logs will be in the old directory, not the new.

1. initialize the new partition (or the whole disk if you want) with mkfs
2. mount the new partition in /mnt - for the purpose below, create a directory var in /mnt and mount it as /mnt/var. The contents will be empty.
3. cp --preserve=all /var /mnt/var
This will copy all current files and security labels that may be in use.
4. mv /var /var.old
This will preserve the existing directory (which will have open files)
5. mkdir /var
Make sure the new directory has the same permissions/labels as /var.old
6. Change/add the mount for the new filesystem (currently mounted on /mnt/var) to /etc/fstab to allow the next boot to use it.
7. reboot.

IF everything works as you expect, you can then do "rm -rf /var.old", but do it ONLY after rebooting.

If something didn't work, you can still boot into single user mode (or from a rescue disk) and rename the /var.old back to /var (deleting the directory /var) and reboot again.

vasis 09-19-2013 01:20 PM

Thanks for the advice jpollard,

Sorry for the delay, I didn't have the time to test it earlier. I was looking for a plan on how to do this actually and your response provides me with one. That worked fine. Thank you very much! Much appreciated!


All times are GMT -5. The time now is 02:53 PM.