How to change /home directory

Posted on 2005-04-30
Last Modified: 2013-12-05
I want to add a new hard drive to my Slackware Linux machine, to serve as the /home directory.

What do I need to do to remap /home  from /dev/hda2/home to /dev/hdb/home ?

Also, after I fdisk the new hard drive, what is the command to format it.. is it simply format ?


Question by:magitek
    LVL 8

    Accepted Solution

    To change the location of home, you'll need to edit the /etc/fstab file.  Hopefully, it should be fairly intuitive.  

    To format the disk, I believe slackware has cfdisk at /sbin/cfdisk.  I would go to single user mode first.  

    Single User mode:

    init 1

    to partition and format:


    I think running cfdisk should be fairly intuitive also.

    After formating, reboot and edit the /etc/fstab file, and mount the old disk to a different location, probably by editting /etc/fstab also.  After doing this, you can run mount -a as root to execute the changes to /etc/fstab.  

    Hopefully, the lack detail of detail in the steps is ok.  You could post your /etc/fstab file if you need more detailed advice.
    LVL 10

    Assisted Solution


    you need to create your desired filesystem:
    mkfs.ext3 /dev/hdb ==> this will make ext3 filesystem
    mkfs.ext3 /dev/hdb2 ==> this will create ext3 on second primary partition

    I all depends how you partitioned your hard drive.
    another options are for example:
    mkfs         mkfs.ext2    mkfs.minix   mkfs.vfat
    mkfs.cramfs    mkfs.msdos

    then just mount this partiton in /etc/fstab

    and your done:-)


    LVL 16

    Assisted Solution

    as mentioned, use fstab to change which drive is mounted as /home

    one thing not mentioned it moving the actual data...

    I would boot into single user mode, then mount the new drive as /mnt/temp (or whatever you want), then do cp -R -a /home/* /mnt/temp/ this will recursively copy everything from /home to the new drive, and keep the ownership and permissions and everything the same.

    Next, unmount the new drive from /mnt/temp, and modify the /etc/fstab to mount the new drive as /home...reboot, and all should be well.
    LVL 12

    Expert Comment

    Install the new hard drive into the system and create a file system on it.

    Then, create a temporary mount of the new partition with something like: mount -t ext3 /dev/hdb1 /mnt

    Copy all of the current "/home" content to the new system like this:

    cp -R -r /home/* /mnt/

    Update your /etc/fstab to automatically mount /dev/hdb1 under /home

    Re-execute the "cp -R -r /home/ /mnt/" command with no users logged in. Then, rename the /home directory with something like "mv /home /home.old". Create a new /home directory with "mkdir /home". Reboot the system and check to see that /dev/hdb1 is mounted as /home. Once you're comfortable that everything is working ok, you can delete the /home directory with "rm -rf /home.old"

    This series of steps assumes the new hard drive is IDE, has only one partition, is formatted as ext3, that you want to "move" all user home directory data to the new drive, and that you have the root password. All are reasonable assumptions, but may not be exactly correct. Adjust pieces as necessary...
    LVL 16

    Expert Comment

    mburdick: 2 questions...
     - why bother executing the cp command twice? if you boot into single-user mode, then you can copy everything with no worries
     - why delete and recreate the /home directory? It's just an empty directory to mount the file system in.

    just curious if there's any reason to do so that I don't see....

    also, -R and -r are the same thing...recursive copy. I used the -a, because that preserves ownership, permissions, and timestamps

    LVL 12

    Expert Comment


    The reason you would execute twice is that the first pass will do the "heavy lifting" to make a "mostly accurate" copy. The second pass will shore things up by updating any files that changed. This basically allows you to make this kind of change on a system with active users and be able to make the diretories exact mirrors with minimal time (on the second pass).

    If you read the directions I posted a little more closely, I don't recommend "deleting and recreating the /home directory". I have the original directory get renamed (which preserves it in its entirety for the purposes of a backout plan). Once renamed, a new one must be created.

    As for the parameters for cp... my bad. I should have specified -R -u, the -u meaning to only copy those files that have changed.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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.

    If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    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…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now