Compare commits

..

No commits in common. "5b033bf5ab42bc88fe20150a4adc9578ebdcff9c" and "7325ee1c0c9506e4dd974e656463af38b056dc7a" have entirely different histories.

17 changed files with 9 additions and 962 deletions

View File

@ -6,4 +6,3 @@ go.work.sum
modd.*conf modd.*conf
test-initrd* test-initrd*
test-initrd/**/* test-initrd/**/*
target

1
.gitignore vendored
View File

@ -5,4 +5,3 @@
/tmp /tmp
/go.work /go.work
/go.work.sum /go.work.sum
/target

569
Cargo.lock generated
View File

@ -1,569 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
[[package]]
name = "anstyle-parse"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
]
[[package]]
name = "anyhow"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "backtrace"
version = "0.3.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bytes"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
name = "cc"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "colorchoice"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
[[package]]
name = "env_filter"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"humantime",
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "gimli"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "indexmap"
version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "init"
version = "0.1.0"
dependencies = [
"anyhow",
"env_logger",
"log",
"serde",
"serde_json",
"serde_yaml",
"tokio",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
[[package]]
name = "itoa"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "libc"
version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "log"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
[[package]]
name = "memchr"
version = "2.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
[[package]]
name = "miniz_oxide"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
dependencies = [
"libc",
"wasi",
"windows-sys 0.48.0",
]
[[package]]
name = "object"
version = "0.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434"
dependencies = [
"memchr",
]
[[package]]
name = "pin-project-lite"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
[[package]]
name = "proc-macro2"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "ryu"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]]
name = "serde"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.9.34+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
dependencies = [
"indexmap",
"itoa",
"ryu",
"serde",
"unsafe-libyaml",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]]
name = "syn"
version = "2.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tokio"
version = "1.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"pin-project-lite",
"signal-hook-registry",
"tokio-macros",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-macros"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets 0.52.5",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm 0.52.5",
"windows_aarch64_msvc 0.52.5",
"windows_i686_gnu 0.52.5",
"windows_i686_gnullvm",
"windows_i686_msvc 0.52.5",
"windows_x86_64_gnu 0.52.5",
"windows_x86_64_gnullvm 0.52.5",
"windows_x86_64_msvc 0.52.5",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"

View File

@ -1,15 +0,0 @@
[package]
name = "init"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.86"
env_logger = "0.11.3"
log = "0.4.21"
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
serde_yaml = "0.9.34"
tokio = { version = "1.38.0", features = ["rt", "signal", "process", "macros"] }

View File

@ -1,17 +1,4 @@
# ------------------------------------------------------------------------ from golang:1.21.6-alpine3.19 as build
from rust:1.79.0-alpine3.20 as rust
run apk add --no-cache musl-dev # pkgconfig cryptsetup-dev lvm2-dev clang-dev clang-static
workdir /src
copy Cargo.* .
copy src src
run --mount=type=cache,id=novit-rs,target=/usr/local/cargo/registry \
--mount=type=cache,id=novit-rs-target,sharing=private,target=/src/target \
cargo build --release && cp target/release/init /
# ------------------------------------------------------------------------
from golang:1.22.4-alpine3.20 as build
workdir /src workdir /src
@ -24,7 +11,7 @@ run \
&& go build -o /go/bin/init -trimpath . && go build -o /go/bin/init -trimpath .
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
from alpine:3.20.0 as initrd from alpine:3.19.0 as initrd
run apk add --no-cache xz run apk add --no-cache xz
@ -35,15 +22,14 @@ run . /etc/os-release \
run apk add --no-cache -p . musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk run apk add --no-cache -p . musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk
run rm -rf usr/share/apk var/cache/apk run rm -rf usr/share/apk var/cache/apk
#copy --from=build /go/bin/init . copy --from=build /go/bin/init .
copy --from=rust /init .
# check viability # check viability
run chroot . /init hello run chroot /layer /init hello
run find |cpio -H newc -o >/initrd run find |cpio -H newc -o >/initrd
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
from alpine:3.20.0 from alpine:3.19.0
copy --from=initrd /initrd / copy --from=initrd /initrd /
entrypoint ["base64","/initrd"] entrypoint ["base64","/initrd"]

