[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

swaping mount points and preserving data

My project at work just got a hand-me-down debian box. Everything on it is in fine working order but I need to change the mount point of one of the drives.

The drives are set up thusly:
/dev/hdd1 - mounted on /
/dev/hdc1 - mounted on /home

In the machine's previous like it had a lot of user files so having almost half of it's storage dedicated to the home directory made sense. My needs for are different, however, and I would like to have hdc1 mounted on /var/lib/mysql since most of the machines job is handling large databases.

Can someone please walk me through, step by step, the best way to change the mount location from /home to /var/lib/mysql on hdc1 without changing any of the files in either directory? I'm pretty new to the world of *nix so I need to have it explained clearly. If it matters the machine is running Debian 3.1r1.

Thank you in advance.
0
bishma
Asked:
bishma
  • 3
  • 2
1 Solution
 
wesly_chenCommented:
First, make sure noone else login to that system.
As root,
umount /home
mkdir /var/lib/mysql

Then edit /etc/fstab and change the following line
/dev/hdc1         /home                   .....
to
/dev/hdc1         /var/lib/mysql         .....

Then
mount /var/lib/mysql
0
 
bishmaAuthor Commented:
Sorry, I forgot to mention that /home and /var/lib/mysql already has a fair amount of stuff in each them. So it I do it this way does the data get transfered? I want every thing that's in /home to end up on hda1 and everything that's in /var/lib/mysql to end up on hdc1 with their ownership and permissions intact.
0
 
wesly_chenCommented:
Ok, then first, boot your machine into single user mode.

0. As root, root
init 0

1. mv /var/lib/mysql /var/lib/mysql2; mkdir /var/lib/mysql

2. mkdir /home2; mv /home/* /home2

3. umount /home

4. Then edit /etc/fstab and change the following line
/dev/hdc1         /home                   .....
to
/dev/hdc1         /var/lib/mysql         .....

5. mount /var/lib/mysql
    mv /var/lib/mysql2/* /var/lib/mysql

6. mv /home2/* /home

7. Reboot into the normal run level
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
bishmaAuthor Commented:
Worked perfectly and was exactly what I was looking for. Thank you for your help wesly_chen.
0
 
slyongCommented:
Hi,

wesly_chen, init 0 is to halt the system.  init 1 is more like it.  I suggest you do this:

1. First move the home directory...

1.1 As root, go to Single User Mode
# init 1

1.2 Make a directory /home2 which will resides in hdd1 and copy the data from /home to /home2 (use copy so that you won't lose data)
# mkdir /home2
# cp -R /home/* /home2

1.3 Unmount the /home from hdc1 and edit the fstab to disable mounting /home on hdc1 on boot
# umount /home
edit /etc/fstab and add a # infront of the line that contains /dev/hdc1

1.4 Now move the files from /home2 back to /home and delete the /home2 directory afterwards
# mv /home2/* /home
# rmdir /home2

1.5 Time to reboot and check if you system still working properly
# init 6

If you are fine until this steps, send a tinker back into EE, we will move forward from there.  Otherwise, we have to roll back what we have done.
0
 
wesly_chenCommented:
Thanks slyong for the correction. My brain didn't work well at that time.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now