0

I need to move my /var (dev/sdc1) back to the / (dev/sda2) from a different file system. I've resized the / partition and want to move /var back to / partition and resize /dev/sdc1 filesystem to mount another directory /data002

Currently, df -h and lsblk details Can someone guide me on this please.

Sam89
  • 11
  • 3
  • this could help https://unix.stackexchange.com/questions/88256/how-to-move-to-a-different-drive-or-partition – Talal Al-Khalifa Mar 16 '20 at 18:40
  • Your request is a little unclear - specifically do the contents if /var exist in the new location? I am pretty sure a key part of what you are looking for is describing the mapping of the block device in /etc/fstab - but this may or may not be the full story. – davidgo Mar 16 '20 at 19:11
  • @davidgo Initially, due to limited space in / partition I moved my /var directory and mounted to /dev/sdc1. Now I have resized the / partition and I need to use /dev/sdc1 for another directory, so I want to move /var directory back to / and unmount it from /dev/sdc1. – Sam89 Mar 16 '20 at 19:15
  • (As you are new to this, back up first) Looking at your link, I suspect you should use a boot disk, mount /dev/sda1 and /dev/sdc1. Copy the contents if /dev/sdc1 to /dev/sda1::/var and then modify /dev/sda1:/etc/fstab and comment out the /var line. Reboot. – davidgo Mar 16 '20 at 19:16
  • (Also, for future reference, if you land up rebuilding this system, use LVM - LVM abstracts disks from volumes and makes reallocating resources easier) – davidgo Mar 16 '20 at 19:19
  • @davidgo, Is this the correct way to do it: mkdir /var_new mv /var/* /var_new/ umount -fl /var mv /var_new /var Remove /var from fstab – Sam89 Mar 16 '20 at 19:22
  • That looks about right. (Not sure about forcing unmounts). Also, I would be inclined to copy rather then move /var (and delete afterwards) - that way if it turns to custard you can revert back. – davidgo Mar 16 '20 at 19:25
  • @davidgo when I try to umount the /var drive from /dev/sdc1 I get the error stating the resource is busy. – Sam89 Mar 17 '20 at 01:03
  • "lsof -D /var" might tell you what files are open and give you a clue what process needs to be stopped. Otherwise do it from a USB booted session where nothing is mounted. – davidgo Mar 17 '20 at 02:14

1 Answers1

0

I will suggest two options :

1- No downtime is tolerated (Use it at your own risk) :

  • Issue the following commands :

mkdir /vartmp
rsync -aqxP /var/* /vartmp
  • Force umounting of /var by :

umount -f /var (force umount)
        OR
umount -l /var (lazy umount)
  • Rename your directories :

mv /var /varbackup (keep your old /var in case of you encounter an issue)
mv /vartmp /var
  • Edit /etc/fstab :

vi /etc/fstab (Delete the line containing '/dev/sdc1 /var')

2- Downtime is tolerated, make sure you have access to the server console directly because network will be down in single user mode and note that /var will not be mounted also :

SYSTEM V based Debian:

  • Reboot the server

  • Choose you kernel and then press e to edit the grub entry.

  • Append init=/bin/bash to the end of the grub line which begins with linux.

  • Now press ctrl-x or F10 to boot into single user mode.

  • Enter the following commands :


mkdir /vartmp
rsync -aqxP /var/* /vartmp
mv /var /varbackup (keep your old /var in case of you encounter an issue)
mv /vartmp /var
vi /etc/fstab (Delete the line containing '/dev/sdc1 /var')
reboot

SYSTEMD based Debian :

systemctl set-default rescue.target
reboot 
mkdir /vartmp
rsync -aqxP /var/* /vartmp
mv /var /varbackup (keep your old /var in case of you encounter an issue)
mv /vartmp /var
vi /etc/fstab (Delete the line containing '/dev/sdc1 /var')
systemctl set-default <graphical.target (OR) multi-user.target>
reboot

P.S : Try to use LVMs in future they are flexible and can deal more efficiently with this kind of situation using just vgsplit & pvmove OR using lvm mirroring & lvm mirror discarding

Reda Salih
  • 231
  • 2
  • 7