lost and found ( for me ? )

Showing posts with label Grub2. Show all posts
Showing posts with label Grub2. Show all posts

KVM : how to connect to Fedora VMs which are using grub2 as a boot loader via virsh console or minicom

Here's an explanation of how to connect to VMs which are using grub2 via virsh console or minicom.
KVM host : Fedora 16
VM : Fedora 16 ( boot loader is grub2 not grub )

[ add a serial port to the VM ]

assume that the Fedora VM has a serial port.
you can check whether or not your VM has a serial port as below:

- on the KVM host

# virsh ttyconsole f16-vm1
/dev/pts/2

or


# virsh dumpxml f16-vm1 | grep serial
   <controller type='virtio-serial' index='0'>
     <alias name='virtio-serial0'/>
   <serial type='pty'>
     <alias name='serial0'/>
   </serial>
     <target type='serial' port='0'/>
     <alias name='serial0'/>
     <address type='virtio-serial' controller='0' bus='0' port='1'/>

[ configure a serial port on the VM ( not the KVM host ) ]

- on the VM

add the red lines
[root@localhost ~]# cat /etc/default/grub
GRUB_CMDLINE_LINUX="quiet rhgb biosdevname=0"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,9600n8"
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1"

add the following line in /etc/inittab
[root@localhost ~]# tail -1 /etc/inittab
S0:12345:respawn:/sbin/agetty ttyS0 115200

add the following line in /etc/securetty file.
[root@localhost ~]# echo "ttyS0" >> /etc/securetty

update grub.cfg
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.3.5-2.fc16.x86_64
Found initrd image: /boot/initramfs-3.3.5-2.fc16.x86_64.img
done


[root@localhost ~]# egrep -v ^# /boot/grub2/grub.cfg

if [ -s $prefix/grubenv ]; then
 load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
 set saved_entry="${prev_saved_entry}"
 save_env saved_entry
 set prev_saved_entry=
 save_env prev_saved_entry
 set boot_once=true
fi

function savedefault {
 if [ -z "${boot_once}" ]; then
   saved_entry="${chosen}"
   save_env saved_entry
 fi
}

function load_video {
 insmod vbe
 insmod vga
 insmod video_bochs
 insmod video_cirrus
}

serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1
terminal_input serial
terminal_output serial
set timeout=5

menuentry 'Linux, with Linux 3.3.5-2.fc16.x86_64' --class gnu-linux --class gnu --class os {
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2
set root='(/dev/vda,gpt2)'
search --no-floppy --fs-uuid --set=root ecdb7a66-7b00-49b9-b507-82e346d4c549
echo 'Loading Linux 3.3.5-2.fc16.x86_64 ...'
linux /boot/vmlinuz-3.3.5-2.fc16.x86_64 root=UUID=ecdb7a66-7b00-49b9-b507-82e346d4c549 ro quiet rhgb biosdevname=0 console=tty0 console=ttyS0,9600n8
echo 'Loading initial ramdisk ...'
initrd /boot/initramfs-3.3.5-2.fc16.x86_64.img
}


reboot the VM

[ connect to the VM from KVM host with virsh console ]

on the KVM host
[root@fc16 ~]# virsh list --all
Id Name                 State
----------------------------------
 1 f16-vm1              running

[root@fc16 ~]# virsh console f16-vm1
Connected to domain f16-vm1
Escape character is ^]

Password:

Login incorrect

login: root
Password:
Last login: Wed May 16 12:02:07 from 192.168.122.1

Appliance: jeos-f16 appliance 1.0
Hostname: localhost
IP Address: 192.168.122.124

[root@localhost ~]#

[ connect to the VM from the KVM host with minicom ]

You can also connect to the VM with minicom.

on the KVM hsot

install minicom
[root@fc16 ~]# yum install -y minicom

check a serial port number of the VM to which you want to connect.
[root@fc16 ~]# virsh ttyconsole f16-vm1
/dev/pts/2

connect to the VM with minicom
[root@fc16 ~]# minicom -op /dev/pts/2


Welcome to minicom 2.5

OPTIONS: I18n
Compiled on Apr  6 2011, 07:59:07.
Port /dev/modem

