Tuesday, December 28, 2010

Grow single partition (Debian running on ESXi)

Now, for a while my Anti-Spam solution worked fine and properly. But after a year, it started to make some Problems. (Described {here}) End of the story was: I need more Storage!


On the virtual Machine, the Storage was automatically partitioned as we installed it first.. (Don't ask - we didn't have much time back then)

Normal
1. Backup
2. Change Harddisk size
3. Change Partitions
Finished!

HELP! My Machine is dead!
4. kernel Panic!!!! - Don't Panic!!! Prepare Chroot
5. GRUB & initramfs Repair
6. Celebrate

Please Follow Steps 1 to 3. If you have a kernel error after Step 3 please follow Steps 4 to 6. 


Fine... Now the system as is:

Host System:
VmWare ESXi 4.0

Guest System:
debian 5.0 r3 with some daemons (spamassasin / mysqld / amavisd - click {here})

I need to grow the size of /var, where the mysql Databases are located.
[root @ maia:~#]>df -h
Dateisystem          Größe Benut  Verf Ben% Eingehängt auf
/dev/sda1             327M  138M  173M  45% /
tmpfs                1008M     0 1008M   0% /lib/init/rw
udev                   10M  604K  9.5M   6% /dev
tmpfs                1008M     0 1008M   0% /dev/shm
/dev/sda9             4.2G  137M  3.9G   4% /home
/dev/sda8             373M   11M  343M   3% /tmp
/dev/sda5             4.2G  840M  3.2G  21% /usr
/dev/sda6             2.1G  1.7G  312M  85% /var
[root @ maia:~#]>
You see, the /var is nearly full, 300 Mb left.

In order to change the disk size, we need to know: /var is /dev/sda6.



We need Tools! Prepare this ISO Images to load into your Server


Parted Magic

If anything goes wrong we need the Debian Live Rescue CD.

Debian Live CD



Step 1 - Backup: 


Backup your virtual Machine!


Snapshot it, Copy it, whatever you do watch that you could go back.

(My Impressum - I don't take any responsibility if anything goes wrong)



Step 2 - Change Harddisk Size:


Change the virtual Harddisk size.
If I were you - Halt the Machine first. Then Change like this (Sorry for German Screenshot):





Step 3 - Change Partitions: 


In order to go forth, you need to get the Parted Magic CD into your virtual Machine and boot from it. After that you might want to change display resolution to work on 1024 x 768 or greater. (vesa configuration)


Then  - Start Gparted
You see now, at the end of the device there is the storage you added to your VM.


Now - Thats a bit tricky. You first need to expand the Extended Partition before you can change that partition you want. (In my case /dev/sda6 aka /var)

















Change everything you need so that it fit's for you, and hit "Apply".


Depending on your disk size and amount of data - go watch a movie.

It's finished? Congratulation! Now Reboot - and look.. if a kernel error

kernel panic-not syncing VFS:unable to mount root fs on unknown-block(0,0)
appears, continue with Step 4.

Otherwise

Finished! Congratulations!

[root @ maia:~#]>df -h
Dateisystem          Größe Benut  Verf Ben% Eingehängt auf
/dev/sda1             327M  138M  173M  45% /
tmpfs                1008M     0 1008M   0% /lib/init/rw
udev                   10M  604K  9.5M   6% /dev
tmpfs                1008M     0 1008M   0% /dev/shm
/dev/sda9             4.2G  137M  3.9G   4% /home
/dev/sda8             992M   11M  930M   2% /tmp
/dev/sda5             4.2G  840M  3.2G  21% /usr
/dev/sda6             9.4G  1.7G  7.2G  19% /var
[root @ maia:~#]>
Now i won't have Problems with that mysql Database again.  

Like i said: if you got a
kernel panic-not syncing VFS:unable to mount root fs on unknown-block(0,0)

Error - Continue with Step 4

Step 4 - kernel Panic!!!! - Don't Panic!!! Prepare Chroot:


You broke your System!.

You don't even have to try bootin again.


To fix that, we need to boot up with the Debian Live CD I've mentioned before.


After you booted and got the shell type
sudo passwd root
And change your root Password. (Something easy - 1234 should work for now) - then get root with
su

 Now what we do is chroot in your previous installation and fix it.

Some Preparations:
cd /
mount -t ext3 /dev/sda1 /mnt
mount -t proc proc /mnt/proc
mount -t sysfs sys /mnt/sys
mount -o bind /dev /mnt/dev

That prepares your chroot environement

To work, we surely need /usr. If you don't have /usr on the same partition as /, then we need to add it.

If you need to chroot any more partitions add them with
mount -t ext3 /dev/sda5 /mnt/usr

and additionally, my /var partition
mount -t ext3 /dev/sda6 /mnt/var 

If your /boot directory is on a different partition from your / you need to add it..
mount -t ext3 /dev/sda2 /mnt/boot

Finished? Now we do the real stuff..
chroot /mnt /bin/bash

We now work on your original system, so be careful.

Because we need to work with GRUB, we need to:
grep -v rootfs /proc/mounts > /etc/mtab

update the /etc/mtab file.


Also, for me it's a help knowing I'm chrooted:
source /etc/profile
export PS1="(chroot) $PS1"

Step 5 - grub & initramfs repair:

First - check your boot directory is there:
(chroot) [root @ maia:~#]>ls -alh /boot
insgesamt 9.4M
drwxr-xr-x  3 root root 1.0K 21. Apr 2010  .
drwxr-xr-x 22 root root 1.0K 21. Apr 2010  ..
-rw-r--r--  1 root root  84K 10. Mär 2010  config-2.6.26-2-amd64
drwxr-xr-x  2 root root 1.0K 21. Apr 2010  grub
-rw-r--r--  1 root root 6.4M 21. Apr 2010  initrd.img-2.6.26-2-amd64
-rw-r--r--  1 root root 1.2M 10. Mär 2010  System.map-2.6.26-2-amd64
-rw-r--r--  1 root root 1.7M 10. Mär 2010  vmlinuz-2.6.26-2-amd64
(chroot) [root @ maia:~#]>

Thats not bad at all, it has just the wrong Partitions mapped. To change that use the following lines:

(Please adapt to your needs)
grub
grub>root(0,0)
grub>setup (hd0)
grub>quit
grub-install hd0

after that, do
cd /boot
mv initrd.img-2.6.26-6-amd64 initrd.img-2.6.26-6-amd64.bak
mv initrd.img-2.6.26-6-amd64.bak initrd.img-2.6.26-6-amd64
update-initrdfs -u -k all -b /boot -f

Update-initrdfs tells you something about initrd.img-2.6.26-6-amd64 was altered and need to update, what it will do in the following.


and then - finally - reboot


Step 6 - celebrate:


Normally your system should boot up just fine, without the Error below:
kernel panic-not syncing VFS:unable to mount root fs on unknown-block(0,0)
 {etcpp}
 maia login: 


Have fun! Chris

No comments:

Post a Comment