From 622cfc673ab2e97001ed394f8cd6d0425d8f3378 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 12 Apr 2015 20:20:01 +0200 Subject: luci-mod-admin-full: simply fstab configuration Simplify fstab setup by offering hints for uuid/label and device node options. Fix rootfs handling logic by removing obsolete references to the "is_rootfs" option and offering "/" and "/overlay" choices for the mountpoint instead. Signed-off-by: Jo-Philipp Wich --- .../luasrc/model/cbi/admin_system/fstab/mount.lua | 104 +++++++++++++++------ 1 file changed, 74 insertions(+), 30 deletions(-) (limited to 'modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/fstab') diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/fstab/mount.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/fstab/mount.lua index 3944690071..54beb63b42 100644 --- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/fstab/mount.lua +++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/fstab/mount.lua @@ -4,20 +4,32 @@ local fs = require "nixio.fs" local util = require "nixio.util" -local has_extroot = fs.access("/sbin/block") local has_fscheck = fs.access("/usr/sbin/e2fsck") -local devices = {} -util.consume((fs.glob("/dev/sd*")), devices) -util.consume((fs.glob("/dev/hd*")), devices) -util.consume((fs.glob("/dev/scd*")), devices) -util.consume((fs.glob("/dev/mmc*")), devices) +local block = io.popen("block info", "r") +local ln, dev, devices = nil, nil, {} -local size = {} -for i, dev in ipairs(devices) do - local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6)))) - size[dev] = s and math.floor(s / 2048) -end +repeat + ln = block:read("*l") + dev = ln and ln:match("^/dev/(.-):") + + if dev then + local e, s, key, val = { } + + for key, val in ln:gmatch([[(%w+)="(.-)"]]) do + e[key:lower()] = val + end + + s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev))) + + e.dev = "/dev/%s" % dev + e.size = s and math.floor(s / 2048) + + devices[#devices+1] = e + end +until not ln + +block:close() m = Map("fstab", translate("Mount Points - Mount Entry")) @@ -41,29 +53,71 @@ mount:tab("advanced", translate("Advanced Settings")) mount:taboption("general", Flag, "enabled", translate("Enable this mount")).rmempty = false -o = mount:taboption("general", Value, "device", translate("Device"), - translate("The device file of the memory or partition (e.g. /dev/sda1)")) +o = mount:taboption("general", Value, "uuid", translate("UUID"), + translate("If specified, mount the device by its UUID instead of a fixed device node")) for i, d in ipairs(devices) do - o:value(d, size[d] and "%s (%s MB)" % {d, size[d]}) + if d.uuid then + o:value(d.uuid, "%s (%s, %d MB)" %{ d.uuid, d.dev, d.size }) + end end -o = mount:taboption("advanced", Value, "uuid", translate("UUID"), - translate("If specified, mount the device by its UUID instead of a fixed device node")) +o:value("", translate("-- match by label --")) + -o = mount:taboption("advanced", Value, "label", translate("Label"), +o = mount:taboption("general", Value, "label", translate("Label"), translate("If specified, mount the device by the partition label instead of a fixed device node")) +o:depends("uuid", "") + +for i, d in ipairs(devices) do + if d.label then + o:value(d.label, "%s (%s, %d MB)" %{ d.label, d.dev, d.size }) + end +end + +o:value("", translate("-- match by device --")) + + +o = mount:taboption("general", Value, "device", translate("Device"), + translate("The device file of the memory or partition (e.g. /dev/sda1)")) + +o:depends({ uuid = "", label = "" }) + +for i, d in ipairs(devices) do + o:value(d.dev, "%s (%d MB)" %{ d.dev, d.size }) +end + o = mount:taboption("general", Value, "target", translate("Mount point"), translate("Specifies the directory the device is attached to")) -o:depends("is_rootfs", "") +o:value("/", translate("Use as root filesystem (/)")) +o:value("/overlay", translate("Use as external overlay (/overlay)")) + + +o = mount:taboption("general", DummyValue, "__notice", translate("Root preparation")) +o:depends("target", "/") +o.rawhtml = true +o.default = [[ +

%s

mkdir -p /tmp/introot
+mkdir -p /tmp/extroot
+mount --bind / /tmp/introot
+mount /dev/sda1 /tmp/extroot
+tar -C /tmp/intproot -cvf - . | tar -C /tmp/extroot -xf -
+umount /tmp/introot
+umount /tmp/extroot
+]] %{ + translate("Make sure to clone the root filesystem using something like the commands below:"), + +} -o = mount:taboption("general", Value, "fstype", translate("Filesystem"), +o = mount:taboption("advanced", Value, "fstype", translate("Filesystem"), translate("The filesystem that was used to format the memory (e.g. ext3)")) +o:value("", "auto") + local fs for fs in io.lines("/proc/filesystems") do fs = fs:match("%S+") @@ -79,18 +133,8 @@ o = mount:taboption("advanced", Value, "options", translate("Mount options"), o.placeholder = "defaults" -if has_extroot then - o = mount:taboption("general", Flag, "is_rootfs", translate("Use as root filesystem"), - translate("Configures this mount as overlay storage for block-extroot")) - - o:depends("fstype", "jffs") - o:depends("fstype", "ext2") - o:depends("fstype", "ext3") - o:depends("fstype", "ext4") -end - if has_fscheck then - o = mount:taboption("general", Flag, "enabled_fsck", translate("Run filesystem check"), + o = mount:taboption("advanced", Flag, "enabled_fsck", translate("Run filesystem check"), translate("Run a filesystem check before mounting the device")) end -- cgit v1.2.3