Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

moving /home to second drive

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
User avatar
llivv
Posts: 5340
Joined: 2007-02-14 18:10
Location: cold storage

Re: moving /home to second drive

#16 Post by llivv »

Revenger wrote:First, you will need to create partition dedicated to /home. (You can use gparted (gnome), kpartx (kde), fdisk + e2fstools or some other tools (if you would not like to use ext3/4 filesystem, but remember to put correct filesystem type in /etc/fstab) (console))

Do these steps as root via console.

Move old home to some other place, eg mv /home /home.old
Create empty /home directory, mkdir /home
Mount partition you intended to use as /home to its mountpoint mount /dev/sdxy /home (It may be /dev/hdxy, if using Lenny and ATA Drive).
Move all contents from /home.old to /home with mv /home.old/* /home
Add a line to /etc/fstab (nano /etc/fstab) to auto mount your new partition

Code: Select all
/dev/sdxy /home <fstype> defaults 0 0
I wasn't paying attention...
First, you will need to create partition dedicated to /home.
You already did this it's hda1
Do these steps as root via console.

Move old home to some other place, eg mv /home /home.old
Create empty /home directory, mkdir /home
Mount partition you intended to use as /home to its mountpoint

Code: Select all

mount -t ext2 /dev/hda1 /home

Move all contents from /home.old to /home with

Code: Select all

mv /home.old/* /home
Add a line to /etc/fstab (nano /etc/fstab) to auto mount your new partition

Code: Select all

   /dev/hda1  /home  ext2    defaults     1     0 
Remove empty /home.old directory

Code: Select all

rmdir /home.old
And at last do

Code: Select all

mount -a
, if there are no errors, you are good and can reboot.
In memory of Ian Ashley Murdock (1973 - 2015) founder of the Debian project.

User avatar
saulgoode
Posts: 1445
Joined: 2007-10-22 11:34
Been thanked: 4 times

Re: moving /home to second drive

#17 Post by saulgoode »

interior.ocean wrote:So is making the "new-disk" directory not making a partition called "new-disk" for the hda1? I want home partition on hda1.

So as root I should just do this:

Code: Select all

mkdir /home
mount -t ext2 /dev/hda1 /home
mv /home /new-disk
and I would have hda1 mounted and have /home partition on it?
Your wording is a little bit backwards. /home is a subdirectory on the / filesystem. You want to mount the filesystem that exists on partition /dev/hda1 onto the /home subdirectory.

This is similar to how you mount a CD-ROM. There is a subdirectory on the root filesystem called /mnt/cdrom (or perhaps /media/cdrom). That subdirectory is typically empty but when you put a CD in the drawer and mount the CD (/dev/cdrom), the filesystem on the CD will become accessible by using /mnt/cdrom. If there were already files in the /mnt/cdrom before you mounted the CD, you would not be able to access those files (until you unmounted the CD).

You could just as easily mount your hda1 partition (i.e., the filesystem that exists on hda1) onto /mnt/cdrom and access all of its files using /mnt/cdrom. Similarly, if you had a directory on your root filesystem called /pub, you could readily mount /dev/hda1 onto /pub.

The only difference with what you're doing is that you want to mount the filesystem on hda1 to the directory /home (this is called the "mount point") and /home already contains a bunch of files and subdirectories. You could actually just go ahead and mount hda1 onto /home without taking any other action but then you would not be able to access any of the files that previously exist in /home. Because you want to have those files accessible, you need to relocate them to the filesystem on /dev/hda1.

There's actually two different ways to do this (the text after the octothorpe is comments and not part of the command).

Code: Select all

mkdir /pub -p   # the -p option says to ignore the command if /pub already exists
mount /dev/hda1 /pub  # Linux will automatically detect the EXT2 filesystem
mv /home/* /pub # this will work fine since there are no hidden files in /home
umount /pub # unmount the hda1 filesystem
mount /dev/hda1 /home # mount it back to where you want it
OR (as Revenger originally described):

Code: Select all

mv /home /home.old  # basically rename the directory
mkdir /home # create a new /home (mount point)
mount /dev/hda1 /home 
mv /home.old/* /home # now the files will be copied over to the hda1 filesystem
rmdir /home.old # this directory is no longer needed
The end result is the same: all of the files and subdirectories on hda1 will be accessible through /home
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan

User avatar
llivv
Posts: 5340
Joined: 2007-02-14 18:10
Location: cold storage

Re: moving /home to second drive

#18 Post by llivv »

other instructions wrote: Introduction

Installing a second hard drive is easy if you know how. I needed to do this on my server and below is the steps I followed.
Assumptions

* I assume that you have installed the hard drive in your PC, and
* That you have rebooted your machine
* In this example our primary hard drive is located at /dev/hda and our second, new hard drive is located at /dev/hdc (replace according to your system)

Installation

The first step is to check to see that your new hard drive is installed and picked up by Debian. You do this by running the following command in a shell:

fdisk -l

This will give you an output that should look something like this:

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 9354 75135973 83 Linux
/dev/hda2 9355 9729 3012187 5 Extended
/dev/hda5 9355 9729 3012156 82 Linux swap / Solaris

Disk /dev/hdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

You can see that the 500GB disk at /dev/hdc is being picked up but there are no partitions yet for this drive.
Partitioning your new drive

Next up we need to partition our drive with the following:

cfdisk /dev/hdc

The cfdisk controller will load up and here you can create a new partition on your drive. From the menus at the bottom I selected the following:

1. New >> Primary >> Size in MB
2. Once done select Write
3. Select Quit

Your new partition has been created at /dev/hdc1
Format the new disk

Now that we have a new partition at /dev/hdc1 we need to format it for usage by the system. From a Linux shell type:

mkfs.ext3 /dev/hdc1

This will now format our partition with the ext3 filesystem which should work fine for your Debian system.
Mount your new drive

Now that we have partitioned the drive and formatted it we can now mount the drive to begin using it. From a shell run:

mkdir /new-disk
mount -t ext3 /dev/hdc1 /new-disk

The above commands create a new directory for the drive to be mounted in and then we mount the drive to this directory. To check that the drive has been mounted run the following:

ls -lsa /new-disk

You should see the following:

root@debian:/# ls -lsa /new-disk
total 24
4 drwxrwxrwt 3 root root 4096 2007-01-29 01:57 .
4 drwxr-xr-x 22 root root 4096 2007-01-29 01:58 ..
16 drwx------ 2 root root 16384 2007-01-29 01:57 lost found

Adding to fstab

Everything is now up and running however we need to add our new drive to /etc/fstab so that it will be mounted automatically when we reboot the machine.

First let's edit fstab:

vim /etc/fstab

At the end of the file add the following line:

/dev/hdc1 /new-disk ext3 defaults,errors=remount-ro 0 1

Save the file and you're done.
I'll try to condense these instructions so you can compare....
The first step is to run the following command in a shell:

Code: Select all

fdisk -l
Here's what 'fdisk -l' says:
fdisk -l wrote: Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00068a3e

Device Boot Start End Blocks Id System
/dev/sda1 * 1 31 248976 83 Linux
/dev/sda2 32 9729 77899185 8e Linux LVM

Disk /dev/hda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x2ceebebf

Device Boot Start End Blocks Id System
/dev/hda1 1 60801 488384001 83 Linux

Disk /dev/dm-0: 76.4 GB, 76470550528 bytes
255 heads, 63 sectors/track, 9297 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 3296 MB, 3296722944 bytes
255 heads, 63 sectors/track, 400 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table
Next up we need to partition our drive with the following:
already done...
Your new partition has been created at /dev/hda1
Format the new disk
already done

Edit
Now that we have partitioned the drive and formatted it we can now mount the drive to begin using it.
Instructions for moving /home to new hard disk belong here.
Now that we have partitioned the drive and formatted it (Edit: "and moved the /home directory to the new disk: ) we can now mount the (Edit: "new disk at the /home mountpoint":) and begin using it:.
From a shell run:

Code: Select all

mkdir /home

Code: Select all

mount -t ext2 /dev/hda1 /home
The above commands create a new directory for the drive to be mounted in and then we mount the drive to this directory. To check that the drive has been mounted run the following:

Code: Select all

ls -lsa /home
You should see the following:

Code: Select all

root@debian:/# ls -lsa /home
total 24
 4 drwxrwxrwt  3 root root  4096 2007-01-29 01:57 .
 4 drwxr-xr-x 22 root root  4096 2007-01-29 01:58 ..
16 drwx------  2 root root 16384 2007-01-29 01:57 lost found 
Adding to fstab:
Everything is now up and running however we need to add our new drive to /etc/fstab so that it will be mounted automatically when we reboot the machine.
First let's edit fstab:

Code: Select all

vim /etc/fstab
At the end of the file add the following line:

Code: Select all

/dev/hda1       /home            ext2    defaults,errors=remount-ro 0       1

Save the file and you're done.
Last edited by llivv on 2010-12-24 11:30, edited 1 time in total.
In memory of Ian Ashley Murdock (1973 - 2015) founder of the Debian project.

User avatar
llivv
Posts: 5340
Joined: 2007-02-14 18:10
Location: cold storage

Re: moving /home to second drive

#19 Post by llivv »

I think the main reason you got confused is because you asked to have us explain how to move home to the new disk
instead of just asking us first how to add the new disk to your system... like the other instructions describe.
So you got four different sets of directions for adding the new disk to your system
and three different sets of instructions for moving your /home/directory to that new disk....
In memory of Ian Ashley Murdock (1973 - 2015) founder of the Debian project.

interior.ocean
Posts: 22
Joined: 2010-12-18 10:40

Re: moving /home to second drive

#20 Post by interior.ocean »

You're right. Since I had so many different instructions and didn't really understand what all the commands did I just got confused. But in the end all went well and now the disk is partitioned. It didn't take this long, but I haven't had access to internet on my computer for a while I haven't been able to come here.

Thank you all for your help.

Post Reply