Modulo de data
This commit is contained in:
parent
4b071f0253
commit
9453a03815
6 changed files with 76 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ v00001/
|
||||||
boot/
|
boot/
|
||||||
image.squashfs
|
image.squashfs
|
||||||
cache/
|
cache/
|
||||||
|
tmp.qcow2
|
||||||
|
|
10
alpine.lua
10
alpine.lua
|
@ -46,6 +46,16 @@ function alpine.mkdir(rootfs_path, path)
|
||||||
if not (status == 0) then return status end
|
if not (status == 0) then return status end
|
||||||
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)
|
function alpine.write_file(rootfs_path, path, content)
|
||||||
local real_path = rootfs_path..path
|
local real_path = rootfs_path..path
|
||||||
|
|
||||||
|
|
51
modules/data.lua
Normal file
51
modules/data.lua
Normal 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")
|
|
@ -23,8 +23,6 @@ modules.runit = {
|
||||||
add_service = add_service,
|
add_service = add_service,
|
||||||
}
|
}
|
||||||
|
|
||||||
modules.fstab.add_mount("tmpfs /var/log tmpfs defaults 0 0")
|
|
||||||
|
|
||||||
-- Estos scripts fueron robados de Void Linux
|
-- Estos scripts fueron robados de Void Linux
|
||||||
add_executable("/etc/runit/functions", [[
|
add_executable("/etc/runit/functions", [[
|
||||||
msg() {
|
msg() {
|
||||||
|
@ -235,6 +233,9 @@ fi
|
||||||
|
|
||||||
msg "Mounting all non-network filesystems..."
|
msg "Mounting all non-network filesystems..."
|
||||||
mount -a -t "nosysfs,nonfs,nonfs4,nosmbfs,nocifs" -O no_netdev || emergency_shell
|
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", [[
|
add_executable("/etc/runit/core-services/04-swap.sh", [[
|
||||||
|
@ -255,6 +256,8 @@ msg "Setting hostname..."
|
||||||
hostname -F /etc/hostname
|
hostname -F /etc/hostname
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
modules.data.add_data_file("/data/dmesg.log", "/var/log/dmesg.log", "root", "root")
|
||||||
|
|
||||||
-- Initial boot
|
-- Initial boot
|
||||||
add_executable("/etc/runit/1", [[#!/bin/sh
|
add_executable("/etc/runit/1", [[#!/bin/sh
|
||||||
|
|
||||||
|
|
6
qemu.sh
6
qemu.sh
|
@ -5,8 +5,12 @@ if test "$NOGRAPHIC" = true; then
|
||||||
qemuappend="-nographic"
|
qemuappend="-nographic"
|
||||||
fi
|
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/
|
sudo chown root:$(id -u) -R boot/ && sudo chmod g+rw -R boot/
|
||||||
qemu-system-x86_64 -enable-kvm -m 2048 \
|
qemu-system-x86_64 -enable-kvm -m 2048 \
|
||||||
-drive file=image.squashfs,media=disk \
|
-drive file=image.squashfs,media=disk \
|
||||||
|
-drive file=tmp.qcow2,media=disk \
|
||||||
-kernel boot/vmlinuz-virt -initrd boot/initramfs-virt \
|
-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
|
||||||
|
|
|
@ -29,6 +29,9 @@ end
|
||||||
function mkdir(path)
|
function mkdir(path)
|
||||||
utils.expect_nil(alpine.mkdir(root, path))
|
utils.expect_nil(alpine.mkdir(root, path))
|
||||||
end
|
end
|
||||||
|
function touch(path)
|
||||||
|
utils.expect_nil(alpine.touch(root, path))
|
||||||
|
end
|
||||||
|
|
||||||
print("=> Initializing rootfs...")
|
print("=> Initializing rootfs...")
|
||||||
utils.expect_nil(alpine.init_rootfs(root, alpine_base_version, alpine_version))
|
utils.expect_nil(alpine.init_rootfs(root, alpine_base_version, alpine_version))
|
||||||
|
@ -38,6 +41,7 @@ local function module(name)
|
||||||
require("modules/" .. name)
|
require("modules/" .. name)
|
||||||
end
|
end
|
||||||
module "fstab"
|
module "fstab"
|
||||||
|
module "data"
|
||||||
module "kernel"
|
module "kernel"
|
||||||
module "runit"
|
module "runit"
|
||||||
module "hostname"
|
module "hostname"
|
||||||
|
|
Loading…
Reference in a new issue