Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am preparing a bootable image manually (via a script) for use with virt-install and the --import option. The bootable image has three main partitions, the first which will be mounted as /boot on the VM, the second as swap, and the third as / (root).
I've got the image populated with the files I need and all I have left is to install grub so that the image will be bootable. I've done some searches and I'm not entirely sure what steps are needed. Let's say my bootable image is test.img. I'm running kpartx to give me access to the partitions in my image:
I need to get grub installed correctly into the /boot partition. I can access it after doing the kpartx command via the /dev/mapper/loop0p1 device (the real block device is actually /dev/dm-0; loop0p1 is a symbolic link). I'm just not sure which grub commands I need to make this a proper bootable image. Can anyone enlighten me as to the procedure I need to follow?
Last edited by PeterSteele; 07-11-2014 at 05:46 PM.
- Step 4: Populate image with custom CentOS template
# mkdir -p /mnt/sysimage
# mount -o loop /dev/dm-2 /mnt/sysimage
# mkdir -o /mnt/sysimage/boot
# mount -o loop /dev/dm-0 /mnt/sysimage/boot
# tar -zxpf custom-img.tar.gz -C /mnt/sysimage
At this point I have everything completed except for the final step of creating grub.conf and preparing the image so that it will boot when launched as a VM. Assuming I get grub setup properly, I'll need to run virt-install as the final step:
The CentOS grub support gpt just fine. If I use the CentOS kickstart facility to duplicate the steps I'm attempting to do manually, the end result is a bootable image that is configured with gpt partitions:
Code:
# parted -s test.img print
Model: Unknown (unknown)
Disk test.img: 51.2GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 128MB 128MB ext4 primary boot
2 129MB 4424MB 4295MB linux-swap(v1)
3 4424MB 51.2GB 46.8GB ext4
So I know I can accomplish what I need to do since CentOS itself does it during an OS install. I can duplicate all of the steps except for what CentOS does to make the image bootable and the specific grub commands it runs. Pages like this describe grub well but I cannot workout what's needed in my more specialized case.
I just found a link to the CentOS forums confirming what you already knew, that CentOS 6 and later supports GPT. Just noticed that my ArchLinux site had no date on it so don't know if it was written last week or ten years ago. I'm afraid I can't help you because I've not used Red Hat or derivatives much a little with Fedora and never had much success even trying to do a remaster.
In looking at the logs that are creating by anaconda during a kickstart controlled VM install, the commands it appears to perform are
- Switch to perspective of VM image just created
# chroot /mnt/sysimage
- Do first step of grub install
# grub-install --just-copy
- Then complete grub install using
# grub --batch --no-floppy --device-map=/boot/grub/device.map
grub> root (hd0,0)
grub> install --stage2=/boot/grub/stage2 /grub/stage1 d (hd0) /grub/stage2 p (hd0,0)/grub/grub.conf
When I try the same sequence of commands after chrooting to my own prepared image, it fails on the "root (hd0,0)" command saying that the selected disk does not exist. There's obviously another step that's not obvious from the logs that makes hd0 visible to Anaconda's chroot environment that I'm missing.
and create device.map to map (hd0) to /dev/vda. After doing this the grub commands all worked and I was able to create and boot a VM using the manually prepared image.
Last edited by PeterSteele; 07-14-2014 at 06:53 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.