mount.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local fs = require "nixio.fs"
  4. local util = require "nixio.util"
  5. local has_fscheck = fs.access("/usr/sbin/e2fsck")
  6. local block = io.popen("block info", "r")
  7. local ln, dev, devices = nil, nil, {}
  8. repeat
  9. ln = block:read("*l")
  10. dev = ln and ln:match("^/dev/(.-):")
  11. if dev then
  12. local e, s, key, val = { }
  13. for key, val in ln:gmatch([[(%w+)="(.-)"]]) do
  14. e[key:lower()] = val
  15. end
  16. s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev)))
  17. e.dev = "/dev/%s" % dev
  18. e.size = s and math.floor(s / 2048)
  19. devices[#devices+1] = e
  20. end
  21. until not ln
  22. block:close()
  23. m = Map("fstab", translate("Mount Points - Mount Entry"))
  24. m.redirect = luci.dispatcher.build_url("admin/system/fstab")
  25. if not arg[1] or m.uci:get("fstab", arg[1]) ~= "mount" then
  26. luci.http.redirect(m.redirect)
  27. return
  28. end
  29. mount = m:section(NamedSection, arg[1], "mount", translate("Mount Entry"))
  30. mount.anonymous = true
  31. mount.addremove = false
  32. mount:tab("general", translate("General Settings"))
  33. mount:tab("advanced", translate("Advanced Settings"))
  34. mount:taboption("general", Flag, "enabled", translate("Enable this mount")).rmempty = false
  35. o = mount:taboption("general", Value, "uuid", translate("UUID"),
  36. translate("If specified, mount the device by its UUID instead of a fixed device node"))
  37. for i, d in ipairs(devices) do
  38. if d.uuid and d.size then
  39. o:value(d.uuid, "%s (%s, %d MB)" %{ d.uuid, d.dev, d.size })
  40. elseif d.uuid then
  41. o:value(d.uuid, "%s (%s)" %{ d.uuid, d.dev })
  42. end
  43. end
  44. o:value("", translate("-- match by label --"))
  45. o = mount:taboption("general", Value, "label", translate("Label"),
  46. translate("If specified, mount the device by the partition label instead of a fixed device node"))
  47. o:depends("uuid", "")
  48. for i, d in ipairs(devices) do
  49. if d.label and d.size then
  50. o:value(d.label, "%s (%s, %d MB)" %{ d.label, d.dev, d.size })
  51. elseif d.label then
  52. o:value(d.label, "%s (%s)" %{ d.label, d.dev })
  53. end
  54. end
  55. o:value("", translate("-- match by device --"))
  56. o = mount:taboption("general", Value, "device", translate("Device"),
  57. translate("The device file of the memory or partition (<abbr title=\"for example\">e.g.</abbr> <code>/dev/sda1</code>)"))
  58. o:depends({ uuid = "", label = "" })
  59. for i, d in ipairs(devices) do
  60. if d.size then
  61. o:value(d.dev, "%s (%d MB)" %{ d.dev, d.size })
  62. else
  63. o:value(d.dev)
  64. end
  65. end
  66. o = mount:taboption("general", Value, "target", translate("Mount point"),
  67. translate("Specifies the directory the device is attached to"))
  68. o:value("/", translate("Use as root filesystem (/)"))
  69. o:value("/overlay", translate("Use as external overlay (/overlay)"))
  70. o = mount:taboption("general", DummyValue, "__notice", translate("Root preparation"))
  71. o:depends("target", "/")
  72. o.rawhtml = true
  73. o.default = [[
  74. <p>%s</p><pre>mkdir -p /tmp/introot
  75. mkdir -p /tmp/extroot
  76. mount --bind / /tmp/introot
  77. mount /dev/sda1 /tmp/extroot
  78. tar -C /tmp/introot -cvf - . | tar -C /tmp/extroot -xf -
  79. umount /tmp/introot
  80. umount /tmp/extroot</pre>
  81. ]] %{
  82. translate("Make sure to clone the root filesystem using something like the commands below:"),
  83. }
  84. o = mount:taboption("advanced", Value, "fstype", translate("Filesystem"),
  85. 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>)"))
  86. o:value("", "auto")
  87. local fs
  88. for fs in io.lines("/proc/filesystems") do
  89. fs = fs:match("%S+")
  90. if fs ~= "nodev" then
  91. o:value(fs)
  92. end
  93. end
  94. o = mount:taboption("advanced", Value, "options", translate("Mount options"),
  95. translate("See \"mount\" manpage for details"))
  96. o.placeholder = "defaults"
  97. if has_fscheck then
  98. o = mount:taboption("advanced", Flag, "enabled_fsck", translate("Run filesystem check"),
  99. translate("Run a filesystem check before mounting the device"))
  100. end
  101. return m