How to install archlinux EFI grub with MBR (msdos) partation table? - bootloader

As we know, EFI boot is not limited to GPT partition table, and MBR is ok.
I've a legacy disk with msdos partition table, and I'd like to reinstall it into archlinux.
In wiki:
https://wiki.archlinux.org/index.php/GRUB#UEFI_systems
it also said that GPT is not necessary.
GPT is not strictly necessary, but it is highly recommended and is the only method currently supported in this article.
What is the way to install grub EFI boot to my hard drive with MBR partition table? Thx.

Assuming:
/dev/sda1 is your efi partition
/dev/sda2 is your root partition (containing /boot too)
Your linux kernel file is /boot/vmlinuz-linux
Your initrd file is /boot/initrd.img
Burn a live usb of ubuntu 16.04 with amd64 architecture, boot on it and paste these commands:
sudo os-prober
efibootmgr
Install os-prober or efibootmgr if it isn't installed yet:
sudo apt-get install os-prober
sudo apt-get install efibootmgr
Grub in efi mode is probably not installed, install it too
sudo apt-get install grub-efi-amd64-signed
Then, install grub:
sudo mount -t ext4 /dev/sda2 /mnt
sudo mount -t vfat /dev/sda1 /mnt/boot/efi
grub-install --target=x86_64-efi --efi-directory=/mnt/boot/efi --boot-directory=/mnt/boot --bootloader-id=grub
Don't try to use grub-mkconfig, it will not work.
Instead, boot from your newly grub bootloader, you will have a grub shell, paste these commands:
set root=(hd0,2)
linux /boot/vmlinuz-linux root=/dev/sda2
initrd /boot/initrd.img
boot
After that, you should be on linux, mount your efi partition (to /boot/efi !) if it's not already, install grub/os-prober/efibootmgr, and run these:
sudo os-prober
grub-install --target=x86_64-efi --efi-directory=/boot/efi --boot-directory=/boot --bootloader-id=grub
grub-mkconfig -o /boot/grub/grub.cfg
Reboot, and grub is back and working

Related

cannot mount usb partition - unknown file system exfat

I have a USB stick with important info that would not show up in Windows. I tried the Disk Management Utility, and the partition with the data shows up as "healthy", but no drive letter, and right-click menu options all grayed out (except 'delete'). I used another laptop, I used a Macbook, all to no avail.
On Ubuntu, it also would not show up. I tried manual mounting, which did not work, and on parted it the "File system" column is empty.
Using fdisk -l it shows as HPFS/NTFS/exFAT.
???
I thought to remove my question, but since it took me a while to find the answer, others may benefit:
sudo apt install exfat-fuse exfat-utils
Now I could mount it with exfat specified as file system (and anyway now Ubuntu also automatically mounted it).
uanble to mount exfat file system then needs to follow below steps
Open a terminal (Ctrl+Alt+T shortcut in Ubuntu).
sudo add-apt-repository universe
sudo apt update
sudo apt install exfat-fuse exfat-utils

linux file system layout -partiton - fdisk

I am tyring to understand linux file system layout. Why does the command work inside virtual box but not on linux shell on windows?
I tried to use the command sudo fdisk -l dev/sda on both my virtual box(Ubuntu) and Ubuntu on windows(from microsoft store). It didn't work on any of them but when I changed the command to sudo fdisk -l, it worked inside virtual box but not on linux bash shell on windows.
Inside linux shell on windows:
:~$ sudo fdisk -l /dev/sda
.
fdisk: cannot open /dev/sda: No such file or directory
:~$ sudo fdisk -l
fdisk: cannot open /proc/partitions: No such file or directory
:~$ man fdisk
:~$ whereis fdisk
fdisk: /sbin/fdisk /usr/share/man/man8/fdisk.8.gz
The fundamental of Windows Subsystem for Linux (WSL) - Ubuntu is a POSIX emulator which is like Cygwin kind of environment helps to port some Linux based commands/applications running on windows platform as windows process.
It contains an abstraction layer of a virtual filesystem (vfs) which has read-only app image & RAM based writable tmpfs and neither it doesn't have access control to read the raw devices on host system nor it emulates the raw devices for the subsystem.
from man(fdisk) :
Description
This command is used to create and modify the partition table, and to install the master boot (IA only) record that
is put in the first sector of the fixed disk. This table is used by
the first-stage bootstrap (or firmware) to identify parts of the disk
reserved for different operating systems, and to identify the
partition containing the second-stage bootstrap (the active Solaris
partition). The rdevice argument must be used to specify the raw
device associated with the fixed disk, for example,
/dev/rdsk/c0t0d0p0.
So WSL-Ubuntu can't execute the fdisk command successfully since it doesn't have its own kernel to manage host resources.
On the other hand, Oracle's VirtualBox is a virtualized system which imitates a fully functional OS running on bare metal. It simulates its own system-space & user-space with the help of virtualization hypervisor and manages the virtual resources via the Guest OS kernel. This is why fdisk command execution was successful on VirtualBox
Reference :
https://www.microsoft.com/en-us/research/wp-content/uploads/2013/01/posix-emulation-submitted.pdf
Credits: https://www.quora.com/How-is-Windows-Subsystem-for-Linux-different-from-running-Linux-on-Windows-in-a-VM