Press CTRL-A Z for help on special keys


Fedora release 16 (Verne)
Kernel 3.3.5-2.fc16.x86_64 on an x86_64 (ttyS0)

login: root
Password:
Last login: Wed May 16 12:34:59 on ttyS0

Appliance:      jeos-f16 appliance 1.0
Hostname:       localhost                                                       
IP Address:     192.168.122.124                                                 
                                                                               
[root@localhost ~]#


when exiting the VM , press Ctrl A and then press x

Fedora 16 : fix hanging Fedora when rebooting

My Fedora 16 device sometimes hangs when rebooting.

Fedora 16 64bit
ONKYO M513A5P ( laptop )

Seen from Fedora’s documentation , I could solve this issue by adding kernel options like this:

http://fedoraproject.org/wiki/Common_kernel_problems#System_hangs_on_reboot

System hangs on reboot

Changing the reboot method can work around this problem. To force a reboot method other than the default, use the reboot= kernel option:
  • reboot=b forces reboot through the system BIOS.
  • reboot=w forces a 'warm" reboot (no memory test.)

These can be combined: reboot=b,w forces a warm reboot using the system BIOS.

edit /etc/default/grub file.
GRUB_CMDLINE_LINUX="reboot=b,a"

b : bios
a : acpi

update grub.cfg
# grub2-mkconfig -o /boot/grub2/grub.cfg

( in case of Ubuntu based distribution , issue update-grub2 )

reboot the Fefora device to reflect kernel options.
# cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.2.7-1.fc16.x86_64 root=/dev/sda1 reboot=b,a

Grub2 chainloader : Linux Mint 12 , Fedora 16 ( Linux dual boot )


Here’s an explanation of how to update the grub2 configuration.

I’ve dual-booted two Linux distributions , Linux Mint 12 and Fedora 16.

MBR (Master Boot Record ) : Linux Mint's Grub2
Linux Mint : /dev/sda6
Fedora's Grub : /dev/sda1

When upgrading the Fedora’s kernels , I need to update Linux Mint’s Grub2 configuration (MBR) so that I can boot the new Fedora’s kernel via Linux Mint’s Grub(MBR).

I’d like to change MBR :

from

Linux mint 12
Fedora 16 ( 3.1.0-7 )

to

Linux mint 12
Fedora 16 ( 3.1.0-7 )
Fedora 16 ( 3.1.6-1 ) <- boot this kernel ver. via Mint’s grub

before updating Mint’s Grub ( MBR )

Let’s check the current /boot/grub/grub.cfg on Mint.

The following lines are  for Linux mint ( Linux Mint’s Grub )
### BEGIN /etc/grub.d/10_linux ###
<snip>
menuentry 'Linux Mint 12 32-bit, 3.0.0-14-generic (/dev/sda6)' --class linuxmint --class gnu-linux --class gnu --class os {
       recordfail
       set gfxpayload=$linux_gfx_mode
       insmod gzio
       insmod part_msdos
       insmod ext2
       set root='(hd0,msdos6)'
       search --no-floppy --fs-uuid --set=root b3a1ec63-246c-4711-b0ba-b14584205b71
       linux   /boot/vmlinuz-3.0.0-14-generic root=UUID=b3a1ec63-246c-4711-b0ba-b14584205b71 ro   quiet splash vt.handoff=7
       initrd  /boot/initrd.img-3.0.0-14-generic
}
<snip>
### END /etc/grub.d/10_linux ###


The followings are for Fedora 16 ( Linux Mint’s Grub )
### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Fedora release 16 (Verne) (on /dev/sda1)" --class gnu-linux --class gnu --class os {
       insmod part_msdos
       insmod btrfs
       set root='(hd0,msdos1)'
       search --no-floppy --fs-uuid --set=root ba2b7a10-73a2-4986-bcc5-964966fea960
       linux /boot/vmlinuz-3.1.0-7.fc16.i686.PAE root=/dev/sda1
       initrd /boot/initramfs-3.1.0-7.fc16.i686.PAE.img
}
### END /etc/grub.d/30_os-prober ###


There are two ways :

- have MBR ( Mint’s Grub ) load Fedora’s grub ( chainloader )
- add Fedora’s new kernel parameters in MBR

way1 : have MBR ( Mint’s Grub ) load Fedora’s grub ( chainload )

on Mint , iinstall os-prober to find installed other OSes
# apt-get install os-prober -y


Fedora 16 has been installed in /dev/sda1
# os-prober
/dev/sda1:Fedora release 16 (Verne):Fedora:linux


make 15_Fedora file to have MBR load Fedora’s grub
# cat /etc/grub.d/15_Fedora
#!/bin/sh
cat << \EOF
menuentry "Fedora" {
   set root='(hd0,msdos1)'  # hd0 = /dev/sda  msdos1 = sda1
   chainloader +1
}
EOF

# chmod u+x 15_Fedora


update grub.cfg ( MBR )
# update-grub2


The red lines are added in /boot/grub/grub.cfg
### BEGIN /etc/grub.d/15_Fedora ###
menuentry "Fedora" {
   set root='(hd0,msdos1)'
   chainloader +1
}
### END /etc/grub.d/15_Fedora ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Fedora release 16 (Verne) (on /dev/sda1)" --class gnu-linux --class g
nu --class os {
       insmod part_msdos
       insmod btrfs
       set root='(hd0,msdos1)'
       search --no-floppy --fs-uuid --set=root ba2b7a10-73a2-4986-bcc5-964966fe
a960
       linux /boot/vmlinuz-3.1.0-7.fc16.i686.PAE root=/dev/sda1
       initrd /boot/initramfs-3.1.0-7.fc16.i686.PAE.img
}
menuentry "Fedora release 16 (Verne) (on /dev/sda1)" --class gnu-linux --class gnu --class os {
       insmod part_msdos
       insmod btrfs
       set root='(hd0,msdos1)'
       search --no-floppy --fs-uuid --set=root ba2b7a10-73a2-4986-bcc5-964966fea960
       linux /boot/vmlinuz-3.1.6-1.fc16.i686.PAE root=/dev/sda1
       initrd /boot/initramfs-3.1.6-1.fc16.i686.PAE.img
}
### END /etc/grub.d/30_os-prober ###


You can boot the Fefora’s new kernel ( 3.1.6-1 ) via Mint’s grub.

way2 : add Fedora’s new kernel parameters in MBR

on Linux Mint 12

install os-prober to find installed other OSes
# apt-get install os-prober -y


Fedora 16 has been installed in /dev/sda1
# os-prober
/dev/sda1:Fedora release 16 (Verne):Fedora:linux


check the file system of /dev/sda1 (Fedora16)
# grub-probe -d /dev/sda1
btrfs


mount /dev/sda1 to tmp directory to check Fedora’s grub.cfg.
# mount -t btrfs /dev/sda1 tmp


check the Fedora’s grub.cfg
Red lines are the new Fedora’s kernel 3.1.6-1.
This kernel ver. does not exist in MBR (Mint’s grub ).
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Fedora (3.1.6-1.fc16.i686.PAE)' --class fedora --class gnu-linux --cl
ass gnu --class os {
       load_video
       set gfxpayload=keep
       insmod gzio
       insmod part_msdos
       insmod btrfs
       set root='(hd0,msdos1)'
       search --no-floppy --fs-uuid --set=root ba2b7a10-73a2-4986-bcc5-964966fe
a960
       echo 'Loading Fedora (3.1.6-1.fc16.i686.PAE)'
       linux   /boot/vmlinuz-3.1.6-1.fc16.i686.PAE root=UUID=ba2b7a10-73a2-4986
-bcc5-964966fea960 ro rd.md=0 rd.lvm=0 rd.dm=0 quiet rhgb rd.luks=0 LANG=ja_JP.U
TF-8  KEYTABLE=jp106
       echo 'Loading initial ramdisk ...'
       initrd /boot/initramfs-3.1.6-1.fc16.i686.PAE.img
}
menuentry 'Fedora Linux, with Linux 3.1.0-7.fc16.i686.PAE' --class fedora --clas
s gnu-linux --class gnu --class os {
       load_video
       set gfxpayload=keep
       insmod gzio
       insmod part_msdos
       insmod btrfs
       set root='(hd0,msdos1)'
       search --no-floppy --fs-uuid --set=root ba2b7a10-73a2-4986-bcc5-964966fea960
       echo    'Loading Linux 3.1.0-7.fc16.i686.PAE ...'
       linux   /boot/vmlinuz-3.1.0-7.fc16.i686.PAE root=UUID=ba2b7a10-73a2-4986-bcc5-964966fea960 ro rd.md=0 rd.lvm=0 rd.dm=0 quiet rhgb rd.luks=0 LANG=ja_JP.UTF-8  KEYTABLE=jp106
       echo    'Loading initial ramdisk ...'
       initrd  /boot/initramfs-3.1.0-7.fc16.i686.PAE.img
}


on Mint , make 15_Fedora file and add the above red lines
# cat /etc/grub.d/15_Fedora
#!/bin/sh
cat << \EOF
menuentry 'Fedora (3.1.6-1.fc16.i686.PAE)' --class fedora --class gnu-linux --cl
ass gnu --class os {
       load_video
       set gfxpayload=keep
       insmod gzio
       insmod part_msdos
       insmod btrfs
       set root='(hd0,msdos1)'
       search --no-floppy --fs-uuid --set=root ba2b7a10-73a2-4986-bcc5-964966fe
a960
       echo 'Loading Fedora (3.1.6-1.fc16.i686.PAE)'
       linux   /boot/vmlinuz-3.1.6-1.fc16.i686.PAE root=UUID=ba2b7a10-73a2-4986
-bcc5-964966fea960 ro rd.md=0 rd.lvm=0 rd.dm=0 quiet rhgb rd.luks=0 LANG=ja_JP.U
TF-8  KEYTABLE=jp106
       echo 'Loading initial ramdisk ...'
       initrd /boot/initramfs-3.1.6-1.fc16.i686.PAE.img
}
EOF

# chmod u+x 15_Fedora


update grub.cfg
# update-grub2
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.0.0-14-generic
Found initrd image: /boot/initrd.img-3.0.0-14-generic
Found linux image: /boot/vmlinuz-3.0.0-13-generic
Found initrd image: /boot/initrd.img-3.0.0-13-generic
Found linux image: /boot/vmlinuz-3.0.0-12-generic
Found initrd image: /boot/initrd.img-3.0.0-12-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Fedora release 16 (Verne) on /dev/sda1
done


Fefora’s new kernel has been added in MBR’s grub.cfg ( Mint )
### BEGIN /etc/grub.d/15_Fedora ###
menuentry 'Fedora (3.1.6-1.fc16.i686.PAE)' --class fedora --class gnu-linux --cl
ass gnu --class os {
       load_video
       set gfxpayload=keep
       insmod gzio
       insmod part_msdos
       insmod btrfs
       set root='(hd0,msdos1)'
       search --no-floppy --fs-uuid --set=root ba2b7a10-73a2-4986-bcc5-964966fe
a960
       echo 'Loading Fedora (3.1.6-1.fc16.i686.PAE)'
       linux   /boot/vmlinuz-3.1.6-1.fc16.i686.PAE root=UUID=ba2b7a10-73a2-4986
-bcc5-964966fea960 ro rd.md=0 rd.lvm=0 rd.dm=0 quiet rhgb rd.luks=0 LANG=ja_JP.U
TF-8  KEYTABLE=jp106
       echo 'Loading initial ramdisk ...'
       initrd /boot/initramfs-3.1.6-1.fc16.i686.PAE.img
}
### END /etc/grub.d/15_Fedora ###


You can boot the Fedora’s new kernel (3.1.6-1) via Mint’s grub ( MBR )

You need to issue update-grub2 command in both the way1 and the way2 after upgrading Fedora’s kernel.
In case of way1 , all you have to do is just issuing update-grub2.
However , in case of way2 , you need to edit  /etc/grub.d/15_Fedora and issue update-grub2.
So I think the way1 would be a better operation than the way2.