marcelp1
Posts: 129
Joined: Mon Jun 11, 2012 8:41 pm

Safe Removal / Detach / Eject of external HDD

Tue Jun 25, 2013 11:05 am

I have external HDD connected to RPi and when wanted to remove it.

In the past I would shut down the Pi and then unplug it, but now have another application
running on the Pi as well so looking how to safely remove the HDD
while the RPi is running, but when I run the command to detach I get error :(

Here is some info:

Code: Select all

lsmod
Module Size Used by
fuse 69333 1
snd_bcm2835 16304 0
snd_usb_audio 104097 0
snd_pcm 77560 2 snd_bcm2835,snd_usb_audio
snd_page_alloc 5145 1 snd_pcm
snd_hwdep 5929 1 snd_usb_audio
snd_usbmidi_lib 18067 1 snd_usb_audio
snd_seq_midi 4591 0
snd_seq_midi_event 6544 1 snd_seq_midi
snd_rawmidi 21160 2 snd_usbmidi_lib,snd_seq_midi
snd_seq 53329 2 snd_seq_midi_event,snd_seq_midi
snd_timer 19998 2 snd_pcm,snd_seq
snd_seq_device 6438 3 snd_seq,snd_rawmidi,snd_seq_midi
snd 58447 9 snd_bcm2835,snd_usb_audio,snd_hwdep,snd_timer,snd_pcm,snd_seq,snd_rawmidi,snd_usbmidi_lib,snd_seq_device
rc_pinnacle_pctv_hd 991 0
em28xx_rc 6094 0
evdev 9426 3
uvcvideo 68510 1
videobuf2_core 26995 1 uvcvideo
videobuf2_vmalloc 2425 1 uvcvideo
videobuf2_memops 2584 1 videobuf2_vmalloc
tda18271 36660 1
cxd2820r 20350 1
em28xx_dvb 15151 0
rc_it913x_v1 1173 0
em28xx 86093 2 em28xx_dvb,em28xx_rc
v4l2_common 9514 1 em28xx
videodev 104342 5 uvcvideo,em28xx,v4l2_common,videobuf2_core
media 13424 2 uvcvideo,videodev
videobuf_vmalloc 5358 1 em28xx
videobuf_core 20459 2 videobuf_vmalloc,em28xx
tveeprom 11605 1 em28xx
leds_gpio 2235 0
led_class 3562 1 leds_gpio
it913x_fe 31012 1
dvb_usb_it913x 12344 0
dvb_usb 17773 1 dvb_usb_it913x
dvb_core 97781 3 em28xx_dvb,dvb_usb,cxd2820r
rc_core 16540 7 dvb_usb,rc_it913x_v1,em28xx_rc,dvb_usb_it913x,rc_pinnacle_pctv_hd

Code: Select all

ls /dev/sd*
/dev/sda /dev/sda1

Code: Select all

sudo blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="2A1C-A09B" TYPE="vfat"
/dev/mmcblk0p2: UUID="41cd5bca-7a62-4952-b8e8-02c43aabb1d9" TYPE="ext4"
/dev/sda1: LABEL="2TB" UUID="68EC102FAC3FD312" TYPE="ntfs"

Code: Select all

sudo fdisk -l
Disk /dev/mmcblk0: 16.0 GB, 16012804096 bytes
4 heads, 16 sectors/track, 488672 cylinders, total 31275008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c7b31

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
/dev/mmcblk0p2 122880 31275007 15576064 83 Linux

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xaecf7683

Device Boot Start End Blocks Id System
/dev/sda1 2048 3907026943 1953512448 7 HPFS/NTFS/exFAT

Code: Select all

sudo mount|grep ^'/dev'
/dev/root on / type ext4 (rw,noatime,data=ordered)
/dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro)
/dev/sda1 on /media/2TB type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other,blksize=4096)

This is the error message I get:

Code: Select all

sudo udisks --unmount /dev/sda1 && udisks --detach /dev/sda
Detach failed: Error detaching: helper exited with exit code 1: Detaching device /dev/sda
USB device: /sys/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.6)
SYNCHRONIZE CACHE: FAILED: No such file or directory
(Continuing despite SYNCHRONIZE CACHE failure.)
STOP UNIT: FAILED: No such file or directory

I have run eject command as well, but got another error msg:

Code: Select all

sudo eject /dev/sda1
eject: unable to eject, last error: Invalid argument




So is it safe to unplug the USB Disk?

User avatar
rpdom
Posts: 15385
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Safe Removal / Detach / Eject of external HDD

Tue Jun 25, 2013 11:12 am

Have you tried

Code: Select all

sudo umount /dev/sda1 && sudo eject /dev/sda
Note the "1" on the first command, but just the disk name on the second.

marcelp1
Posts: 129
Joined: Mon Jun 11, 2012 8:41 pm

Re: Safe Removal / Detach / Eject of external HDD

Tue Jun 25, 2013 11:18 am

rpdom wrote:Have you tried

Code: Select all

sudo umount /dev/sda1 && sudo eject /dev/sda
Note the "1" on the first command, but just the disk name on the second.

Its the same error I got when running the eject on its own:

pi@RaspberryPi ~ $ sudo umount /dev/sda1 && sudo eject /dev/sda
eject: unable to eject, last error: Invalid argument

User avatar
rpdom
Posts: 15385
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Safe Removal / Detach / Eject of external HDD

Tue Jun 25, 2013 11:41 am

marcelp1 wrote:Its the same error I got when running the eject on its own:

pi@RaspberryPi ~ $ sudo umount /dev/sda1 && sudo eject /dev/sda
eject: unable to eject, last error: Invalid argument
Strange...
However the umount seems to have worked (wait a few seconds, then check with df or mount), so it should be safe to pull the drive. umount will have flushed all the buffered data to the disk before closing it.

The thing to watch for is that it doesn't get auto-mounted again before you disconnect it.

Return to “Beginners”