3

I cannot get a CentOS 7 ISO (on a hard drive) to boot from GRUB2 that is installed on the hard drive.

I have tried the following steps based on this article

My requirement is to boot a CentOS ISO from a virtual hard disk drive inside a VMWare VM (i.e a bootable .vmdk). These are the requirements, and alternatives are not what I am looking for at the moment.

I have tried to install grub2 on a virtual hard disk and modify the grub configuration to boot this ISO

I perform both of these activities on a VM that I booted to the latest CentOS Gnome Live ISO (here is the process, I used)

Create new VM (call it VMDK_Stager) with 4GB Virtual hard disk (vmdk)

Mount and Boot to CentOS-Live-GNOME.iso

Open Terminal to run commands

Get to root

su

Run these commands to stage the drive, and install grub and Create Partition

fdisk /dev/sda
n (for new partition, then select all defaults for blocks/sizing/etc.)
a (to activate)
w (to write changes and quit fdisk)

Format partition

mkfs.ext4  /dev/sda1

mount partition

mount /dev/sda1

update install packages involved

yum install livecd-tools
yum upgrade grub2
yum upgrade dracut

install Grub on disk/partiion (this will create /mnt/boot/grub2)

   grub2-install /dev/sda --boot-directory=/mnt/boot

create /mnt/boot/iso to house the ISO file

mkdir /mnt/boot/iso
cd /mnt/boot/iso

Copy CentOS-7-x86_64-GNOME-1603-02.iso (downloaded from CentOS mirror) to /mnt/boot/iso (I did this to test a "known good" ISO)

create custom grub.cfg

#Begin /boot/grub2/grub.cfg
set default=0
set timeout=10
set root=(hd0,1)

menuentry 'CentOS-Live-GNOME' {
    set isolabel=CentOS-7-x86_64-GNOME-1603-02
    set isofile='/boot/iso/CentOS-7-x86_64-GNOME-1603-02.iso'
    loopback loop $isofile
    linux (loop)/isolinux/vmlinuz0 iso-scan/filename=$isofile root=live:CDLABEL=$isolabel ro rd.live.image quiet rhgb
    initrd (loop)/isolinux/initrd0.img
}

Copy this staged vmdk to another directory on the host to be used by another VM (call it VMDK_ISO_Booter) Create a VM and use this vmdk as the only hard drive

It ends in a dracut prompt and says that the /dev/disk/by-label cannot be found

2

The issue is almost certainly some combination of using a slightly incorrect CDLABEL, grub not being able to mount the iso, the kernel arguments do not match those intended for use with the image, or there is some irregularity with the ISO - I didn't see that specific one on the mirrors.

You need to grab the exact label from the isolinux.cfg file that is on the iso

If you have CentOS-7-x86_64-LiveGNOME-1603-02.iso the line in the file is:

 append initrd=initrd0.img root=live:CDLABEL=CentOS-7-x86_64-GNOME-1603-02 rootfstype=auto ro rd.live.image quiet  rhgb rd.luks=0 rd.md=0 rd.dm=0 

Here's a modified grub.cfg to try (based on an ISO that I have; yours may be slightly different; they apparently dropped the 'Live' part of the name, or you did.

menuentry "CentOS-Live-GNOME" {
    set isolabel="CentOS-7-x86_64-GNOME-1603-02"
    set isofile="/boot/iso/CentOS-7-x86_64-LiveGNOME-1603-02.iso"
    insmod iso9660
    loopback loop ${isofile}
    linux (loop)/isolinux/vmlinuz0 root=live:CDLABEL=CentOS-7-x86_64-GNOME-1603-02 rootfstype=auto ro rd.live.image quiet rhgb rd.luks=0 rd.md=0 rd.dm=0 iso-scan/filename=${isofile} 
    initrd (loop)/isolinux/initrd0.img
}

That might work as is, but double check the label and the rest of the kernel arguments against the isolinux.cfg entry.

When / If you get to a dracut prompt, grep the file sosreport.txt for the word "loop" - it should give the actual name being presented by the iso; and you can then make the correction. Also take a look at the devices on /dev; can you find the iso 'device' anywhere in the /dev/disk/... by-id .. by-label .. by-uuid etc. Any of those references will work. It has to be a perfect match; here is what is being evaluated and where the error you are receiving comes from.

I did nearly exactly what you are doing but with Fedora a while ago (fedora 19?), and it took a little tweaking before it worked.

