Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Successful hard drive replacement on a laptop
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
qanuta
n00b
n00b


Joined: 04 Apr 2003
Posts: 43
Location: NJ, USA

PostPosted: Sat Oct 11, 2003 3:43 pm    Post subject: Successful hard drive replacement on a laptop Reply with quote

Last night & this morning I successfully replaced the aging (3-4 yrs old) hard drive on my notebook with a new drive. The old one had begun to make "clunking" noises intermittently, and while it still functioned perfectly fine, it was a little disconcerting to hear a drive make those noises. Assuming it was on its way to hard drive heaven, I decided to replace it. Below are the steps that I took, posted in the hope that they might help someone else who wants to replace a notebook hard drive.

Step 1. Prepare a way to transfer the data from your old drive to the new one. With a desktop, this is pretty easy -- you would just put the new drive in alsongside the old, and copy away. But with a notebook, it's a little more difficult -- there's only room for one drive at a time. When I purchased my new 40 GB hard drive (might as well upgrade fom the original 10GB drive while I'm at it!), I also purchased an external mount for a notebook hard drive that plugs into the USB port. The new drive was about $150 and the external drive enclosure was about $50 -- I ordered both from drivesolutions.com, who seem to have a wide selection, actually have items in stock, and have a web page that doesn't suck.

To use the external USB drive converter, you need to make sure USB is compiled into the kernel. You'll need USB, usb-storage modules, and you'll also need to have SCSI and SCSI hard drives enabled since USB drives are always mapped in as SCSI for some reason.

Step 2. Connect the drive and partition it. I hooked up the new drive into the converter, and plugged it into the USB port. It wasn't completely happy at first. As it turns out, the laptop couldn't supply enough power to run the external drive fully. The enclosure had a socket in the back for an external 5V power supply, so I gave it power via the socket, and linux immediately recognized it. You can tell by looking in /proc/bus/usb or alternatively use the easier lsusb function.

The external drive shows up as a SCSI drive, and since it is my only one, it appears as /dev/sda. Using "fdisk /dev/sda", I partitioned the new drive. I was sure to leave an extra partition at the beginning of the drive for the notebook's suspend data (partition type a0 for my HP N5190). I really followed the directions as outlined in the Gentoo installation manual -- a boot partition, a swap partition, and a root partition, the latter being the bulk of the disk. Make sure you set the /boot partition as bootable in the partition table.

Step 3. Copy over the data. First, you need to make the filesystems on each of the partitions. I used mke2fs for the boot partition, mkswap for the swap partition, and mkreiserfs for the root partition. A typical command would look like "mke2fs /dev/sda2" or "mkswap /dev/sda3".

Once you have your filesystem, you can mount it and copy over data with tar. Here is what I did for /boot -- you would have to repeat for each partition you want to copy over.

Mount the original /boot partition, which is not usually mounted by default on my system
Code:
mount /boot

Create a place to mount the new /boot, and mount it there.
Code:
mkdir /newboot
mount /dev/sda2 /newboot

Copy data over with tar -- make sure you use the -p option to preserve file attributes.
Code:
(cd /boot && tar -cpf - .) | (cd /newboot && tar -xpvf -)

All done -- unmount the drive and go on to the next partition
Code:
umount /newboot


Step 4. Make changes as necessary to the new /etc/fstab. I decided with my new hard drive to use a slightly different partitioning scheme than on my old. Therefore, it was necessary to go into the new disk's root partition and edit /etc/fstab. Now although this drive is currently available as /dev/sda, you will want to use /dev/hda names in fstab for it. This is becuase once we put it into the laptop, it will become an IDE drive and not a SCSI/USB drive.

Step 5. Fix up the bootloader. I use grub for my bootloader. I'm certainly not an expert with it -- I pretty much only know what is in the Gentoo installation guide. According to the grub help, in th grub numbering scheme, IDE drives come first, then SCSI drives. My machine has only the one IDE internal drive, (drive 0 in grub) and then the external IDE drive masquerading as SCSI since it's via USB (drive 1 in grub). So in grub, I want to make my /dev/sda2 the boot location. This requires the following commands:
Code:
root (hd1,1)
setup (hd1)
quit


Now, when this new drive is ultimately placed in the machine, it will know where to go at boot time. You will also need to edit /boot/grub/grub.conf (on the new drive) to reflect your new partition scheme if it has changed.

Step 6. Install the new drive. This is the part that could potentially be the most difficult depending on your skills and what information you can find on the web. I was lucky that someone had pictorially taken apart my laptop on a web page, so I could learn from them.

Step 7. Power up and cross your fingers! On my machine, everything came up perfectly on the first boot. There were a couple warnings at boot time about some tmp files that probably got carried over from the data copy, but they seemed harmless and didn't reappear on subsequent boots.

Now, no more clunking, and the extra 30GB of space is nice to have. Happy hard drive replacing!


Last edited by qanuta on Tue Oct 21, 2003 9:44 pm; edited 2 times in total
Back to top
View user's profile Send private message
hulmeman
Apprentice
Apprentice


Joined: 02 Jul 2002
Posts: 184
Location: Duchy of Lancaster, England.

PostPosted: Tue Oct 21, 2003 11:45 am    Post subject: Hmmm? Reply with quote

Great post, but I think the syntax may be wrong here:
(cd /boot && tar -cfp - .) | (cd /newboot && tar -xfpv -)
I get this error message:
root@baz3 /mnt/hdh1# (cd /boot && tar -cfp - .) | (cd /mnt/hdh1 && tar -xfpv -)
tar: pv: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: -: Cannot stat: No such file or directory
tar: ./p: file is the archive; not dumped

I can't figure out how to get it to work!
Any ideas?
Baz
Back to top
View user's profile Send private message
qanuta
n00b
n00b


Joined: 04 Apr 2003
Posts: 43
Location: NJ, USA

PostPosted: Tue Oct 21, 2003 9:40 pm    Post subject: Reply with quote

Hmmm. After a little experimentation, it seems you are correct. For some reason, it looks like the order of the arguments to tar is important. Try changing the flags on both tars so that the "f" flag is last. So, change
Code:
(cd /boot && tar -cfp - .) | (cd /mnt/hdh1 && tar -xfpv -)

to
Code:
(cd /boot && tar -cpf - .) | (cd /mnt/hdh1 && tar -xpvf -)

I echoed this fix in the original message above. Let me know how you make out--It was my hope that someone would be able to use these notes as a guide save them some grief.
Back to top
View user's profile Send private message
hulmeman
Apprentice
Apprentice


Joined: 02 Jul 2002
Posts: 184
Location: Duchy of Lancaster, England.

PostPosted: Wed Oct 22, 2003 11:25 am    Post subject: Reply with quote

Thanks for the reply, this indeed does work:
(cd /boot && tar -cpf - .) | (cd /newboot && tar -xpvf -)
But, apparently, there is a problem, in that tar can only handle ext2 partitions up to 2 GB, (4GB for reiserfs) but this does work:

# cd /newdrive
# ls /
# bin boot dev etc home lib mnt newdrive opt proc root sbin tmp usr var
# tar -c --recursion /bin > bin.tar
# tar -c --recursion /boot > boot.tar
# tar -c --recursion /dev > dev.tar
# tar -c --recursion /etc > etc.tar........................................

Omitting /proc, /mnt and /newdrive, of course.
If /usr, or any other root directory, is over 2GB, this will need to be broken up also:

# mkdir usr
# cd usr
# ls /usr
# X11R6 games......................................
# tar -c --recursion /usr/X11R6 > X11R6.tar
# tar -c --recursion /usr/games > games.tar..........................................

Then:

# cd /newdrive
# for file in `ls /newboot/*.tar`; do tar xpvf $file; done
# cd /newdrive/usr
# for file in `ls /newdrive/usr/*.tar`; do tar xpvf $file; done
# mkdir proc mnt

Et voila! Done.

There is though a simpler way to do it, boot using a gentoo live cd,
# mount /dev/hd** /mnt/gentoo/olddrive
# mount /dev/hd** /mnt/gentoo/newdrive
# cp -ax /mnt/gentoo/olddrive/* /mnt/gentoo/newdrive

The -x switch instructs cp to stay on same drive, the -a switch instucts cp to never follow symbolic links, preserve the specified attributes and copy directories recursively.
Many thanks,
Baz
Back to top
View user's profile Send private message
pilla
Bodhisattva
Bodhisattva


Joined: 07 Aug 2002
Posts: 7729
Location: Underworld

PostPosted: Wed Oct 22, 2003 12:10 pm    Post subject: Reply with quote

Moved from H&L
_________________
"I'm just very selective about the reality I choose to accept." -- Calvin
Back to top
View user's profile Send private message
Ravilj
Apprentice
Apprentice


Joined: 29 Jul 2004
Posts: 164
Location: ziig / #

PostPosted: Tue Mar 29, 2005 9:34 pm    Post subject: Reply with quote

This was really helpful in enlarging my root partition. That cp -ax /... /... was exactly what i was looking for! D:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum