LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Blogs > radiodee1
User Name
Password

Notices

Rate this Entry

Moving Root To A Larger Partition

Posted 01-11-2009 at 06:22 AM by radiodee1
Updated 01-11-2009 at 06:40 AM by radiodee1

I wanted to set up the root hard drive on a 20GB partition. It was previously on a 10GB partition. The first thing I did was to make sure the 20GB partition was empty. Then my plan was to copy all important files to the new partition and change the Master Boot Record so that it pointed to the new copy. Along the way I'd have to change the /etc/fstab file along with the /boot/grub/menu.lst file.

First I switched to a terminal, by typing ctrl-alt-F1. Then I stopped GDM. This is what I typed:

Code:
# /etc/init.d/gdm stop
Then I tried ctrl-alt-F7 to see if Gnome was cancelled. I don't remember exactly what I did, but I made sure that 'root' was the only one logged in by checking the screen at ctrl-alt-F7. Then I went back to ctrl-alt-F1 as root and unmounted all the other partitions. My /home directory is on another partition, so I remmoved it. This is the command I used:

Code:
# umount /home
I used similar commands to unmount the other partitions on my system. Then I went to /mnt and made sure there was a mount point called /mnt/format. This I use for occasions exactly like this one. I mounted the new blank directory, in this case called /dev/sda9, at /mnt/format. I cd'd into /mnt/format to see if everything was as it should be. These commands would do that:

Code:
# mount /dev/sda9 /mnt/format
# cd /mnt/format
# ls
The last command 'ls' would show the contents of the newly mounted partition. In this case it was just the directory 'lost+found'. After that I started copying the file system over to the new partition. This process takes a long time. You want to make sure that you use the '-p' option with the copy command in this case. It preserves the file's 'mode, ownership, and timestamps'. This way if the file was owned by root in the original directory, it will still be owned by root in the copy. I also think the '-v' option is essential. That way you can see if the files are being copied, or if not, exactly where in the process they are being held up.

Code:
# cp -rpv / /mnt/format/
As I said, this took a long time. At one point the copy command started copying the /proc file system. I just let it go, till finally it hung on /proc/kmsg. I had to stop it. After that I had to go back to the root directory and figure out what had been copied and what hadn't. I used two commands like this, and then I compared the results.

Code:
# ls /
# ls /mnt/format/
If it looked like I had missed something, I went back and copied it to the new partition. You can list several directories at once in the 'from' portion of the copy command. I looked in the 'man cp' page for this kind of info. You just have to separate the directories with spaces. At the command line I typed something like this. As you can see I just ignored the /proc file system. I think as long as a mount point exists for it, it doesn't need any contents:

Code:
# cp -rpv /bin /usr /mnt/format/
Then I waited a long time. When I was done I edited the /mnt/format/etc/fstab file so that (1) the right partition was listed as the root partition, and (2) the partition that used to be empty and that I was now using for the new root filesystem was not mounted by accident somewhere else on the filesystem.

Then I edited the /mnt/format/boot/grub/menu.lst file so that (1) the grub root directory was listed as the new partition -- in this case the line read 'groot=(hd0,8)' since the new partition was /dev/sda9, -- and (2) the root partition on the 'kernel' line was specified as '/dev/sda9' just like it should be. Actually, I edited the menu.lst file in two places as shown below. The hash symbols are part of the file and not a command line prompts -- you're not supposed to remove them:

Code:
...
## default kernel options
# kopt=root=/dev/sda9 ro
...
and

Code:
...
## default grub root device
# groot=(hd0,8)
...
After this I had 'update-grub' apply the info to the remainder of the file. This I did by using the 'chroot' command and then the 'update-grub' command like so. In this case the hash symbols are command line prompts:

Code:
# chroot /mnt/format
# update-grub
Then I used grub to setup the Master Boot Record. I did this while I was in the chroot environment, but I don't think I had to. Grub has a command line syntax similar to a command shell like 'bash' or 'sh'. You start by invoking grub, then you type your command line arguments, then you exit by typing quit. The 'root' command below tells grub which partition grub is supposed to go on, and the 'setup' command tells grub which MBR to edit. I'm not sure if the 'root' command was neccissary in my case, but I used it anyway.

Code:
# grub
> root (hd0,8)
> setup (hd0)
> quit
#
Then you should be able to type 'exit' to get you out of the chroot environment and then 'reboot' to boot into your new root partition. In reality I had some trouble. It turns out that I typed the syntax to the setup command wrong, so the grub program didn't write the MBR right. Then I tried to reboot and my system hung. I was able to boot up to a live CD, in this case I tried both the debian live CD and also the GParted live CD. Then I created a mount point, mounted the newly copied partition, and tried grub again. Ultimately it worked. When I used grub the second time I used the '--verbose' flag. This way I was more sure that I had accomplished my goal with the 'setup' command.

Code:
# grub --verbose
> root (hd0,8)
> setup (hd0)
> quit
#
If you're typing in the commands right there's alot of hexadecimal output on the screen. If you're typing the commands wrong, the shell tells you it doesn't understand the arguments. You could, of course, type the syntax right but get the numbers wrong. I also tried a command called 'grub-install' but I think it was not needed.
Posted in Uncategorized
Views 1425 Comments 0
« Prev     Main     Next »

  



All times are GMT -5. The time now is 04:09 PM.

Main Menu

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration