LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 06-18-2015, 01:28 AM   #1
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Rep: Reputation: Disabled
Installing grub2 manually under CentOS 7


This is a long posting, generally for those with expert level grub/os install experience. I am moving my project from CentOS 6 to CentOS 7 and need to deal with the changes in the boot requirements introduced by CentOS 7, particularly the upgrade from grub to grub2. The gist of the problem is this:

In my CentOS 6 based work, I had my hard drive partitioned into various slices that each hosted a VM, installed with virt-install. I used a pre-created CentOS image that I could untar directly into the partition that was hosting the VM. Each VM's slice was partitioned into boot, swap, and rootfs partitions. I ran the required grub install commands to make the VM bootable.

In CentOS 7, things have changed a bit. When grub2 is installed on a GPT drive it requires an additional "bios_grub" partition. Let's assume I am installing a VM into /dev/sda4 of my hard drive. I've distilled my process down to the following set of commands:

-- Prepare the disk partition to host a VM. The VM has four partitions, one for grub, one for /boot, one for swap, and one for the main root file system.
# parted -s /dev/sda4 mklabel gpt
# parted -s /dev/sda4 mkpart primary ext3 1049kB 2097kB
# parted -s /dev/sda4 mkpart primary ext3 2MiB 130MiB
# parted -s /dev/sda4 mkpart primary linux-swap 130MiB 146MiB
# parted -s /dev/sda4 mkpart primary ext4 146MiB 100%
# parted -s /dev/sda4 set 1 bios_grub on
# parted -s /dev/sda4 set 2 boot on

# parted -s /dev/sda4 print
Model: Unknown (unknown)
Disk /dev/sda4: 75.2GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB primary bios_grub
2 2097kB 136MB 134MB ext3 primary boot
3 136MB 153MB 16.8MB linux-swap(v1) primary
4 153MB 75.2GB 75.0GB ext4 primary

-- Now install the vm image
# kpartx -av /dev/sda4
add map sda4p1 (253:0): 0 2048 linear /dev/sda4 2048
add map sda4p2 (253:1): 0 262144 linear /dev/sda4 4096
add map sda4p3 (253:2): 0 32768 linear /dev/sda4 266240
add map sda4p4 (253:4): 0 146499584 linear /dev/sda4 299008

# mkfs.ext3 /dev/mapper/sda4p1
# mkfs.ext3 /dev/mapper/sda4p2
# mkswap /dev/mapper/sda4p3
# mkfs.ext4 /dev/mapper/sda4p4

# mkdir /mnt/rootfs
# mount /dev/mapper/sda4p4 /mnt/rootfs
# mkdir /mnt/rootfs/boot
# mount /dev/mapper/sda4p2 /mnt/rootfs/boot
# tar zxf vm-template.tgz -C /mnt/rootfs
# mount -t devtmpfs /dev /mnt/rootfs/dev
# mount -t proc /proc /mnt/rootfs/proc
# mount -t sysfs /sys /mnt/rootfs/sys

-- Next, install grub2
# chroot /mnt/rootfs grub2-install --force /dev/sda4
Installing for i386-pc platform.
Installation finished. No error reported.

# chroot /mnt/rootfs grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-229.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.el7.x86_64.img
done

-- Umount everything
# umount /mnt/rootfs/sys
# umount /mnt/rootfs/proc
# umount /mnt/rootfs/dev
# umount /mnt/rootfs/boot
# umount /mnt/rootfs
# kpartx -dv /dev/sda4

-- And finally create my VM...
# virt-install --connect=qemu:///system --network bridge=br0,mac=RANDOM,model=virtio --name=vm-00 --disk path=/dev/sda4,bus=virtio --force --vcpus=1 --ram=1024 --check-cpu --accelerate --hvm --nographics --noreboot --import

Starting install...
Creating domain...
Domain creation completed. You can restart your domain by running:
virsh --connect qemu:///system start vm-00

Alas, at this point, the VM does start, but it immediately hangs. The BIOS does not make the transition to grub to boot CentOS. The same basic approach works for CentOS 6 so I assume I am missing some key step here, most likely related to how I am installing grub2. If anyone is experienced in this area and has any advice, I'd appreciate some input.

Peter
 
Old 07-07-2015, 09:22 AM   #2
colorpurple21859
LQ Veteran
 
Registered: Jan 2008
Location: florida panhandle
Distribution: Slackware Debian, Fedora, others
Posts: 7,345

Rep: Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588
The commands are correct for installing grub2. I think the host sees the partitions differently from the virtual machine so may cause problems with grub2. You could add a cdrom to the virtual machine and use a live iso.img to install grub2 to the virtual machine drive.
 
Old 07-11-2015, 06:16 PM   #3
colorpurple21859
LQ Veteran
 
Registered: Jan 2008
Location: florida panhandle
Distribution: Slackware Debian, Fedora, others
Posts: 7,345

Rep: Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588Reputation: 1588
Virt-rescue is an option to reinstall grub2 using the same commands you initially used to install grub2.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
set Ip Address manually in centos stella1051 Linux - Networking 8 12-10-2016 03:53 AM
Creating a GRUB2 Menu that will Dual Boot CentOS and Win7 desertcat Red Hat 7 05-04-2015 05:10 AM
centos 7: how to manually start a new system log? needsleep Linux - Software 3 12-26-2014 07:20 PM
CentOS 4.3 - Cannot run fsck manually because root password is unknown BobbyMac Linux - Newbie 11 07-21-2013 10:20 PM
[SOLVED] Download GRUB2 for CentOS 6 vikas027 Linux - Server 7 06-08-2012 01:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 09:42 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration