1 -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local fs = require "nixio.fs"
5 local util = require "nixio.util"
7 local has_fscheck = fs.access("/usr/sbin/e2fsck")
9 local block = io.popen("block info", "r")
10 local ln, dev, devices = nil, nil, {}
14 dev = ln and ln:match("^/dev/(.-):")
17 local e, s, key, val = { }
19 for key, val in ln:gmatch([[(%w+)="(.-)"]]) do
23 s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev)))
25 e.dev = "/dev/%s" % dev
26 e.size = s and math.floor(s / 2048)
28 devices[#devices+1] = e
35 m = Map("fstab", translate("Mount Points - Mount Entry"))
36 m.redirect = luci.dispatcher.build_url("admin/system/fstab")
38 if not arg[1] or m.uci:get("fstab", arg[1]) ~= "mount" then
39 luci.http.redirect(m.redirect)
45 mount = m:section(NamedSection, arg[1], "mount", translate("Mount Entry"))
46 mount.anonymous = true
47 mount.addremove = false
49 mount:tab("general", translate("General Settings"))
50 mount:tab("advanced", translate("Advanced Settings"))
53 mount:taboption("general", Flag, "enabled", translate("Enable this mount")).rmempty = false
56 o = mount:taboption("general", Value, "uuid", translate("UUID"),
57 translate("If specified, mount the device by its UUID instead of a fixed device node"))
59 o:value("", translate("-- match by uuid --"))
61 for i, d in ipairs(devices) do
62 if d.uuid and d.size then
63 o:value(d.uuid, "%s (%s, %d MB)" %{ d.uuid, d.dev, d.size })
65 o:value(d.uuid, "%s (%s)" %{ d.uuid, d.dev })
70 o = mount:taboption("general", Value, "label", translate("Label"),
71 translate("If specified, mount the device by the partition label instead of a fixed device node"))
73 o:value("", translate("-- match by label --"))
77 for i, d in ipairs(devices) do
78 if d.label and d.size then
79 o:value(d.label, "%s (%s, %d MB)" %{ d.label, d.dev, d.size })
81 o:value(d.label, "%s (%s)" %{ d.label, d.dev })
86 o = mount:taboption("general", Value, "device", translate("Device"),
87 translate("The device file of the memory or partition (<abbr title=\"for example\">e.g.</abbr> <code>/dev/sda1</code>)"))
89 o:value("", translate("-- match by device --"))
91 o:depends({ uuid = "", label = "" })
93 for i, d in ipairs(devices) do
95 o:value(d.dev, "%s (%d MB)" %{ d.dev, d.size })
102 o = mount:taboption("general", Value, "target", translate("Mount point"),
103 translate("Specifies the directory the device is attached to"))
105 o:value("/", translate("Use as root filesystem (/)"))
106 o:value("/overlay", translate("Use as external overlay (/overlay)"))
109 o = mount:taboption("general", DummyValue, "__notice", translate("Root preparation"))
110 o:depends("target", "/")
113 <p>%s</p><pre>mkdir -p /tmp/introot
114 mkdir -p /tmp/extroot
115 mount --bind / /tmp/introot
116 mount /dev/sda1 /tmp/extroot
117 tar -C /tmp/introot -cvf - . | tar -C /tmp/extroot -xf -
119 umount /tmp/extroot</pre>
121 translate("Make sure to clone the root filesystem using something like the commands below:"),
126 o = mount:taboption("advanced", Value, "fstype", translate("Filesystem"),
127 translate("The filesystem that was used to format the memory (<abbr title=\"for example\">e.g.</abbr> <samp><abbr title=\"Third Extended Filesystem\">ext3</abbr></samp>)"))
132 for fs in io.lines("/proc/filesystems") do
134 if fs ~= "nodev" then
139 local ok, lines = pcall(io.lines, "/etc/filesystem")
147 o = mount:taboption("advanced", Value, "options", translate("Mount options"),
148 translate("See \"mount\" manpage for details"))
150 o.placeholder = "defaults"
154 o = mount:taboption("advanced", Flag, "enabled_fsck", translate("Run filesystem check"),
155 translate("Run a filesystem check before mounting the device"))