Ejecting/unmounting random USB flash drive in Raspberry pi / Python - bash

So I'm trying to get a working code in Python that will eject/unmount all USB flash drives attached to the Pi (Running Raspbian) - so that they can be removed safely. The final code will be run from within the python program.
Additionally, I'd like to eject/unmount the USB flash drive even if it's in use.
I've looked around and can't see how to do this. Thanks.
udisks --detach /media/pi/DOCS/ - 'Blocked device... Resource temporarily available'...
udisks --detach /media/pi/ - 'Blocked device...Resource temporarily available'...
udisks --detach /media/ - 'Blocked device...Resource temporarily available'...
sudo udisks --detach /media/pi/DOCS/ - still blocked...
sudo umount /path/to/devicename - command not found...
eject /media/pi/DOCS/ - Unable to open '/dev/sda'
(DOCS is the name if my USB flash drive. - though I want to eject all USB flash drives - not just my one)
So I'm going to ask the user in Python to select their USB flash drive from a list, which is pretty easy (just read in the folder) - so I will have the pathway to the USB. I'm still not sure which code can safely disconnect the USB flash drive - Maybe more research is the answer. Thanks for your help so far.

For udisks --detach the parameter should be the device, not the mounting point.
For example, if the USB Disk is /dev/sdb the command would be udisks --detach /dev/sdb
If the command still doesn't work you could try udiskctl power-off -b <device> which should also work.

so I found the answer:
sudo eject /dev/sda1
-This disconnects the USB flash drive on a Raspberry Pi.
Thank you very much to everyone who helped!

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

How to fix the stuck after the command, 'bash flash.sh'

I was trying to flash the mendel-enterprise-chef-13 to the Coral EdgeTPU Development Board but got stuck after the command, "bash flash.sh."
The host computer is the MacBook Pro (2018) with macOS Mojave ver. 10 and connected with the Coral EdgeTPU Dev Board.
I have followed the instructions on the Coral Document listed at https://coral.withgoogle.com/docs/dev-board/get-started/.
The process went smooth up to without the problem untill the step 8 and 12.
mkdir -p ~/.local/bin
sudo mv ~/Downloads/platform-tools/fastboot ~/.local/bin/
pip3 install --user mendel-development-tool
and then install the CP210x USB to UART Bridge Virtual COM Port (VCP) driver for Mac.
screen /dev/cu.SLAB_USBtoUART 115200
fastboot 0
fastboot devices
1b0741d6f0609912 fastboot # I did not get this message
cd ~/Downloads
curl -O https://dl.google.com/coral/mendel/enterprise/mendel-enterprise-chef-13.zip
unzip mendel-enterprise-chef-13.zip \
&& cd mendel-enterprise-chef-13
bash flash.sh # Got stuck here.
I want to know how to fix the issues of flashing the mendel image.
this sounds like a problem with the USB-A USB-C cable, or the usb port on your host machine, have you tried a different port?

Can't mount Android Things image file in OS X to tweak config files

Some tutorials recommend making modifications to files such as wpa_supplicant.conf within the Android Things image file, as per this answer https://stackoverflow.com/a/41732035/766115. I'm trying with the Android Things developer preview 4.1 image file.
However, I've had no luck mounting this file for editing purposes on OS X. Various attempts to use os x Disk Utility or the mount command from the terminal all result in some type of error message telling me the file format is not compatible. I can see in Disk Util, or through terminal mount, that the ISO image has 15 sectors (or partitions), but I can't access them.
I've even tried spinning up an Ubuntu in AWS, uploading and mounting from there. No dice.
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
Any advice? What am I missing.
On macOS I have done this way:
Connect the sdcard on your Mac
Run on terminal diskutil list and see the name of your sdcard (in my case /dev/disk2s1)
Create a directory where the sdcard will be mounted: sudo mkdir -p /Volumes/pisdcard
Mount the sdcard: sudo mount -t msdos /dev/disk2s1 /Volumes/pisdcard
Edit what you want and unmount the sdcard with: sudo umount /dev/disk2s1
It worked for me, I used to change config.txt and cmdline.txt to change UART mode and use a GPS module on Android Things.
hdiutil attach [file] is the macOS command to treat an image file as a disk device. If the image file contains a filesystem macOS can read, it should also mount any volumes contained in the file. If your image contains a volume not supported by macOS (e.g., ext4), you also need to install an appropriate driver before you can mount the volume.

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