On Mon, Aug 04, 2003 at 03:33:17AM -0400, Kevin Mark wrote:
> On Sun, 2003-08-03 at 17:31, alex wrote:
> > Suppose Debian was installed on hda with only two partitions, swap
> > and / and you have accumulated much data in /home.
> >
> > Later, you add another hard drive, hdb, and decided to place swap
> > and a separate /home partition on this new drive while keeping / on
> > the original hda.
> >
> > How would you create new swap and /home partitions om hdb so Debian
> > would use these instead of the original /home and swap?
> Hi Alex,
> This is the basic step -- THIS IS NOT TESTED. wait for a few GURUS to
> debug.
I wouldn't call myself a GURU, but I seem to have done this sort of
thing quite a lot recently...
> edit partition table with
> cfdisk /dev/hdb
> create file system with
> mkfs.ext2 /dev/hdb1
> mount new partition with
> mount /dev/hdb1 /mnt/home2
... assuming that /mnt/home2 exists; if not, either create it or just
use /mnt
> move data to new partition with
> mv /home/* /mnt/home2
Everyone has their own recipe for this, it seems... I prefer 'cp -a',
which preserves permissions, handles special files correctly, doesn't
ignore dot files, and stuff.
cp -a /home/* /mnt/home2
> get rid of old home directory with
> rmdir /home
if you used cp -a instead of mv:
rm -rf /home (gets rid of old stuff)
mkdir /home (you still need a /home as a mount point)
Note that:
rm -rf /home/* won't get rid of those pesky dot files
rm -rf /home/.* gets rid of a little bit too much...
> modify /etc/fstab to point to new partition with
your-favourite-editor /etc/fstab
> add "/dev/hdb1 /home ext2 ?????? 1 1" (not sure what to put for ????)
Make that "/dev/hdb1 /home ext2 defaults 0 2"
> make changes active with
umount /mnt/home2
mount /home
(no need to reboot!)
> the swap is similar:
> cfdisk /dev/hdb
(if you forgot to define a swap partition the first time you ran cfdisk)
> mkswap /dev/hdb2
Turn off swap while editing swap entry in /etc/fstab:
swapoff -a
> edit /etc/fstab by changing /dev/<old-swap> to /dev/hdb2
Turn on new swap:
swapon -a
(again, no need to reboot)
cfdisk tends to moan at you to reboot to make sure that the kernel
re-reads the partition table. IME this is a "safety message" which is
given irrespective of whether it's needed; if nothing is using the
disk in question (as is the case when partitioning a brand-new disk)
the kernel re-reads the partition table quite happily. You know it has
done this by the line that appears which messes up the screen layout
and is recognisable as similar to the lines in dmesg produced by the
kernel when it reads the partition table on bootup. If you don't see
such a line, you need to reboot immediately on quitting cfdisk, before
you do anything else. You still don't need to reboot at any other point.
> > Additionally, how could you best utilize the space gained by
> > transferring data from the original /home to the new /home partition?
Define 'best' - there are loads of possible answers here... For an
ordinary home PC I'd say just leave it in / and the system will use it
as it needs it.
To make available the space used by your original swap partition,
you'll need to use parted. Assuming your old swap is on /dev/hda1 and
your / is on /dev/hda2:
parted /dev/hda
p (prints out a listing of the current partition table. You need this
information for resizing)
rm 1 (deletes /dev/hda1)
resize 2 START END (START = what p gave you for Start on /dev/hda1
END = what p gave you for End on /dev/hda2
This resizes /dev/hda2 to include the space
originally used for /dev/hda1)
q (quit)
You'll need to boot off a rescue disk, install CD or something to do
this, as it is dangerous to do it on a mounted filesystem.
--
Pigeon
Be kind to pigeons
Get my GPG key here: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x21C61F7F
Attachment:
pgpobRanB6v2S.pgp
Description: PGP signature