The next link shows you to do this manually (somewhat), so you can step through rather than going through the painful regenerate, reboot, repeat cycle.

https://help.ubuntu.com/community/Grub2/ISOBoot

  • I am giving this answer the upvote, because it does aggregate the answers that I have found through my own research. However, I do have the labels correct for this and other ISO, and it still fails to boot. When this happens, the /dev/disk/by-label directory doesn't exist (I am fairly certain that the issue resides in the dracut version included on the CentOS iso). I say this because, I have been able to create an ISO that works by simply updating the version of dracut from Fedora repos. – user1431174 May 9 '16 at 19:03
  • I wanted a drive that I could boot from a USB adapter as well as from the sata and do an install with a custom kickstart. I used the Centos 7 Live CD on a USB to create a drive then added a custom.cfg in /boot/grub2 and included the configuration in Argonauts' answer. I can now boot to the live CD iso. Now I plan to write an OI to customize my installs and pass that information to liveinst. I have the rest of the hard drive to store map data, other iso images, etc. and will end up with a fully contained Linux build environment. – prankin Aug 4 '16 at 22:39
  • By the way, if you don't know the exact label of the iso do the following: mount -o loop <file.iso> /mnt; blkid and you will see the label along with the UUID. – prankin Aug 4 '16 at 22:48
  • And another thing, it is probably best not to edit the grub.cfg file since it gets overwritten when you do a grub-mkconfig. Instead create a file called custom.cfg in the /boot/grub2 directory and it will add these menus in to the grub menu. I had no luck adding them to the file: /etc/grub.d/40_custom. – prankin Aug 4 '16 at 22:54
0

I cannot understand why this is giving you so much trouble. Yours looks like another example of an XY problem. A much simpler solution is:

  1. Download a CentOS iso from here;

  2. Install CentOS from the iso in a new VM, in just about any Hypervisor: for instance, I have just used VirtualBox (make sure you choose vdmk for the disk format when you create the new VM); also, make sure you reboot the VM at least twice, in order to go through the whole installation process. Turn off the CentOS VM.

You are done: the vmdk disk on which you have installed CentOS, if you have done everything correctly, already contains a partition with the boot flag set. You can now mount the newly created vmdk disk as a hard disk with a SATA controller in a second VM, and possibly in another hypervisor (VMWare, Xen, you name it). If you want to boot from the CentOS disk in the second VM, just make sure that the order of booting allows you to boot first from the new disk, i.e. the one created under CentOS.

  • The requirement is to boot an ISO (this is for distributing to our customers). Not to install CentOS on a VM. – user1431174 Apr 27 '16 at 22:39
  • Do you have any suggestions to ensure that I am not asking an XY problem? My intent was to explain what I have tried. The problem is that I can't boot the CentOS iso from a hard drive (which is what I need to do based on requirements given to me). I really looked over the "How to ask a good question" after doing an exhaustive search on the matter – user1431174 Apr 28 '16 at 19:31
  • 1.: do you mean an ISO of a special version of CentOS, with your own modification, or just an ISO of a clean version without customization? 2.: you avoid asking an XY question by separating clearly your problem, and your attempted solution. You must state very clearly what your problem is, and, if necessary, why other, well-known solutions do not apply to your problem. Then you start spinning your tale: I thought I could solve this by trying so and so, but got stuck here... Hope this helps. – MariusMatutiae Apr 30 '16 at 9:06
  • I mean "just an ISO of a clean version without customization". My attempt to state that was : "Copy CentOS-7-x86_64-GNOME-1603-02.iso (downloaded from CentOS mirror) to /mnt/boot/iso (I did this to test a "known good" ISO)" – user1431174 May 6 '16 at 0:50
  • I have also updated my post/question in an attempt to follow your suggestion to avoid XY question. – user1431174 May 6 '16 at 0:57
0

I usually write my own XML for qemu/virsh VMs, but the idea is to tell the virtual BIOS to boot from the ISO, right? So, when you set up your VM, tell it that the ISO is a CD-ROM, give it an empty file on the host to act like a hard disk to install onto, and set the boot order to try the hard disk, then the CD-ROM. Then boot the VM and follow the screen prompts for a normal install.

The installation will put grub on the virtual hard disk for you.

IMHO, VMware makes things more mysterious than they need to be.

  • Thanks for the answer, however the requirement is to boot and ISO from a virtual hard drive. Grub installs just fine with the steps I took on 'Stager' VM. It just won't boot the ISO from the Booter VM – user1431174 May 9 '16 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.