add disk
This commit is contained in:
commit
386bbd0dfd
82
CMakeLists.txt
Normal file
82
CMakeLists.txt
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
|
||||||
|
# dear god
|
||||||
|
project(lindows)
|
||||||
|
|
||||||
|
# find our programs
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake.d/")
|
||||||
|
find_package(NTFS3g REQUIRED)
|
||||||
|
find_package(CoreUtils REQUIRED)
|
||||||
|
find_package(MTools REQUIRED)
|
||||||
|
|
||||||
|
# make c drive mount point
|
||||||
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lindows_c")
|
||||||
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lindows_efi")
|
||||||
|
|
||||||
|
# this should probably be a shell script, i unfortunately do not care
|
||||||
|
add_custom_command(OUTPUT lindows_c.img
|
||||||
|
# create empty 16MiB disk image
|
||||||
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
|
if=/dev/zero
|
||||||
|
of=lindows_c.img
|
||||||
|
bs=1M
|
||||||
|
count=16
|
||||||
|
# format disk with new NTFS filesystem
|
||||||
|
COMMAND "${NTFS3g_Mkfs_EXECUTABLE}" ARGS -F # scary!
|
||||||
|
-L Windows
|
||||||
|
./lindows_c.img
|
||||||
|
# mount filesystem
|
||||||
|
COMMAND "${NTFS3g_Mount_EXECUTABLE}" ARGS
|
||||||
|
-o no_def_opts
|
||||||
|
lindows_c.img
|
||||||
|
lindows_c
|
||||||
|
|
||||||
|
# create dirs
|
||||||
|
COMMAND mkdir ARGS lindows_c/Windows
|
||||||
|
COMMAND mkdir ARGS lindows_c/Users
|
||||||
|
|
||||||
|
# unmount filesystem
|
||||||
|
COMMAND "umount" ARGS lindows_c
|
||||||
|
)
|
||||||
|
|
||||||
|
# this makes the efi system partition
|
||||||
|
add_custom_command(OUTPUT lindows_efi.img
|
||||||
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
|
if=/dev/zero
|
||||||
|
of=lindows_efi.img
|
||||||
|
bs=1M
|
||||||
|
count=16
|
||||||
|
COMMAND "${MTools_Format_EXECUTABLE}" ARGS -F -i lindows_efi.img
|
||||||
|
)
|
||||||
|
|
||||||
|
# make the full disk image
|
||||||
|
add_custom_command(OUTPUT lindows.img
|
||||||
|
COMMAND echo ARGS label: gpt > disk.sfdisk
|
||||||
|
COMMAND echo ARGS unit: sectors >> disk.sfdisk
|
||||||
|
COMMAND echo ARGS 1M 16M C12A7328-F81F-11D2-BA4B-00A0C93EC93B - >> disk.sfdisk
|
||||||
|
COMMAND echo ARGS 17M 16M EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 - >> disk.sfdisk
|
||||||
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
|
if=/dev/zero
|
||||||
|
of=lindows.img
|
||||||
|
bs=1M
|
||||||
|
count=64
|
||||||
|
# partition disk
|
||||||
|
COMMAND sfdisk ARGS lindows.img < disk.sfdisk
|
||||||
|
# write partitions
|
||||||
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
|
if=lindows_efi.img
|
||||||
|
of=lindows.img
|
||||||
|
bs=1M
|
||||||
|
count=16
|
||||||
|
seek=1
|
||||||
|
COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS
|
||||||
|
if=lindows_c.img
|
||||||
|
of=lindows.img
|
||||||
|
bs=1M
|
||||||
|
count=16
|
||||||
|
seek=17
|
||||||
|
DEPENDS lindows_c.img lindows_efi.img
|
||||||
|
BYPRODUCTS disk.sfdisk
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(lindows ALL DEPENDS lindows.img)
|
47
cmake.d/FindCoreUtils.cmake
Normal file
47
cmake.d/FindCoreUtils.cmake
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#[=============================[.rst:
|
||||||
|
FindCoreUtils
|
||||||
|
----------
|
||||||
|
|
||||||
|
finds coreutils. crazy, isnt it?
|
||||||
|
|
||||||
|
Imported Targets
|
||||||
|
^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Provides the following imported targets:
|
||||||
|
|
||||||
|
``CoreUtils::dd``
|
||||||
|
The dd command
|
||||||
|
|
||||||
|
Result Variables
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Defines the following variables:
|
||||||
|
|
||||||
|
``CoreUtils_FOUND``
|
||||||
|
True if the system has coreutils
|
||||||
|
``CoreUtils_dd_EXECUTABLE``
|
||||||
|
Path to dd
|
||||||
|
|
||||||
|
#]=============================]
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
# dd
|
||||||
|
find_program(CoreUtils_dd_EXECUTABLE
|
||||||
|
NAMES dd
|
||||||
|
)
|
||||||
|
|
||||||
|
find_package_handle_standard_args(CoreUtils
|
||||||
|
FOUND_VAR CoreUtils_FOUND
|
||||||
|
REQUIRED_VARS
|
||||||
|
CoreUtils_dd_EXECUTABLE
|
||||||
|
)
|
||||||
|
|
||||||
|
# coreutils really only looks good lowercase, but it doesnt fit with cmakes other stuff then
|
||||||
|
if (CoreUtils_Found)
|
||||||
|
# add dd
|
||||||
|
add_executable(CoreUtils::dd UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(CoreUtils::dd PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${CoreUtils_dd_EXECUTABLE}"
|
||||||
|
)
|
||||||
|
endif()
|
28
cmake.d/FindMTools.cmake
Normal file
28
cmake.d/FindMTools.cmake
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#[=============================[.rst:
|
||||||
|
FindMTools
|
||||||
|
----------
|
||||||
|
|
||||||
|
finds mtools. holy crap wow.
|
||||||
|
|
||||||
|
Result Variables
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Defines the following variables:
|
||||||
|
|
||||||
|
``MTools_FOUND``
|
||||||
|
True if the system has mtools
|
||||||
|
``MTools_Format_EXECUTABLE``
|
||||||
|
Path to mformat
|
||||||
|
|
||||||
|
#]=============================]
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
# mformat
|
||||||
|
find_program(MTools_Format_EXECUTABLE NAMES mformat)
|
||||||
|
|
||||||
|
find_package_handle_standard_args(MTools
|
||||||
|
FOUND_VAR MTools_FOUND
|
||||||
|
REQUIRED_VARS
|
||||||
|
MTools_Format_EXECUTABLE
|
||||||
|
)
|
34
cmake.d/FindNTFS3g.cmake
Normal file
34
cmake.d/FindNTFS3g.cmake
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#[=============================[.rst:
|
||||||
|
FindNTFS3g
|
||||||
|
----------
|
||||||
|
|
||||||
|
finds nsfs-3g. who woulda guessed.
|
||||||
|
|
||||||
|
Result Variables
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Defines the following variables:
|
||||||
|
|
||||||
|
``NTFS3g_FOUND``
|
||||||
|
True if the system has ntfs-3g
|
||||||
|
``NTFS3g_Mkfs_EXECUTABLE``
|
||||||
|
Path to mkfs.ntfs
|
||||||
|
``NTFS3g_Mount_EXECUTABLE``
|
||||||
|
Path to ntfs-3g
|
||||||
|
|
||||||
|
#]=============================]
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
# mkfs.ntfs
|
||||||
|
find_program(NTFS3g_Mkfs_EXECUTABLE NAMES mkfs.ntfs)
|
||||||
|
|
||||||
|
# ntfs-3g
|
||||||
|
find_program(NTFS3g_Mount_EXECUTABLE NAMES ntfs-3g)
|
||||||
|
|
||||||
|
find_package_handle_standard_args(NTFS3g
|
||||||
|
FOUND_VAR NTFS3g_FOUND
|
||||||
|
REQUIRED_VARS
|
||||||
|
NTFS3g_Mkfs_EXECUTABLE
|
||||||
|
NTFS3g_Mount_EXECUTABLE
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user