Koozali.org: home of the SME Server

kernel panic trying to resize /dev/mapper/mainroot

Offline lightman

  • ****
  • 75
  • +0/-0
kernel panic trying to resize /dev/mapper/mainroot
« on: August 18, 2010, 06:08:11 AM »
Hello
I´m trying to resize the / partition, since it's nearly full, with tons of emails (we use imap a lot).

I'm Running SME 7.4 from a ESXi 4 Virtual Machine (and of course, this attempt was done with an offline copy just in case :D )

I follow the steps outlined here: http://forums.contribs.org/index.php?topic=35920.0

but the post is a little old and sure something changed since then!.

I delete partition 2 where the / is, and recreate it to occupy the entire new space, change type and write it. (with fdisk)

then reboot with the rescue CD and do:
#mdadm --create /dev/md2 --level 1 --raid-devices=2 /dev/hdc2 missing

Of course my drive is /dev/sda so I changed hdc2 by sda2

now when a reboot I get: Volume group "main" not found
ERROR: /bin/lvm exited abnormally!
...
mount: error 6 mounting ext3
mount: error 2 mounting none
Switching to new root
switchroot: mount failed: 22
umount /initrd/dev failed: 2
Kernel Panic - not syncing: Attempted to kill init!!

And that's all, Obviously I don't have understanding of LVM at all, so I don't know what's wrong.
can anyone point me in the right direction please?
what did I do wrong?

thank you in advance :D
indkt.

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: kernel panic trying to resize /dev/mapper/mainroot
« Reply #1 on: August 18, 2010, 10:00:13 AM »
hi

you say it's a virtual machine so..
- does it have only an hd?
- did you install with no-raid option?

please post the output of
Code: [Select]
cat /proc/mdstat

and of
Code: [Select]
mount

thank you

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: kernel panic trying to resize /dev/mapper/mainroot
« Reply #2 on: August 18, 2010, 02:39:48 PM »
I delete partition 2 where the / is, and recreate it to occupy the entire new space, change type and write it. (with fdisk)

then reboot with the rescue CD and do:
#mdadm --create /dev/md2 --level 1 --raid-devices=2 /dev/hdc2 missing

Of course my drive is /dev/sda so I changed hdc2 by sda2

now when a reboot I get: Volume group "main" not found

Since you have deleted your / partition, created a new one, but you have not made a file system on the new partition, and have not put any files on the new / partition, then it is not surprising at all that your system does not boot.

Offline lightman

  • ****
  • 75
  • +0/-0
Re: kernel panic trying to resize /dev/mapper/mainroot
« Reply #3 on: August 23, 2010, 01:55:50 AM »
Hi! Thank you both for reply!, I had to travel and couldn't check the forum.
I really didnt remember with what options I have installed it, it is probably that I choose noraid since it would be in a virtual machine.

when I do cat /proc/mdstat says:
Personalities:
unused devices: <none>

(does it means that I installed using noraid option?)

mount:
/dev/mapper/main-root on / type ext3 (rw,usrquota,grpquota)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sda1 on /boot type ext3 (rw)
none on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

I'm sorry I know I'm an idiot in this matter, specially when it comes to LVM, i have ZERO knowledge in it (but you already know that  :lol: )

I'm reading the LVM faq and howto's but I have a lot to learn, any help, appreciated :D

Light.

[EDIT]: Forgot to mention that it has only 1 drive /dev/sda.
[EDIT2]: I'm eating all I can about LVM, and maybe I'm using the wrong approach, correct me please if I'm Wrong, wouldn't be better to create another partition in the empty space /dev/sda3, and add it to the LVM Group MAIN?, then extend the volume root ?, for what I'm reading is how it should be done (I see a but coming... :D) can I do something like this?.
« Last Edit: August 23, 2010, 06:18:26 AM by lightman »

Offline lightman

  • ****
  • 75
  • +0/-0
Re: kernel panic trying to resize /dev/mapper/mainroot
« Reply #4 on: August 23, 2010, 06:47:14 AM »
Hello, After almost 6 hours of investigating and reading all I could find on the net, here is the (aparent (??)) solution.

I'm posting it, because it can be of help to someone else, and also, please, SME Guru's tell me if I didn't make any dangerous or inconvenient mistake, thank you :)

First, we must know the name of the logical volume and the name of the volume group.

lvm
lvm>lvdisplay
--- Logical Volume ---
LV Name              /dev/main/root     <---- this is it
VG Name             main   <--- Group name
there will be (probably) other with the swap:
--- Logical Volume ---
LV Name            /dev/main/swap

In my case SME was in a virtual machine (ESXi 4) so what I did was allocate more space, editing the virtual machine.
after doing this and start SME, i have three partition instead of two

fdisk /dev/sda
p

/dev/sda1   *
/dev/sda2
/dev/sda3


since /dev/sda3 was not pointing to anywere, i added it to the LVM's physical volume.

lvm
lvm>pvcreate /dev/sda3

now add it to the group

lvm>vgextend main /dev/sda3

