grub
This commit is contained in:
parent
386bbd0dfd
commit
dbdc494392
@ -1,5 +1,8 @@
|
|||||||
cmake_minimum_required(VERSION 3.28)
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
|
||||||
|
# grab commands
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
# dear god
|
# dear god
|
||||||
project(lindows)
|
project(lindows)
|
||||||
|
|
||||||
@ -8,19 +11,47 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake.d/")
|
|||||||
find_package(NTFS3g REQUIRED)
|
find_package(NTFS3g REQUIRED)
|
||||||
find_package(CoreUtils REQUIRED)
|
find_package(CoreUtils REQUIRED)
|
||||||
find_package(MTools REQUIRED)
|
find_package(MTools REQUIRED)
|
||||||
|
# TODO: find_package for python (for GRUB)
|
||||||
|
# TODO: find_package for bison (for GRUB)
|
||||||
|
# TODO: find_package for flex (for GRUB)
|
||||||
|
# TODO: find_package for sfdisk (for disk image generation)
|
||||||
|
# TODO: find_package for mkfs.vfat (for GRUB)
|
||||||
|
# TODO: add mmd to mtools
|
||||||
|
# TODO: add mkdir to coreutils
|
||||||
|
|
||||||
# make c drive mount point
|
# make c drive mount point
|
||||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lindows_c")
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lindows_c")
|
||||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lindows_efi")
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lindows_efi")
|
||||||
|
|
||||||
|
# build grub
|
||||||
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/grub")
|
||||||
|
ExternalProject_Add(GRUB
|
||||||
|
GIT_REPOSITORY "https://git.savannah.gnu.org/git/grub.git"
|
||||||
|
GIT_TAG "grub-2.12"
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
GIT_PROGRESS TRUE
|
||||||
|
UPDATE_COMMAND "" # the commit is fixed, we will never need to update
|
||||||
|
# this should make it stop rebuilding every `make`
|
||||||
|
CONFIGURE_COMMAND ./bootstrap
|
||||||
|
COMMAND ./configure
|
||||||
|
--host=x86_64-pc-linux-gnu
|
||||||
|
--target=x86_64
|
||||||
|
--with-platform=efi
|
||||||
|
--disable-efiemu
|
||||||
|
--prefix=${CMAKE_CURRENT_BINARY_DIR}/grub
|
||||||
|
BUILD_COMMAND make
|
||||||
|
BUILD_IN_SOURCE TRUE
|
||||||
|
INSTALL_COMMAND make install
|
||||||
|
)
|
||||||
|
|
||||||
# this should probably be a shell script, i unfortunately do not care
|
# this should probably be a shell script, i unfortunately do not care
|
||||||
add_custom_command(OUTPUT lindows_c.img
|
add_custom_command(OUTPUT lindows_c.img
|
||||||
# create empty 16MiB disk image
|
# create empty 128MiB disk image
|
||||||
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
if=/dev/zero
|
if=/dev/zero
|
||||||
of=lindows_c.img
|
of=lindows_c.img
|
||||||
bs=1M
|
bs=1M
|
||||||
count=16
|
count=128
|
||||||
# format disk with new NTFS filesystem
|
# format disk with new NTFS filesystem
|
||||||
COMMAND "${NTFS3g_Mkfs_EXECUTABLE}" ARGS -F # scary!
|
COMMAND "${NTFS3g_Mkfs_EXECUTABLE}" ARGS -F # scary!
|
||||||
-L Windows
|
-L Windows
|
||||||
@ -31,8 +62,18 @@ add_custom_command(OUTPUT lindows_c.img
|
|||||||
lindows_c.img
|
lindows_c.img
|
||||||
lindows_c
|
lindows_c
|
||||||
|
|
||||||
# create dirs
|
# create system folders
|
||||||
COMMAND mkdir ARGS lindows_c/Windows
|
COMMAND mkdir ARGS lindows_c/Windows
|
||||||
|
COMMAND mkdir ARGS lindows_c/Windows/GRUB
|
||||||
|
COMMAND mkdir ARGS lindows_c/Windows/GRUB/x86_64-efi
|
||||||
|
|
||||||
|
# grub stuff
|
||||||
|
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/grub/lib/grub/x86_64-efi/* lindows_c/Windows/GRUB/x86_64-efi
|
||||||
|
|
||||||
|
# copy linux kernel from host please replace with custom kernel
|
||||||
|
COMMAND cp ARGS /boot/vmlinuz-linux lindows_c/Windows/vmlinuz-linux
|
||||||
|
|
||||||
|
# create users folder
|
||||||
COMMAND mkdir ARGS lindows_c/Users
|
COMMAND mkdir ARGS lindows_c/Users
|
||||||
|
|
||||||
# unmount filesystem
|
# unmount filesystem
|
||||||
@ -41,25 +82,36 @@ add_custom_command(OUTPUT lindows_c.img
|
|||||||
|
|
||||||
# this makes the efi system partition
|
# this makes the efi system partition
|
||||||
add_custom_command(OUTPUT lindows_efi.img
|
add_custom_command(OUTPUT lindows_efi.img
|
||||||
|
COMMAND mkdir ARGS -p lindows_efi/
|
||||||
|
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/grub/bin/grub-mkimage" ARGS
|
||||||
|
-p /Windows/GRUB
|
||||||
|
-O x86_64-efi
|
||||||
|
-o lindows_efi/grubx64.efi
|
||||||
|
-c ${CMAKE_CURRENT_SOURCE_DIR}/src/grub/grub-early.cfg
|
||||||
|
part_gpt ntfs
|
||||||
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
if=/dev/zero
|
if=/dev/zero
|
||||||
of=lindows_efi.img
|
of=lindows_efi.img
|
||||||
bs=1M
|
bs=1M
|
||||||
count=16
|
count=33
|
||||||
COMMAND "${MTools_Format_EXECUTABLE}" ARGS -F -i lindows_efi.img
|
COMMAND mkfs.vfat lindows_efi.img -F 32
|
||||||
|
COMMAND mmd -i lindows_efi.img ::/EFI
|
||||||
|
COMMAND mmd -i lindows_efi.img ::/EFI/BOOT
|
||||||
|
COMMAND ${MTools_Copy_EXECUTABLE} -i lindows_efi.img lindows_efi/grubx64.efi ::/EFI/BOOT/BOOTX64.EFI
|
||||||
|
DEPENDS src/grub/grub-early.cfg
|
||||||
)
|
)
|
||||||
|
|
||||||
# make the full disk image
|
# make the full disk image
|
||||||
add_custom_command(OUTPUT lindows.img
|
add_custom_command(OUTPUT lindows.img
|
||||||
COMMAND echo ARGS label: gpt > disk.sfdisk
|
COMMAND echo ARGS label: gpt > disk.sfdisk
|
||||||
COMMAND echo ARGS unit: sectors >> disk.sfdisk
|
COMMAND echo ARGS unit: sectors >> disk.sfdisk
|
||||||
COMMAND echo ARGS 1M 16M C12A7328-F81F-11D2-BA4B-00A0C93EC93B - >> disk.sfdisk
|
COMMAND echo ARGS 1MiB 33MiB C12A7328-F81F-11D2-BA4B-00A0C93EC93B - >> disk.sfdisk
|
||||||
COMMAND echo ARGS 17M 16M EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 - >> disk.sfdisk
|
COMMAND echo ARGS 34MiB 128MiB EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 - >> disk.sfdisk
|
||||||
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
if=/dev/zero
|
if=/dev/zero
|
||||||
of=lindows.img
|
of=lindows.img
|
||||||
bs=1M
|
bs=1M
|
||||||
count=64
|
count=256
|
||||||
# partition disk
|
# partition disk
|
||||||
COMMAND sfdisk ARGS lindows.img < disk.sfdisk
|
COMMAND sfdisk ARGS lindows.img < disk.sfdisk
|
||||||
# write partitions
|
# write partitions
|
||||||
@ -67,14 +119,16 @@ add_custom_command(OUTPUT lindows.img
|
|||||||
if=lindows_efi.img
|
if=lindows_efi.img
|
||||||
of=lindows.img
|
of=lindows.img
|
||||||
bs=1M
|
bs=1M
|
||||||
count=16
|
count=33
|
||||||
seek=1
|
seek=1
|
||||||
|
conv=notrunc
|
||||||
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
if=lindows_c.img
|
if=lindows_c.img
|
||||||
of=lindows.img
|
of=lindows.img
|
||||||
bs=1M
|
bs=1M
|
||||||
count=16
|
count=128
|
||||||
seek=17
|
seek=34
|
||||||
|
conv=notrunc
|
||||||
DEPENDS lindows_c.img lindows_efi.img
|
DEPENDS lindows_c.img lindows_efi.img
|
||||||
BYPRODUCTS disk.sfdisk
|
BYPRODUCTS disk.sfdisk
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,8 @@ Defines the following variables:
|
|||||||
True if the system has mtools
|
True if the system has mtools
|
||||||
``MTools_Format_EXECUTABLE``
|
``MTools_Format_EXECUTABLE``
|
||||||
Path to mformat
|
Path to mformat
|
||||||
|
``MTools_Copy_EXECUTABLE``
|
||||||
|
Path to mcopy
|
||||||
|
|
||||||
#]=============================]
|
#]=============================]
|
||||||
|
|
||||||
@ -21,8 +23,12 @@ include(FindPackageHandleStandardArgs)
|
|||||||
# mformat
|
# mformat
|
||||||
find_program(MTools_Format_EXECUTABLE NAMES mformat)
|
find_program(MTools_Format_EXECUTABLE NAMES mformat)
|
||||||
|
|
||||||
|
# mcopy
|
||||||
|
find_program(MTools_Copy_EXECUTABLE NAMES mcopy)
|
||||||
|
|
||||||
find_package_handle_standard_args(MTools
|
find_package_handle_standard_args(MTools
|
||||||
FOUND_VAR MTools_FOUND
|
FOUND_VAR MTools_FOUND
|
||||||
REQUIRED_VARS
|
REQUIRED_VARS
|
||||||
MTools_Format_EXECUTABLE
|
MTools_Format_EXECUTABLE
|
||||||
|
MTools_Copy_EXECUTABLE
|
||||||
)
|
)
|
||||||
|
2
src/grub/grub-early.cfg
Normal file
2
src/grub/grub-early.cfg
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
set root=(hd0,gpt2)
|
||||||
|
set prefix=($root)/Windows/GRUB
|
Loading…
x
Reference in New Issue
Block a user