VirtualBox: mount.vboxsf: mounting failed with the error: No such device [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I'm using VirtualBox with OS X as host and CentOS on the guest VM.
In OS X I created folder myfolder, added it as shared folder to the VM, turned on the VM, in CentOS created folder /home/user/myfolder and typing:
sudo mount -t vboxsf myfolder /home/user/myfolder
and have output:
/sbin/mount.vboxsf: mounting failed with the error: No such device
What I'm doing wrong?
UPDATED:
Guest Additions installed.
My shared folder/clipboard stopped to work for some reason (probably due to a patch installation on my virtual machine).
sudo mount -t vboxsf Shared_Folder ~/SF/
Gave following result:
VirtualBox: mount.vboxsf: mounting failed with the error: No such device
The solution for me was to stop vboxadd and do a setup after that:
cd /opt/VBoxGuestAdditions-*/init
sudo ./vboxadd setup
You're using share folders, so you need to install VirtualBox Guest Additions inside your virtual machine to support that feature.
Vagrant
If you're using Vagrant (OS X: brew cask install vagrant), run:
vagrant plugin install vagrant-vbguest
vagrant vbguest
In case it fails, check the logs, e.g.
vagrant ssh -c "cat /var/log/vboxadd-install.log"
Maybe you're just missing the kernel header files.
VM
Inside VM, you should install Guest Additions, kernel headers and start the service and double check if kernel extension is running.
This depends on the guest operating system, so here are brief steps:
Install kernel include headers (required by VBoxLinuxAdditions).
RHEL: sudo apt-get update && sudo apt-get install kernel-devel
CentOS: sudo yum update && sudo yum -y install kernel-headers kernel-devel
Install Guest Additions (this depends on the operating system).
Ubuntu: sudo apt-get -y install dkms build-essential linux-headers-$(uname -r) virtualbox-guest-additions-iso
If you can't find it, check by aptitude search virtualbox.
Debian: sudo apt-get -y install build-essential module-assistant virtualbox-ose-guest-utils
If you can't find it, check by dpkg -l | grep virtualbox.
manually by downloading the iso file inside VM (e.g. wget) and installing it, e.g.
wget http://download.virtualbox.org/virtualbox/5.0.16/VBoxGuestAdditions_5.0.16.iso -P /tmp
sudo mount -o loop /tmp/VBoxGuestAdditions_5.0.16.iso /mnt
sudo sh -x /mnt/VBoxLinuxAdditions.run # --keep
Extra debug: cd ~/install && sh -x ./install.sh /mnt/VBoxLinuxAdditions.run
Double check that kernel extensions are up and running:
sudo modprobe vboxsf
Start/restart the service:
manually: sudo /opt/VBoxGuestAdditions*/init/vboxadd setup (add sudo sh -x to debug)
Debian: sudo /etc/init.d/vboxadd-service start
Fedora: sudo /etc/init.d/vboxdrv setup
CentOS: sudo service VBoxService start
Building the main Guest Additions module
If above didn't work, here are more sophisticated steps to fix it. This assumes that you've already VBoxGuestAdditions installed (as shown above).
The most common reason why mounting shared folder doesn't work may related to building Guest Additions module which failed. If in /var/log/vboxadd-install.log you've the following error:
The headers for the current running kernel were not found.
this means either you didn't install kernel sources, or they cannot be found.
If you installed them already as instructed above, run this command:
$ sudo sh -x /opt/VBoxGuestAdditions-5.0.16/init/vboxadd setup 2>&1 | grep KERN
+ KERN_VER=2.6.32-573.18.1.el6.x86_64
+ KERN_DIR=/lib/modules/2.6.32-573.18.1.el6.x86_64/build
So basically vboxadd script is expecting your kernel sources to be available at the following dir:
ls -la /lib/modules/$(uname -r)/build
Check if the kernel dir exists (symbolic link points to the existing folder). If it's not, please install them to the right folder (e.g. in /usr/src/kernels).
So vboxadd script can enter your kernel source directory and run make kernelrelease, get the value and compare with your current kernel version.
Here is the logic:
KERN_VER=`uname -r`
KERN_DIR="/lib/modules/$KERN_VER/build"
if [ -d "$KERN_DIR" ]; then
KERN_REL=`make -sC $KERN_DIR --no-print-directory kernelrelease 2>/dev/null || true`
if [ -z "$KERN_REL" -o "x$KERN_REL" = "x$KERN_VER" ]; then
return 0
fi
fi
If the kernel version doesn't match with the sources, maybe you've to upgrade your Linux kernel (in case the sources are newer than your kernel).
CentOS
Try:
vagrant plugin install vagrant-vbguest vagrant vbgues
If won't work, try the following manual steps for CentOS:
$ sudo yum update
$ sudo yum install kernel-$(uname -r) kernel-devel kernel-headers # or: reinstall
$ rpm -qf /lib/modules/$(uname -r)/build
kernel-2.6.32-573.18.1.el6.x86_64
$ ls -la /lib/modules/$(uname -r)/build
$ sudo reboot # and re-login
$ sudo ln -sv /usr/src/kernels/$(uname -r) /lib/modules/$(uname -r)/build
$ sudo /opt/VBoxGuestAdditions-*/init/vboxadd setup
I am able to resolved this by running below commmand
modprobe -a vboxguest vboxsf vboxvideo
In addition to #Mats answer, I'm adding some more info (it helped me on Debian 8).
My shared folder/clipboard stopped to work for some reason (probably due to a patch installation on my virtual machine).
sudo mount -t vboxsf Shared_Folder ~/SF/
Gave me following result:
VirtualBox: mount.vboxsf: mounting failed with the error: No such device
The solution for me was to stop vboxadd and do a setup after that:
cd /opt/VBoxGuestAdditions-*/init
sudo ./vboxadd setup
At this point, if you still get the following error:
No such device. The Guest Additions installation may have failed. The error has been logged in /var/log/vboxadd-install.log
You need to install linux headers:
apt-get install linux-headers-$(uname -r)
then you can install Guest Additions:
sh /media/cdrom/VBoxLinuxAdditions.run --nox11
and restart your Linux by:
reboot
then you will be able to mount your shared folder!
mount -t vboxsf Shared_Folder ~/SF/
More informations (in French), check this page.
This was the only solution what worked for me:
Install Vagrant plugin: vagrant-vbguest, which can keep your VirtualBox Guest Additions up to date.
vagrant plugin install vagrant-vbguest
Source: https://github.com/aidanns/vagrant-reload/issues/4#issuecomment-230134083
This was resolved by:
yum install gcc kernel-devel make
workaround is here: https://gist.github.com/larsar/1687725
Shared folder was earlier working for me but all f sudden it stopped working (Virualbox - host was Windows 7, Guest was OpenSuSe)
modprobe -a vboxguest vboxsf vboxvideo
then
mount -t vboxsf testsf /opt/tsf (testsf was the folder in Windows C drive which was added in Virtualbox shared folder --- and /opt/tsf is the folder in OpenSuse
My host is Windows10 my VM guest is ubuntu build by vagrant. This worked for me:
vagrant plugin install vagrant-winnfsd
The solution for me was to update guest additions
(click Devices -> Insert Guest Additions CD image)
I also had a working system that suddenly stopped working with the described error.
After furtling around in my /lib/modules it would appear that the vboxvfs module is no more. Instead modprobe vboxsf was the required incantation to get things restarted.
Not sure when that change ocurred, but it caught me out.
I am running VirtualBox 5.1.20, and had a similar issue. Here is a url to where I found the fix, and the fix I implemented:
# https://dsin.wordpress.com/2016/08/17/ubuntu-wrong-fs-type-bad-option-bad-superblock/
if [ "5.1.20" == "${VBOXVER}" ]; then
rm /sbin/mount.vboxsf
ln -s /usr/lib/VBoxGuestAdditions/mount.vboxsf /sbin/mount.vboxsf
fi
The link had something similar to /usr/lib/VBoxGuestAdditions/other/mount.vboxsf, rather than what I have in the script excerpt.
For a build script I use in vagrant for the additions:
https://github.com/rburkholder/vagrant/blob/master/scripts/additions.sh
Seems to be a fix at https://www.virtualbox.org/ticket/16670
For me, on a mac, it turned out I had an old VirtualBox image stored on my machine that didn't have metadata, so it wasn't being updated to the latest version.
That old image had an older version of the vbguest plugin installed in it, which the newer vbguest plugin on my machine couldn't work with.
So to fix it, I just removed the image that my Vagrant was based on, and then Vagrant downloaded the newer version and it worked fine.
# Remove an old version of the virtual box image that my vagrant was using
$ vagrant box remove centos/7
You can find out which boxes you have cached on your machine by running:
$ vagrant box list
I had also upgraded my vbguest plugin in my earlier attempts at getting this to work, using the following process, but I don't think this helped. FYI !
# Get rid of old plugins
vagrant plugin expunge
# Globally install the latest version of the vbguest plugin`
vagrant plugin install vagrant-vbguest
If you find bring the box fails on guest addtions, you can try doing the following to ensure the plugins install correctly. This downloads the latest based image for your system (for me CentOS), and may resolve the issue (it did for me!)
$ vagrant box update
There can be errors/incorrect approach in two scenarios. Check both of it and figure it out
SCENARIO 1 :
Once you are running the VBoxLinuxAdditions.run or VBoxSolarisAdditions.pkg or VBoxWindowsAdditions.exe , check if all the modules are getting installed properly.
1.1.a. In case of VBoxLinuxAdditions, if Building the VirtualBox Guest Additions kernel modules gets failed,
check the log file in /var/log/vboxadd-install.log . If the error is due to kernel version update your kernel and reboot the vm. In case of fedora,
1.1.b. yum update kernel*
1.1.c. reboot
1.2. If nothing gets failed, then all is fine. You are already having the expected kernel version
SCENARIO 2 :
If the VBoxGuestAdditions is installed (check for a folder /opt/VBoxGuestAdditions-* is present .... * represents version) you need to start it before mounting.
2.1. cd /opt/VBoxGuestAdditions-*/init && ./vboxadd start
You need to specify the user id and group id of your vm user as options to the mount command.
2.2.a. Getting uid and gid of a user:
id -u <'user'>
id -g <'user'>
2.2.b. Setting uid and gid in options of mount command:
mount -t vboxsf -o uid=x,gid=x shared_folder_name guest_folder
On Ubuntu this worked:
sudo apt-get install build-essential linux-headers-`uname -r` dkms
Had the same issue with VirtualBox 5.0.16/rXXX
Installed latest VirtualBox 5.0.18 and installed latest Vagrant 1.9.3, issue went toodles.
I added as root user
/etc/rc.d/rc.local
/root/mount-vboxsf.sh
then
chmod +x /etc/rc.d/rc.local
and the sample script /root/mount-vboxsf.sh (set your own the uid and gid options)
modprobe -a vboxguest vboxsf vboxvideo
mount -t vboxsf NAME_SHARED_DIRECTORY /media/sf_NAME_SHARED_DIRECTORY -o rw,uid=0,gid=0
you need add
chmod + /root/mount-vboxsf.sh
I have similar issue, check header if it's not match then run below command
CentOS: sudo yum update && sudo yum -y install kernel-headers kernel-devel
If you're on Debian:
1) remove all installed package through Virtualbox Guest Additions ISO file:
sh /media/cdrom/VBoxLinuxAdditions.run uninstall
2) install Virtualbox packages:
apt-get install build-essential module-assistant virtualbox-guest-dkms virtualbox-guest-utils
Note that even with modprobe vboxsf returning nothing (so the module is correctly loaded), the vboxsf.so will call an executable named mount.vboxsf, which is provided by virtualbox-guest-utils. Ignoring this one will prevent you from understanding the real cause of the error.
strace mount /your-directory was a great help (No such file or directory on /sbin/mount.vboxsf).
An update did the trick for me !
$ vagrant box update
$ vagrant plugin install vagrant-vbguest
Below two commands works for me.
vagrant ssh
sudo mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant
Okay everyone is missing a basic fact.
mkdir /test - Makes sub directory in current directory.
sudo mkdir /test - Make directory in Root.
So if your shared directory name is shared and you do the following:
mkdir /test
sudo mount -t vboxsf shared /test
It generates this error:
sbin/mount.vboxsf: mounting failed with the error: No such file or directory
Because the directory is in the wrong place! Yes that's what this error is saying. The error is not saying reload the VBOX guest options.
But if you do this:
sudo mkdir ~/test
sudo mount -t vboxsf shared ~/test
Then it works fine.
It really amazes me how many people suggest reloading the Vbox guest additions to solve this error or writing a complex program to solve a directory created in the wrong place.

