swaping mount points and preserving data

Posted on 2006-05-25
Last Modified: 2013-12-16
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.
Question by:bishma
    LVL 38

    Expert Comment

    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                   .....
    /dev/hdc1         /var/lib/mysql         .....

    mount /var/lib/mysql

    Author Comment

    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.
    LVL 38

    Accepted Solution

    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                   .....
    /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

    Author Comment

    Worked perfectly and was exactly what I was looking for. Thank you for your help wesly_chen.
    LVL 24

    Expert Comment


    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.
    LVL 38

    Expert Comment

    Thanks slyong for the correction. My brain didn't work well at that time.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now