View File

@ -1,5 +0,0 @@
from rust:1.77.1-alpine as rust
run apk add --no-cache musl-dev
run apk add --no-cache musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk

View File

@ -1,2 +0,0 @@
from alpine:3.19.0
run apk add --no-cache musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk

View File

@ -1,27 +0,0 @@
set -ex
which podman &>/dev/null && docker=podman || docker=docker
mkdir -p empty
$docker build -t nv-rs-build --network=host -f Dockerfile.build empty
case $1 in
release)
opts=--release
bindir=target/release
;;
"")
bindir=target/debug
;;
*)
echo >&2 "invalid arg: $1"
exit 1
;;
esac
$docker run --rm -i --net=host --user=$UID \
nv-rs-build \
cargo build $opts
mkdir -p dist
cp $bindir/init dist/

View File

@ -1 +0,0 @@
target/debug/init

View File

@ -7,15 +7,8 @@ go.??? **/*.go {
prep: go build -o dist/ ./tools/... prep: go build -o dist/ ./tools/...
} }
**/*.rs Cargo.* { dist/init Dockerfile {
prep: cargo test prep: docker build -t novit-initrd-gen .
#prep: cargo build prep: docker run novit-initrd-gen |base64 -d >dist/initrd.new
prep: docker build --network host -t novit-initrd-gen . prep: mv dist/initrd.new dist/initrd
prep: docker run --net=host --rm novit-initrd-gen |base64 -d >dist/initrd.new
} }
#dist/init Dockerfile {
# prep: docker build --network host -t novit-initrd-gen .
# prep: docker run --net=host --rm novit-initrd-gen |base64 -d >dist/initrd.new
# prep: mv dist/initrd.new dist/initrd
#}

View File

@ -1,2 +0,0 @@
docker build -t nv-initrd-test -f Dockerfile.test empty
docker run -d --name nv-initrd-test -it --privileged -v $PWD:/src --workdir /src/test-initrd nv-initrd-test

View File

@ -1 +0,0 @@
pub mod config;

View File

@ -1,145 +0,0 @@
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Config {
anti_phishing_code: String,
keymap: Option<String>,
modules: String,
auths: Vec<Auth>,
networks: Vec<Network>,
#[serde(default)]
ssh: SSHServer,
#[serde(default)]
pre_lvm_crypt: Vec<CryptDev>,
#[serde(default)]
lvm: Vec<LvmVG>,
#[serde(default)]
crypt: Vec<CryptDev>,
bootstrap: Bootstrap,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Auth {
name: String,
#[serde(rename = "sshKey")]
ssh_key: String,
password: String,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Network {
name: String,
interfaces: Vec<NetworkInterface>,
script: String,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct NetworkInterface {
pub var: String,
pub n: i16,
pub regexps: Vec<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SSHServer {
listen: String,
keys: SSHKeys,
}
impl Default for SSHServer {
fn default() -> Self {
Self {
listen: "[::]:22".to_string(),
keys: SSHKeys::default(),
}
}
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SSHKeys {
dsa: String,
rsa: String,
ecdsa: String,
ed25519: String,
}
impl Default for SSHKeys {
fn default() -> Self {
Self {
dsa: "id_dsa".to_string(),
rsa: "id_rsa".to_string(),
ecdsa: "id_ecdsa".to_string(),
ed25519: "id_ed25519".to_string(),
}
}
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct LvmVG {
vg: String,
pvs: LvmPV,
#[serde(default)]
defaults: LvmLVDefaults,
lvs: Vec<LvmLV>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct LvmLVDefaults {
#[serde(default = "default_fs")]
fs: String,
raid: Option<Raid>,
}
impl Default for LvmLVDefaults {
fn default() -> Self {
Self {
fs: default_fs(),
raid: None,
}
}
}
fn default_fs() -> String {
"ext4".to_string()
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct LvmLV {
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
fs: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
raid: Option<Raid>,
#[serde(skip_serializing_if = "Option::is_none")]
size: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
extents: Option<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct LvmPV {
n: i16,
regexps: Vec<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct CryptDev {
name: String,
dev: Option<String>,
prefix: Option<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Raid {
mirrors: Option<u8>,
stripes: Option<u8>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Bootstrap {
dev: String,
seed: String,
}

View File

@ -1,27 +0,0 @@
use std::io;
use std::process::Command;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Report {
pub blockdevices: Vec<BlockDev>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct BlockDev {
pub name: String,
#[serde(rename = "maj:min")]
pub maj_min: String,
pub rm: bool,
pub size: String,
pub ro: bool,
#[serde(rename = "type")]
pub dev_type: String,
pub mountpoints: Vec<Option<String>>,
#[serde(default)]
pub children: Vec<BlockDev>,
}
pub fn report() -> io::Result<Report> {
let output = Command::new("lsblk").arg("--json").output()?;
Ok(serde_json::from_slice(output.stdout.as_slice()).unwrap())
}

View File

@ -1,84 +0,0 @@
use std::io;
use std::process::Command;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
struct Report {
report: Vec<ReportObj>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(untagged)]
enum ReportObj {
PV { pv: Vec<PV> },
VG { vg: Vec<VG> },
LV { lv: Vec<LV> },
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct PV {
pub pv_name: String,
pub vg_name: String,
pub pv_fmt: String,
pub pv_attr: String,
pub pv_size: String,
pub pv_free: String,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct VG {
pub vg_name: String,
pub pv_count: String,
pub lv_count: String,
pub snap_count: String,
pub vg_attr: String,
pub vg_size: String,
pub vg_free: String,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct LV {
lv_name: String,
vg_name: String,
lv_attr: String,
lv_size: String,
pool_lv: String,
origin: String,
data_percent: String,
metadata_percent: String,
move_pv: String,
mirror_log: String,
copy_percent: String,
convert_lv: String,
}
pub fn pvs() -> io::Result<Vec<PV>> {
report_cmd("pvs", |o| match o {
ReportObj::PV { pv } => Some(pv),
_ => None,
})
}
pub fn vgs() -> io::Result<Vec<VG>> {
report_cmd("vgs", |o| match o {
ReportObj::VG { vg } => Some(vg),
_ => None,
})
}
pub fn lvs() -> io::Result<Vec<LV>> {
report_cmd("lvs", |o| match o {
ReportObj::LV { lv } => Some(lv),
_ => None,
})
}
fn report_cmd<T>(cmd: &str, find: fn(ReportObj) -> Option<Vec<T>>) -> io::Result<Vec<T>> {
let output = Command::new(cmd).arg("--reportformat=json").output()?;
let report: Report = serde_json::from_slice(output.stdout.as_slice()).unwrap();
Ok(report
.report
.into_iter()
.filter_map(find)
.flatten()
.collect())
}

View File

@ -1,51 +0,0 @@
mod bootstrap;
mod lsblk;
mod lvm;
use anyhow::format_err;
use log::error;
use std::io::{self, Read, Write};
use std::process::exit;
use std::{env, fs};
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
if let None = env::var_os("RUST_LOG") {
env::set_var("RUST_LOG", "info");
}
env_logger::init();
if let Some(arg) = env::args().into_iter().nth(1) {
match arg.as_str() {
"hello" => println!("hello"),
_ => {
error!("invalid arg: {arg}");
exit(1);
}
};
exit(0);
}
let cfg = fs::read("config.yaml").map_err(|e| format_err!("failed to read config: {e}"))?;
let cfg: bootstrap::config::Config = serde_yaml::from_slice(cfg.as_slice())
.map_err(|e| format_err!("failed to parse config: {e}"))?;
serde_yaml::to_writer(io::stdout(), &cfg)?;
for pv in lvm::pvs().unwrap() {
println!("pv: {pv:?}");
}
for vg in lvm::vgs().unwrap() {
println!("vg: {vg:?}");
}
for lv in lvm::lvs().unwrap() {
println!("lv: {lv:?}");
}
println!("lsblk: {:?}", lsblk::report());
// TODO
Ok(())
}

View File

@ -1 +0,0 @@
../dist/init