Removing GRUB from sda from Mac Internet Recovery

I tried to make a bootable Ubuntu DVD on my MAC. This lead to messing up my bootloader which I have been unable to fix.
https://discussions.apple.com/thread/3109456?tstart=0
One person states
Boot OSX and in the terminal write:
mkdir mnt ; sudo mount -t msdos /dev/disk0s1 mnt
Will show a new drive EFI
Open this drive and open the folder EFI
Inside you will have the folders APPLE and UBUNTU
Just delete the UBUNTU folder
So I keep reading and see
When in -Recovery From Internet- it is impossible to use mkdir, but
you can "cd /tmp" and mount it there.
So I haven't been able to figure out how to mount disk0s1 in the /tmp. If someone could please show me the commands to get into the EFI Folder so I can delete the Ubuntu folder.
I assume the link means you can do something like:
mount -t msdos /dev/disk0s1 /tmp/
then
cd /tmp
and you should see the APPLE and UBUNTU directories. I am not in Recovery Mode now so I can't try that, but deleting UBUNTU from there may help you.
This page:
http://www.rodsbooks.com/refind/getting.html
is what I use when I want to install Linux on a Mac, and has a lot of useful explanation about EFI booting on Mac machines. I have had good luck with SuperGrub2 when I've gotten in trouble:
http://www.supergrubdisk.org/category/download/supergrub2diskdownload/super-grub2-disk-stable/

OS Development - booting from floppy drive using qemu

I have been reading BrokenThorn's OS development tutorial and am at the part of creating and loading the second stage bootloader. The tutorial is for Windows, but I am doing this in Linux(Ubuntu 13.04).
This is what I have done:
Created file floppy.img under ~/Documents/floppy with the mkfs.vfat command
Compiled by boot.asm file using nasm giving me boot.bin
Then I ran this command : dd if=boot.bin of=~/Documents/floppy/floppy.img bs=512 count=1
Thus I have the floppy image with the first stage bootloader. On starting that using qemu, it works fine.
However, after I create the second stage bootloader, (if I am correct)I would have to mount the floppy.img and copy stage 2 on to the mounted filesystem. In such a case, how can one boot a mounted floppy using qemu ? Is it even possible ? If not, how do I work with the second stage bootloader.
Please forgive me for any stupid assumption/question as I am new with this.
Where is your problem? You mount the image:
mount -oloop ~/Documents/floppy.img /mnt/floppy
Copy the stage2:
cp stage2.bin /mnt/floppy
Unmount it:
umount /mnt/floppy
And launch it with QEMU:
qemu -fda ~/Documents/floppy.img
VoilĂ !

Resources