now if we do vgdisplay wi will see that instead of 1 or 2 PE we have a LOT!. (look at the line that says FREE PE / SIZE)

ok, now we have free space available in our group, now we add it to the root volume (where the entire / is)

lvm>lvextend -L+10G /dev/main/root     (in this case, I added 10Gb, the group is main, the logical volume is root)

now we must extend the filesystem, but since it must be dismounted for this, reboot with the SME CD, type SME RESCUE,
do not mount network and mount the filesystem when ask.

then umount manually everything that says /mnt/sysimage/xxx , then the /mnt/sysimage
(I do this, because i don't know how to start the LVM in rescue mode, this is a nasty way to do it  :D )

check if fs is ok first, or else....:
e2fsck -f /dev/main/root

then the resize:
resize2fs -p /dev/main/root

exit and reboot, that's it.
If someone will try this on a live system BACKUP FIRST!, I did it 4 times in 2 SME to be sure before going to the real thing, and since I'm in a virtual machine enviroment I have SNAPSHOTS, so I can go back if something's going wrong, so be careful!.

that's it, please correct me if I did something incorrect :).
BTW: I had no idea how great and powerful LVM was!!, amazing!!.
« Last Edit: August 23, 2010, 03:25:58 PM by lightman »

Offline slords

  • *****
  • 235
  • +3/-0
Re: kernel panic trying to resize /dev/mapper/mainroot
« Reply #5 on: August 23, 2010, 05:16:51 PM »
The directions you followed aren't the best on how to expand your system.  They might work on a standard install, but you don't have a standard install.  It appears the you did in fact install without raid.  Even if you did install with raid you shouldn't ever have to recreate the raid setup like that post suggests.  You can just grow it.

If you want to do something similar to what that post said you can try the following on your test vm first.  It will be a good learning experience for you and might help you understand what is going on a little more.

None of this should need to be done in rescue mode.  It will take a few reboots but everything should work from a cmd prompt within sme itself.

First off you can type "pvs" (physical volume show) and see what physical volumes you have.
Code: [Select]
[root@handel ~]# pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/hda2  main lvm2 a-   74.41G 48.47G

If you get back /dev/md# then you have it installed on raid and need to expand that first.  Assuming you don't have that (if you do let me know and we can walk through expanding that), you need to note what drive you are using (sda#, sdb#, etc).

Next list the partitions on the drive that you want to expand with "fdisk -l /dev/sdX".
Code: [Select]
[root@handel ~]# fdisk -l /dev/hda

Disk /dev/hda: 81.9 GB, 81964302336 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        9964    79931407+  8e  Linux LVM

You will need to take note of the Start and Id sections of the #2 partition.  Delete the second partition and recreate it using the rest of the drive.  Before you write the partition table out ensure that the Start and Id are the same!

Once you write the partition table out you will get a warning that it couldn't because the drive is in use.  Reboot the system at this point to read in the updated partition table.

After rebooting the drive you will need to grow the physical volume with "pvresize" command.
Code: [Select]
root@handel ~]# pvresize /dev/hda2
  Physical volume "/dev/hda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

At this point you should be able to see available PE's and can continue like you did before by expanding the LV and resizing the filesystem.

After the "lvresize -L +10G /dev/main/root" you can resize the filesystem online by using "ext2online -C0 /dev/main/root" instead of the "resize2fs" command that would require you to be in rescue mode.  (If you are running sme8/centos5 then the resize2fs command will resize an online filesystem).

Hope this helps you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." -- Rich Cook

Offline lightman

  • ****
  • 75
  • +0/-0
Re: kernel panic trying to resize /dev/mapper/mainroot
« Reply #6 on: August 25, 2010, 05:44:32 AM »
Hi slords
Thank you for all the information!, I did it, and worked with an online system!!! WOW! :shock: I couldn't believe it.
I first resize the partition preserving start and ID, then pvresize, el rest as always and it worked instantly!, fantastic!! thankyou!.

One thing I would like to learn, is how will it be in case i have software raid, for what I can see md loads before lvm right?, so in order to resize it it would be necessary to unload md? to operate at disk level (and then reload md after the resize and then software raid will rebuild from scratch) or the resize should be done over the md device?

I will look around how the software raid works, so i have a better understanding of this, if you have some link, specifically of the working in the sme server, would be great.
thank you again :D
regards
Lightman
« Last Edit: August 25, 2010, 05:48:23 AM by lightman »

Offline slords

  • *****
  • 235
  • +3/-0
Re: kernel panic trying to resize /dev/mapper/mainroot
« Reply #7 on: August 26, 2010, 12:04:11 AM »
One thing I would like to learn, is how will it be in case i have software raid, for what I can see md loads before lvm right?, so in order to resize it it would be necessary to unload md? to operate at disk level (and then reload md after the resize and then software raid will rebuild from scratch) or the resize should be done over the md device?

This is already documented.  The only difference would be the fdisk process above to grow the #2 partition.  Once you have increased the size of the #2 partition as described above you just need to execute the commands under point 6 on http://wiki.contribs.org/Raid#Upgrading_the_Hard_Drive_Size
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." -- Rich Cook