I have X86 based UEFI compatible system , Would like to boot the linux OS , but I am using GRUB as a boot loader .
I can boot the linux via GRUB boot loader script using command
linux ${dir_path}/vmlinuz root_image=${root_path}/rootfs.img root_node=8 console=tty0 console=ttyS0,115200n8
boot
So the boot works as below
Grub.efi-->vmlinux-> rootfs
However , I have a question that can we create a single monolithic efi image which contains GRUB, VMLINUZ and Rootfs ?
Is so what changes are required in the Grub bootloader script inroder to boot ?
Can you share the any pointers or link that talks about this..
Tinker of the GRUB is required to be compatible with older OS version so that it helps transition from older OS flavour to Openwrt
Your post is very unclear. In the original post, you wrote "Linux" and didn't mention OpenWrt at all. I suggest you take the time to explain what you currently have (which Linux, which hardware etc) and what exactly you want to achieve.
Yes that is how OpenWrt is distributed, as a "combined-efi" image. OpenWrt is intended to run on bare metal as the only OS on the disk. There isn't a "transition" process-- installation consists of clobbering everything on the disk and overwriting it with the OpenWrt system. The combined image includes a partition table, partitions, GRUB, and OpenWrt which were built at the same time and made to be compatible with each other. It doesn't matter what was installed on your disk before, or if you start with a blank new disk.
Write the image directly to the raw disk (after uncompressing it with gzip). Since the partition table is being overwritten, any existing partitions on the disk will be lost.
I have a requirement to run the Openwrt in X86 based system which has UEFI as firmware.
For UEFI Firmware to handover the control to either GRUB or linux , the image format should be EFI.
My question is , can we get a monolithic image that has GRUB , kernel , initramfs and rootfs as single EFI image.
I am looking at grub-mkimage make image utility which will has -d argument.
Can we add all the image that include grub, kernel , initramfs , rootfs as part of the -d parameter ?
Or -d should include only the grub image ?
Hello-
This is fairly simple if you are not trying to make a dual-boot system.
download
openwrt-23.05.5-x86-64-generic-ext4-combined-efi.img.gz
This image boots using grub, on an efi system.
You can boot the system using something like Clonezilla and image the boot device with something like
zcat openwrt-23.05.5-x86-64-generic-ext4-combined-efi.img.gz |dd bs=4096 of=/dev/sda
assuming /dev/sda is your boot device.
(It will give you a note about ignoring garbage, ignore this note.)
Note that this will overwrite any system that is there, but this should boot as an efi, x86 openwrt when you're done. This is the simplest way.
If you want to dual-boot an existing linux system, you can do that but it's a bit more complex. I'm trying to give you the simplest answer.
Hello-
That will probably work most of the time, but the image is an image of a block device, and /dev/sda is a block device. dd makes sure the blocks of the image line up with the blocks of the device. Using the > operator is file-level, not block-level. It will probably be fine, but because the system is trying to optimize things for file-level access, it's not guaranteed. For a bootable device with partitions, dd is safest.
Hello Kamil-
I did not read the original question closely enough, apologies..
If you have a line that you can type manually into grub on the existing system and it works to boot openwrt, you can add the line to your grub boot menu.
If it's a debian/ubuntu derivative, edit /etc/grub.d/40_custom to add a menu entry. (I'm leaving out the exact details of that because I don't have a working one in front of me) add your grub boot entry there. Then check /etc/default/grub to make sure the timeout is not zero. When you have those done, do an
update-grub
Then you can reboot and you'll have grub as a menu entry. If it's working you can change the default in /etc/grub/default and run update-grub again to make openwrt the default boot option.
For redhat variants, it will be different of course, but hopefully this will give you enough clues to look up adding a custom grub entry.
On linux, /dev/sda is a file. There is no distinction between that and a block device, as far as writing into it is concerned - at least AFAIK. If you have a reliable source that claims otherwise then bring it on. In the meantime:
Well, it's represented as a file, but it's not actually a file. Files can be physically fragmented, can have 'holes', and can be written to and read from in arbitrary amounts.
When you use '>' you're writing to it using the shell. The shell is only able to write to a block device using a character stream because that's being handled by VFS. VFS is pretty smart these days, so it may not make any real difference, but it does things like caching, etc, that are not always visible.
So, to play it safe, I use dd because it writes in chunks that are multiples of the physical block size, and it is the tool for that purpose. If I'm writing to a device that I want to boot, I'm going to play it safe and use what I know is going to work every time.
The OpenWRT docs for x86 use dd: https://openwrt.org/docs/guide-user/installation/openwrt_x86
They're using bs=1m, which is a multiple of 4096 (base two!)
In the end, if you like using the shell or cat to write to block files, that's your preference. Just remember to do a 'sync'!