Modulo de data

This commit is contained in:
Cat /dev/Nulo 2022-06-18 12:05:18 -03:00
parent 4b071f0253
commit 9453a03815
6 changed files with 76 additions and 3 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ v00001/
boot/
image.squashfs
cache/
tmp.qcow2

View File

@ -46,6 +46,16 @@ function alpine.mkdir(rootfs_path, path)
if not (status == 0) then return status end
end
function alpine.touch(rootfs_path, path)
local real_path = rootfs_path..path
local cmd = t("touch '{{real_path}}'", { real_path = real_path })
-- XXX: Usar lua-posix
local status = os.execute(cmd)
if not (status == 0) then return status end
end
function alpine.write_file(rootfs_path, path, content)
local real_path = rootfs_path..path

51
modules/data.lua Normal file
View File

@ -0,0 +1,51 @@
local t = require "../utils/templater"
local dirs = {}
local function generate_mount_data()
local string = "#!/bin/sh\n"
for i=1,#dirs do
local dir = dirs[i]
if dir.type == "file" then
touch(dir.mountpoint)
string = string .. t([[
touch -a '{{path}}' || exit 1
mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || exit 1
]],
dir
)
elseif dir.type == "dir" then
mkdir(dir.mountpoint)
string = string .. t([[
mkdir -p '{{path}}' || exit 1
mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || exit 1
]],
dir
)
end
end
add_file("/usr/local/bin/mount-data", string)
chmod("/usr/local/bin/mount-data", 700)
end
local function add_data_dir(path, mountpoint, uid, gid)
table.insert(dirs, {
type = "dir",
path = path, mountpoint = mountpoint, uid = uid, gid = gid
})
generate_mount_data()
end
local function add_data_file(path, mountpoint, uid, gid)
table.insert(dirs, {
type = "file",
path = path, mountpoint = mountpoint, uid = uid, gid = gid
})
generate_mount_data()
end
modules.data = {
add_data_dir = add_data_dir,
add_data_file = add_data_file,
}
mkdir("/data")
-- XXX: hardcodeado
modules.fstab.add_mount("/dev/sdb /data ext4 defaults 0 0")

View File

@ -23,8 +23,6 @@ modules.runit = {
add_service = add_service,
}
modules.fstab.add_mount("tmpfs /var/log tmpfs defaults 0 0")
-- Estos scripts fueron robados de Void Linux
add_executable("/etc/runit/functions", [[
msg() {
@ -235,6 +233,9 @@ fi
msg "Mounting all non-network filesystems..."
mount -a -t "nosysfs,nonfs,nonfs4,nosmbfs,nocifs" -O no_netdev || emergency_shell
# data module
msg "Creating and mounting data directories..."
/usr/local/bin/mount-data || emergency_shell
]])
add_executable("/etc/runit/core-services/04-swap.sh", [[
@ -255,6 +256,8 @@ msg "Setting hostname..."
hostname -F /etc/hostname
]])
modules.data.add_data_file("/data/dmesg.log", "/var/log/dmesg.log", "root", "root")
-- Initial boot
add_executable("/etc/runit/1", [[#!/bin/sh

View File

@ -5,8 +5,12 @@ if test "$NOGRAPHIC" = true; then
qemuappend="-nographic"
fi
qemu-img create -f qcow2 tmp.qcow2 1G
mkfs.ext4 tmp.qcow2
sudo chown root:$(id -u) -R boot/ && sudo chmod g+rw -R boot/
qemu-system-x86_64 -enable-kvm -m 2048 \
-drive file=image.squashfs,media=disk \
-drive file=tmp.qcow2,media=disk \
-kernel boot/vmlinuz-virt -initrd boot/initramfs-virt \
-append "root=/dev/sda rootfstype=squashfs init=/sbin/runit-init $append" $qemuappend
-append "root=/dev/sda rootfstype=squashfs modules=ext4 init=/sbin/runit-init $append" $qemuappend

View File

@ -29,6 +29,9 @@ end
function mkdir(path)
utils.expect_nil(alpine.mkdir(root, path))
end
function touch(path)
utils.expect_nil(alpine.touch(root, path))
end
print("=> Initializing rootfs...")
utils.expect_nil(alpine.init_rootfs(root, alpine_base_version, alpine_version))
@ -38,6 +41,7 @@ local function module(name)
require("modules/" .. name)
end
module "fstab"
module "data"
module "kernel"
module "runit"
module "hostname"