我正在尝试使用java为linux上的raid驱动器创建文件系统。
当我尝试使用 ProcessBuilder 执行以下命令时遇到以下问题。
进程 '[/usr/bin/sudo, /sbin/mkfs.ext4, /dev/md0, -m 1, -O uninit_bg, -E lazy_itable_init=1]' 标准错误转储:mke2fs 1.42.3(2012 年 5 月 14 日)
指定了错误的选项:lazy_ _init
扩展选项由逗号分隔,并且可以采用由等号 ('=') 分隔的参数。
有效的扩展选项是:stride= stripe-width= resize=lazy_itable_init=<0 禁用,1 启用>lazy_journal_init=<0 禁用,1 启用> test_fs discard nodiscard quotatype=
我的 ProcessBuilder 对象看起来像这样
mkfs("ext4", "/dev/md0", "-m 1", "-O uninit_bg", "-E lazy_itable_init=1")
public void mkfs(String filesystem, String devicename, String... options) {
mkfsCommand.add(SUDO_CMD);
if(fileSystemType.equals("xfs")){
mkfsCommand.add("/sbin/mkfs.xfs");
} else if (fileSystemType.equals("ext4")) {
mkfsCommand.add("/sbin/mkfs.ext4");
}
mkfsCommand.add(deviceName);
for (String option:options) {
mkfsCommand.add(option);
}
List<String> mkfsCommand = Lists.newLinkedList();
Exec.exec(ProcessBuilder(mkfsCommand))
}
Exec.exec 是我用来执行系统命令的库。我无法更改它,但这是它的功能片段。
public String exec(ProcessBuilder pb) {
String cmdString = Arrays.deepToString(pb.command().toArray(new String[0]));
int retval = 0;
Process p = null;
String output = "";
if(shouldLog) {
logger.debug("in exec: " + cmdString);
}
String error = null;
try {
p = pb.start();
if (executionDeadline != null) {
Thread durationEnforcer = new DurationEnforcer(executionDeadline, p);
durationEnforcer.start();
}
Future<String> futureErr = null;
if (!pb.redirectErrorStream()) {
futureErr = SingleExecutor.submit(new StreamReader(p.getErrorStream()));
}
StreamReader outputReader = new StreamReader(p.getInputStream());
p.getOutputStream().close();
output = outputReader.call();
retval = p.waitFor();
if (futureErr != null) {
error = futureErr.get();
}
if (error != null && !error.isEmpty()) {
if(shouldLog) {
logger.warn("Process '" + cmdString + "' stderr dump:\n" + error);
}
}
this.stdOutput = output;
this.stdError = error;
} catch (Exception e) {
logger.warn("exec failed: " + e + "\nstdout:\n" + output);
throw new RuntimeException("exec failed: ", e);
} finally {
StreamHelper.closeStreamsAndDestroy(p);
}
if (retval != 0) {
String msg = "exec failed with " + retval + ": " + cmdString;
if(shouldLog) {
logger.warn(msg + "\nstdout:\n" + output);
}
throw new ExecException(error, cmdString, retval, output);
}
if(shouldLog) {
logger.debug("finished exec: " + cmdString);
}
return output;
}
}
我不确定为什么会收到此错误。我怀疑 -E lazy_itable_init=1 没有正确传递给 Processbuilder。有什么想法吗?