How to script in Windows Subsystem for Linux (WSL) and call it from a batch file?
Over on https://askubuntu.com/a/1108609/912537 I suggested a method to edit grub from windows. I have grub installed on /boot/efi/EFI/grub and have been trying to create a script which changes the "next_entry" variable in the Grub Environment Block.
Dual booting Win10 and Debian9, I have WSL running Debian (Bash on Win).
I am trying to use a script as a reboot to Linux shortcut since my BT keyboard doesn't work in GRUB. I have the reverse working from Linux just fine. I have a batch file and a shell script (not) working in tandem. Here is the code:
reboot-to-linux.bat
@echo off
mountvol s: /S
wsl /mnt/c/Users/<username>/Documents/User_scripts/reboot-to-linux.sh
mountvol s: /D
Restart-Computer -Computername 'localhost'
reboot-to-linux.sh
#!/bin/bash
sudo mount -t drvfs s: /mnt/s
sudo grub-editenv /mnt/s/EFI/grub/grubenv set next_entry=0
sudo umount /mnt/s
This is the error I'm getting:
does not existint /mnt/s
grub-editenv: error: cannot open `/mnt/s/EFI/grub/grubenv.new': No such file or directory.
umount: /mnt/s: not mounted
Which tells me that the mount command is failing to mount the s: windows mountpoint onto /mnt/s - weirdly, each of these commands works individually in their respective consoles, I'm obviously not writing the scripts correctly.
What is the correct way to write these scripts?
windows-10 multi-boot script uefi grub2
add a comment |
Over on https://askubuntu.com/a/1108609/912537 I suggested a method to edit grub from windows. I have grub installed on /boot/efi/EFI/grub and have been trying to create a script which changes the "next_entry" variable in the Grub Environment Block.
Dual booting Win10 and Debian9, I have WSL running Debian (Bash on Win).
I am trying to use a script as a reboot to Linux shortcut since my BT keyboard doesn't work in GRUB. I have the reverse working from Linux just fine. I have a batch file and a shell script (not) working in tandem. Here is the code:
reboot-to-linux.bat
@echo off
mountvol s: /S
wsl /mnt/c/Users/<username>/Documents/User_scripts/reboot-to-linux.sh
mountvol s: /D
Restart-Computer -Computername 'localhost'
reboot-to-linux.sh
#!/bin/bash
sudo mount -t drvfs s: /mnt/s
sudo grub-editenv /mnt/s/EFI/grub/grubenv set next_entry=0
sudo umount /mnt/s
This is the error I'm getting:
does not existint /mnt/s
grub-editenv: error: cannot open `/mnt/s/EFI/grub/grubenv.new': No such file or directory.
umount: /mnt/s: not mounted
Which tells me that the mount command is failing to mount the s: windows mountpoint onto /mnt/s - weirdly, each of these commands works individually in their respective consoles, I'm obviously not writing the scripts correctly.
What is the correct way to write these scripts?
windows-10 multi-boot script uefi grub2
add a comment |
Over on https://askubuntu.com/a/1108609/912537 I suggested a method to edit grub from windows. I have grub installed on /boot/efi/EFI/grub and have been trying to create a script which changes the "next_entry" variable in the Grub Environment Block.
Dual booting Win10 and Debian9, I have WSL running Debian (Bash on Win).
I am trying to use a script as a reboot to Linux shortcut since my BT keyboard doesn't work in GRUB. I have the reverse working from Linux just fine. I have a batch file and a shell script (not) working in tandem. Here is the code:
reboot-to-linux.bat
@echo off
mountvol s: /S
wsl /mnt/c/Users/<username>/Documents/User_scripts/reboot-to-linux.sh
mountvol s: /D
Restart-Computer -Computername 'localhost'
reboot-to-linux.sh
#!/bin/bash
sudo mount -t drvfs s: /mnt/s
sudo grub-editenv /mnt/s/EFI/grub/grubenv set next_entry=0
sudo umount /mnt/s
This is the error I'm getting:
does not existint /mnt/s
grub-editenv: error: cannot open `/mnt/s/EFI/grub/grubenv.new': No such file or directory.
umount: /mnt/s: not mounted
Which tells me that the mount command is failing to mount the s: windows mountpoint onto /mnt/s - weirdly, each of these commands works individually in their respective consoles, I'm obviously not writing the scripts correctly.
What is the correct way to write these scripts?
windows-10 multi-boot script uefi grub2
Over on https://askubuntu.com/a/1108609/912537 I suggested a method to edit grub from windows. I have grub installed on /boot/efi/EFI/grub and have been trying to create a script which changes the "next_entry" variable in the Grub Environment Block.
Dual booting Win10 and Debian9, I have WSL running Debian (Bash on Win).
I am trying to use a script as a reboot to Linux shortcut since my BT keyboard doesn't work in GRUB. I have the reverse working from Linux just fine. I have a batch file and a shell script (not) working in tandem. Here is the code:
reboot-to-linux.bat
@echo off
mountvol s: /S
wsl /mnt/c/Users/<username>/Documents/User_scripts/reboot-to-linux.sh
mountvol s: /D
Restart-Computer -Computername 'localhost'
reboot-to-linux.sh
#!/bin/bash
sudo mount -t drvfs s: /mnt/s
sudo grub-editenv /mnt/s/EFI/grub/grubenv set next_entry=0
sudo umount /mnt/s
This is the error I'm getting:
does not existint /mnt/s
grub-editenv: error: cannot open `/mnt/s/EFI/grub/grubenv.new': No such file or directory.
umount: /mnt/s: not mounted
Which tells me that the mount command is failing to mount the s: windows mountpoint onto /mnt/s - weirdly, each of these commands works individually in their respective consoles, I'm obviously not writing the scripts correctly.
What is the correct way to write these scripts?
windows-10 multi-boot script uefi grub2
windows-10 multi-boot script uefi grub2
edited Jan 11 at 23:03
Jon T
asked Jan 10 at 16:49
Jon TJon T
112
112
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In fact, both the scripts are functional however the batch commands can be wrapped by the line
@powershell -c " "
to be run from outside a terminal and as for the shell script - don't write your scripts in notepad people. Yes, a rookie mistake, Windows had made me complacent. FYI notepad and other windows editiors use "carriage return, line feed" as their new line (/r/n) and Linux expects just a line-feed (/n) so this breaks the script.
Also, better idea is to store your shell script in the wsl filesystem rather than somewhere in /mnt/c - just keep windows away from it. There you have it - clickable reboot shortcuts from Linux to windows and back again! I think I'll be seeing less and less of Windows these days.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1392842%2fhow-to-script-in-windows-subsystem-for-linux-wsl-and-call-it-from-a-batch-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In fact, both the scripts are functional however the batch commands can be wrapped by the line
@powershell -c " "
to be run from outside a terminal and as for the shell script - don't write your scripts in notepad people. Yes, a rookie mistake, Windows had made me complacent. FYI notepad and other windows editiors use "carriage return, line feed" as their new line (/r/n) and Linux expects just a line-feed (/n) so this breaks the script.
Also, better idea is to store your shell script in the wsl filesystem rather than somewhere in /mnt/c - just keep windows away from it. There you have it - clickable reboot shortcuts from Linux to windows and back again! I think I'll be seeing less and less of Windows these days.
add a comment |
In fact, both the scripts are functional however the batch commands can be wrapped by the line
@powershell -c " "
to be run from outside a terminal and as for the shell script - don't write your scripts in notepad people. Yes, a rookie mistake, Windows had made me complacent. FYI notepad and other windows editiors use "carriage return, line feed" as their new line (/r/n) and Linux expects just a line-feed (/n) so this breaks the script.
Also, better idea is to store your shell script in the wsl filesystem rather than somewhere in /mnt/c - just keep windows away from it. There you have it - clickable reboot shortcuts from Linux to windows and back again! I think I'll be seeing less and less of Windows these days.
add a comment |
In fact, both the scripts are functional however the batch commands can be wrapped by the line
@powershell -c " "
to be run from outside a terminal and as for the shell script - don't write your scripts in notepad people. Yes, a rookie mistake, Windows had made me complacent. FYI notepad and other windows editiors use "carriage return, line feed" as their new line (/r/n) and Linux expects just a line-feed (/n) so this breaks the script.
Also, better idea is to store your shell script in the wsl filesystem rather than somewhere in /mnt/c - just keep windows away from it. There you have it - clickable reboot shortcuts from Linux to windows and back again! I think I'll be seeing less and less of Windows these days.
In fact, both the scripts are functional however the batch commands can be wrapped by the line
@powershell -c " "
to be run from outside a terminal and as for the shell script - don't write your scripts in notepad people. Yes, a rookie mistake, Windows had made me complacent. FYI notepad and other windows editiors use "carriage return, line feed" as their new line (/r/n) and Linux expects just a line-feed (/n) so this breaks the script.
Also, better idea is to store your shell script in the wsl filesystem rather than somewhere in /mnt/c - just keep windows away from it. There you have it - clickable reboot shortcuts from Linux to windows and back again! I think I'll be seeing less and less of Windows these days.
answered Jan 12 at 7:29
Jon TJon T
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1392842%2fhow-to-script-in-windows-subsystem-for-linux-wsl-and-call-it-from-a-batch-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown