7

This question already has an answer here:

I am using a USB with an embedded device running linux. The issue is that in some cases when I unmount the usb by giving the command umount /media/sda1 the unmount is successful but when I proceed to remove the usb I get an error saying unable to mark fs as dirty and when I plug it back in I get the error Volume was not properly unmounted. Some data may be corrupt. Please run fsck. Is there any other command on the linux terminal which I can use to safely eject the usb? so that the usb device is powered off before I unplug it.

Update: I tried using sync but the error is still there as shown below:

root@(none):~# sync
root@(none):~# umount /media/sda1
root@(none):~# ls /media/sda1
root@(none):~# [  296.021241] usb 2-1: USB disconnect, device number 3
[  296.026879] sd 1:0:0:0: [sda] Synchronizing SCSI cache
[  296.031175] sd 1:0:0:0: [sda]
[  296.033743] Result: hostbyte=0x01 driverbyte=0x00
[  296.048283] FAT-fs (sda1): unable to read boot sector to mark fs as dirty

marked as duplicate by jimmij, cas, MelBurslan, garethTheRed, Serge Jun 17 '16 at 16:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    You could try sync. – garethTheRed Jun 17 '16 at 6:47
  • Are there any side effects as It says here unix.stackexchange.com/questions/90657/… that 'sync is bad for lifetime of the device' and i am unsure about the side effects of flush – malik12 Jun 17 '16 at 7:01
  • Bad or not - what's the effect of not syncing? Corrupt files. The article you linked to suggests that syncing each time you write to the device (for example after a few minutes of editing a document) is bad as you write too many times which in theory reduces the lifetime of the device. Syncing just before you umount is common sense as you want your data to be written to the device don't you? – garethTheRed Jun 17 '16 at 7:08
  • as others mentioned, use sync before umount – mazs Jun 17 '16 at 7:23
  • 4
    FWIW, umount does a sync on the partition automatically. – Stephen Harris Jun 17 '16 at 11:26
4

eject /dev/sda will try and safely remove the device from the kernel and make it safe to remove. You can verify it's removed by looking on /dev to see if the partition entry has been removed (the base device may still show up).

e.g. I just plugged in a USB stick and it showed as /dev/sdg and the partition as sdg1. I can unmount it and it still shows, but after the eject it disappears

$ ls /dev/sdg*
/dev/sdg  /dev/sdg1

$ df | grep sdg
/dev/sdg1       59632764  47460364   9136496  84% /media/sweh/music

$ umount /dev/sdg1

$ ls /dev/sdg*
/dev/sdg  /dev/sdg1

$ sudo eject /dev/sdg

$ ls /dev/sdg*       
/dev/sdg
  • my linux version apparently doesn't have that command root@(none):~# eject /dev/sda1 -sh: eject: command not found – malik12 Jun 17 '16 at 11:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.