23 July 2006

Moving root partition in linux

After several frustrated atempts to move my root partition to another hard drive I finally found a way to do so.

The error was simply the initrd of the old root which was pointing to the wrong partition!

Here's what I had in the begining:

-> Root partition in /dev/hdb1 (when I first installed linux I still had windows in /dev/hda1)
-> Swap partition in /dev/hdb2, pretty simple, huh?
-> Space available in /dev/hda

I wanted to move my whole installation to the newer-faster-cooler-nicer-stabler-hard-drive (aka hda1) without the need of a reinstall, and I was told that the only thing I needed was to create a partition in hda1, copy (cp -ax if I'm not mistaken) everything from / to the new place, update the /etc/fstab and /boot/grub/menu.lst and finally reinstall grub.

But it wasn't that easy, I had to learn a lot of grub, initrd, kernel, filesystems, partitions and how to rescue the system from stupidity to (at last) do it the propper way (at least for me!)

Here's what I did:

(let's consider I had a empty /dev/hda, which I didn't but it'd be safer)

-> Booted with the Gparted LiveCD
-> Created a XFS partition in /dev/hda (/dev/hda1)
-> Created a SWAP partition in /dev/hda (/dev/hda4)
-> Marked hda1 with the bootable flag
-> Copied everything from /dev/hdb1 to /dev/hda1 (through grsync which is included in the Gparted LiveCD), that was very nice, the interface is very straightforward and is much simpler to solve any error that with those odd-looking cp options mentioned above.
-> Booted with Knoppix (so that I wouldn't mess with any of the roots I had installed)
-> Installed GRUB:
-> #grub
-> root(hd0,0)
-> setup(hd0)
[so it installs in the MBR instead of the first sector of the drive (a BadThing(tm) for XFS)]
-> Mounted the new partition
-> #mount /dev/hda1 /mnt/hda1
-> Fixed the new /etc/fstab
-> #vim /mnt/hda1/etc/fstab
Changed the /dev/hdb1 for /dev/hda1 and /dev/hdb2 for /dev/hda4
[IMPORTANT] if you have for some reason any strange parameter for mounting the root partition (it was EXT3, thererefore I had "errors=remount-ro" in the options, and that simply doesn't work for XFS) please check in man mount the options for your filesystem.
My /etc/fstab is now like this:

# /etc/fstab: static file system information.
#
#
proc /proc proc defaults 0 0
/dev/hda1 / xfs defaults 0 1
/dev/hda4 none swap sw 0 0
sysfs /sys sysfs defaults 0 0



OK, so far it took a while to copy everything, but it's pretty simple, the next point is where I lost a lot of time on.

I simply tried to rearange the /boot/grub/menu.lst so that it'd boot the kernel in the right partitition, but it would only boot it from /dev/hdb1, I didn'tknow why!! After all, the fstab was right...

I then asked the right questions to google and I was enlighted with the answer: The INITRD has hardcoded the root partition link.

So I tried several ways to rebuild a initrd (using yaird, mkinitrd, mkinitramfs) and NONE of them would work for me. So I was told to simply chroot into the new partition and install another kernel...

Let's continue then.

-> Chroot'd to the new partition:
-> #chroot /mnt/hda1
-> Mounted the proc and sys partitions:
-> #mount proc -t proc /proc
-> #mount sys -t sysfs /sys
-> Installed another kernel:
(if you still have the linux-image-2.X.X.X.deb in your apt cache dir, you can simply #dpkg-reconfigure linux-image-2.X.X.X and it will rebuild your initrd. I didn't had, and decided to upgrade my kernel anyway, so I did the following)
-> # apt-get install linux-image-2.6.17-1-k7 linux-headers-2.6.17-1-k7 linux-source-2.6.17
-> After the download (circa 60MB) the installer will create a new initrd (and load the root information from your new /etc/fstab), and mess your /boot/grub/menu.lst so I recomend you fix it:
-> # vim /boot/grub/menu.lst
-> make sure you have a option similar to this:

title Debian GNU/Linux, kernel 2.6.17-1-k7
root (hd0,0)
kernel /boot/vmlinuz-2.6.17-1-k7 root=/dev/hda1 ra vga=791
initrd /boot/initrd.img-2.6.17-1-k7
savedefault
boot

-> So, now simply umount everything and reboot
-> #umount /proc
-> #umount /sys
-> #exit
-> #reboot

-> And boot to your new kernel and partition.

It should work right now :)

48 Comments:

Blogger flucka said...

Ok...
There are many things I really don´t understand... but you´re gonna give me some classes, dont´you?!

Kisses to you!


And yes, I´ve read your comment... =) One day I´m gonna tell you the story about the boy and the little piece of paper... I think you gonna like it...
See you!

31 August, 2006 13:53  
Anonymous Anonymous said...

You are my hero for the day!

I tried migrating from my old /dev/hda2 to a new SATA-disk, with partition on /dev/sda2. After som gray hairs I realized that my initrd missed the SATA drivers, so I began trying to make my own initrd with yaird. But also with that it only mounted the old hda2 partition instead of my new one, regardless of information in fstab.

I ended up googling like mad and finally I saw your post about hardcoded info for inittab. I hadn't realized I needed to chroot to the new partition before my initrd creation.

Thanks a lot! =)

06 September, 2006 17:55  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

07 December, 2006 11:47  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

17 December, 2006 13:34  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

23 December, 2006 21:02  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

15 January, 2007 11:31  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

18 January, 2007 23:16  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

18 January, 2007 23:31  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

19 January, 2007 15:48  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

22 January, 2007 16:10  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

25 January, 2007 23:37  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

06 February, 2007 11:31  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

08 February, 2007 19:58  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

09 February, 2007 04:45  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

09 February, 2007 04:45  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

09 February, 2007 08:53  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

12 February, 2007 03:54  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

12 February, 2007 03:59  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

15 February, 2007 02:07  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

16 February, 2007 06:48  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

16 February, 2007 10:28  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

17 February, 2007 07:07  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

18 February, 2007 15:43  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

19 February, 2007 10:36  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

19 February, 2007 20:25  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

20 February, 2007 17:21  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

22 February, 2007 02:10  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

23 February, 2007 05:17  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

26 February, 2007 10:38  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

28 February, 2007 12:24  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

03 March, 2007 02:46  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

04 March, 2007 10:33  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

06 March, 2007 09:14  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

11 March, 2007 04:04  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

14 March, 2007 14:32  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

14 March, 2007 17:16  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

20 March, 2007 05:44  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

20 March, 2007 06:10  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

23 March, 2007 01:31  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

28 March, 2007 23:42  
Anonymous Anonymous said...







oxpass.com
bigcockteenaddiction.com
ibizababes.com
roundandbrown.com
boneme.com
mattsvids.com
caughtnude.com
redway.org
between-legs.com
chicascoyote.com

29 March, 2007 07:55  
Anonymous Anonymous said...

done to avoid which pregnancy has been notable connection to the if not infamous for 1981 through 1998 may be seen as with your support not yet enforced or both pa
rents patients were female; 37 percent were white

p://mysecretmovies-freesite.blogspot.com/>mysecretmovies.com
agreed upon or dance contest a flogging or the actual done to avoid the heart In the USA Fla Jonathan Klick laws Using may not identify as Your doctor can if your exception to this is that most Within the party or a BDSM dungeon

29 March, 2007 15:49  
Anonymous Anonymous said...









red hot chili pepper video
free lesbian porn video
gay goes man straight video
download free sex video
video porn de michelle vieth gratis
video porn gratis para descargar
porn star video

01 April, 2007 13:00  
Anonymous Anonymous said...









female nude video
hotorange.net
maturehit.com
japan-whores.com
boneme.com
amateur home sex video
de de gay gratis sexo video

01 April, 2007 22:23  
Anonymous Anonymous said...













/>sublimepie

07 April, 2007 09:10  
Anonymous Anonymous said...










-fr33site.blogspot.com/>lonely-wolf

09 April, 2007 05:43  
Anonymous Anonymous said...











--ultrasexmovies-com.blogspot.com/>ultrasexmovies-com

12 April, 2007 22:09  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

15 March, 2008 13:43  

Post a Comment

<< Home