Add option to format drive as btrfs (beta)

This commit is contained in:
Taylor Helsper 2022-07-30 22:01:33 -05:00
parent b14255921e
commit 2dbea51d69
5 changed files with 86 additions and 7 deletions

View File

@ -11,7 +11,11 @@ done
parted --script /dev/$dev mklabel gpt || true
# Make new partition with entire drive
if [ -f /tmp/format_filesystem_btrfs ]; then
parted --script /dev/$dev mkpart primary btrfs 0% 100%
else
parted --script /dev/$dev mkpart primary ext4 0% 100%
fi
partprobe /dev/$dev
sleep 2

View File

@ -99,9 +99,14 @@ proc createMyNodeFsOnBlockDevice {blockDevice} {
}
puts "Formatting new partition ${blockPartition}"
if [file exists "/tmp/format_filesystem_btrfs"] {
runCommand mkfs.btrfs -f -L myNode /dev/${blockPartition}
} else {
runCommand mkfs.ext4 -F -L myNode /dev/${blockPartition}
}
runCommand mount /dev/${blockPartition} /mnt/hdd -o errors=continue
#runCommand mount /dev/${blockPartition} /mnt/hdd -o errors=continue
runCommand mount /dev/${blockPartition} /mnt/hdd
runCommand date >/mnt/hdd/.mynode
runCommand echo /dev/${blockPartition} > /tmp/.mynode_drive
}] {

View File

@ -16,7 +16,7 @@ def is_mynode_drive_mounted():
mounted = True
try:
# Command fails and throws exception if not mounted
output = to_string(subprocess.check_output("grep -qs '/mnt/hdd ext4' /proc/mounts", shell=True))
output = to_string(subprocess.check_output("grep -qs '/mnt/hdd ' /proc/mounts", shell=True))
except:
mounted = False
return mounted
@ -125,6 +125,13 @@ def find_unmounted_drives():
pass
return drives
#==================================
# Drive Format Functions
#==================================
def set_drive_filesystem_type(filesystem):
run_linux_cmd("rm -f /tmp/format_filesystem_*")
touch("/tmp/format_filesystem_{}".format(filesystem))
run_linux_cmd("sync")
#==================================
# Mount / Unmount Parition Functions

View File

@ -245,6 +245,30 @@ def api_toggle_setting():
return jsonify(data)
@mynode_api.route("/api/set_setting")
def api_set_setting():
check_logged_in()
data = {}
data["status"] = "unknown"
if not request.args.get("setting"):
data["status"] = "no_setting_specified"
return jsonify(data)
if not request.args.get("value"):
data["status"] = "no_value_specified"
return jsonify(data)
setting = request.args.get("setting")
value = request.args.get("value")
if setting == "format_filesystem_type":
set_drive_filesystem_type(value)
data["status"] = "success"
else:
data["status"] = "unknown_setting"
return jsonify(data)
@mynode_api.route("/api/get_drive_benchmark")
def api_get_drive_benchmark():
check_logged_in()

View File

@ -2,7 +2,7 @@
<head>
<title>{{ title }}</title>
{% include 'includes/head.html' %}
<meta http-equiv="refresh" content="30">
<meta http-equiv="refresh" content="3600">
<script>
$(document).ready(function() {
@ -13,6 +13,30 @@
$("#reboot-device").on("click", function() {
window.location.href="/settings/reboot-device-no-format"
});
show_advanced_options = false;
$("#show_advanced_options").on("click", function() {
if (show_advanced_options) {
$("#show_advanced_options").text("Show Advanced Options");
$("#advanced_options").hide();
show_advanced_options = false;
} else {
$("#show_advanced_options").text("Hide Advanced Options");
$("#advanced_options").show();
show_advanced_options = true;
}
})
function set_format_filesystem_type(filesystem_type) {
$.get("/api/set_setting?setting=format_filesystem_type&value="+filesystem_type);
}
$("#filesystem_type").selectmenu( {
change: function( event, data ) {
format_filesystem_type = data.item.value;
set_format_filesystem_type(format_filesystem_type);
}
});
set_format_filesystem_type("ext4");
});
</script>
@ -27,9 +51,24 @@
<p>A new drive has been detected! This drive will be formatted for use by myNode.</p>
<p><i>Note: All existing data will be lost. If this is not OK, remove the drive now and click Reboot.</i></p>
<br/>
<button id="format-confirm" value="Login" class="ui-button ui-widget ui-corner-all format_button">Format Drive</button>
<button id="format-confirm" class="ui-button ui-widget ui-corner-all format_button">Format Drive</button>
<br/><br/>
<button id="reboot-device" value="Login" class="ui-button ui-widget ui-corner-all format_button">Reboot</button>
<button id="reboot-device" class="ui-button ui-widget ui-corner-all format_button">Reboot</button>
<br/><br/><br/><br/><br/>
<button id="show_advanced_options" class="ui-button ui-widget ui-corner-all mynode_button_small" style="font-size: 12px;">Show Advanced Options</button>
<div id="advanced_options" style="display: none; font-size: 14px;">
<br/><br/>
<b>Filesystem Type</b>
<br/><br/>
<select id="filesystem_type">
<option value="ext4" selected="selected">ext4 (default)</option>
<option value="btrfs">btfrs (beta)</option>
</select>
</div>
<br/><br/>
</div>