Linux remove usb device

How to remove a USB drive without worrying if its been unmounted? [duplicate]

Sometimes I unplug my USB drive only to find out files were not written to it. I suppose the only way to ensure files are written to it is to right click on the USB drive on the desktop and then select «un-mount», but sometimes I forget. What is the best way to ensure files are written to the USB drive instantly? This way I can remove the USB drive as soon as I notice the LED light on the USB drive stopped blinking. OS: CentOS 6

Disable the write cache. Maybe hdparm -W0 /dev/sdX (where sdX is your USB device) can do this, but I’m not really sure. Also I don’t know how one can disable the write cache for USB devices by default.

@MartinvonWittich — the other one is a post by a known troll, I’m attempting to save my answer and Gilles’ answers and also a decent question.

3 Answers 3

This is Gilles’ answer, saving it here so it doesn’t get lost.

If you use the sync mount option on the removable drive, all writes are written to the disk immediately, so you won’t lose data from not-yet-written files. It’s a bad idea, but it does what you’re asking, kind of.

Note that sync does not guarantee that you won’t lose data. Unmounting a removable drive also ensures that no application has a file open. If you don’t unmount before unplugging, you won’t notice if you have unsaved data until it’s too late. Unmounting while a file is open also increases the chance of corruption, both at the filesystem level (the OS may have queued some operations until the file is closed) and at the application level (e.g. if the application puts a lock file, it won’t be removed).

Furthermore, sync is bad for the lifetime of the device. Without the sync option, the kernel reorders writes and writes them in batches. With the sync option, the kernel writes every sector in the order requested by the applications. On cheap flash media that doesn’t reallocate sectors (meaning pretty much any older USB stick, I don’t know if it’s still true of recent ones), the repeated writes to the file allocation table on (V)FAT or to the journal on a typical modern filesystem can kill the stick pretty fast.

Therefore I do not recommend using the sync mount option.

On FAT filesystems, you can use the flush mount option. This is intermediate between async (the default) and sync : with the flush option, the kernel flushes all writes as soon as the drive becomes idle, but it does not preserve the order of writes (so e.g. all writes to the FAT are merged).

Читайте также:  Can linux mount ntfs

Источник

How do I remove a usb device?

I’ve got a controller hooked up that is a pain to unplug. It’s a steering wheel with pedals and in some applications/games it acts like I’m holding down on a joystick. When I’m in Windows I simply open devices & printers, right click the icon for the steering wheel and select remove. How can I do this on Ubuntu? Preferably with an easy command I can alias.

1 Answer 1

Open nautilus. In the side bar is a list of external drives. Click the Eject (⏏) button.

If you can’t see this, press F9 .

enter image description here

This only applies to storage devices.

Open Terminal ( Ctrl + Alt + T )

$ xinput ⎡ Virtual core pointer [master pointer (3)] ⎜ Virtual core XTEST pointer [slave pointer (2)] ⎜ Mitsumi Electric Apple Optical USB Mouse [slave pointer (2)] ⎜ Microsoft Trackball Explorer® [slave pointer (2)] ⎣ Virtual core keyboard [master keyboard (2)] Virtual core XTEST keyboard [slave keyboard (3)] Power Button [slave keyboard (3)] Power Button [slave keyboard (3)] UVC Camera (046d:08c9) [slave keyboard (3)] BTC USB Multimedia Keyboard [slave keyboard (3)] BTC USB Multimedia Keyboard [slave keyboard (3)] Eee PC WMI hotkeys [slave keyboard (3)] 

You should be able to see it there, for example my mouse is a Microsoft Trackball Explorer® and it has an id of 10 .

Yours will also have an id. Run the following command:

then to enable it (if you want)

a restart also resets this, so they will all become active again.

Источник

Linux (Ubuntu): safely remove a USB flash disk via the command line [closed]

Is there anything wrong with umount ? As in, umount /media/A . The command might be hidden a bit out of the way (perhaps /sbin instead of /bin ), but it is a fundamental command and is likely to be in one of those two (or, possibly, /usr/sbin ).

After umounting, the flash disk is still not ready for remove. This link is the best explanation I ever saw: askubuntu.com/questions/5845/… It seems to me that this is because of the USB power supply. So the disk disappears from nautilus yet removing it is just not «safe».

After unmounting, you can unplug it. The only thing that would still be going through the wires should be power. if it’s not, something is seriously wrong with your computer.

Cole would you please give me some reference? A comprehensive ref list will form an excellent answer.

1 Answer 1

You can do this using udisks. It is not installed by default, but it is easy enough to install (the package is like a megabyte in size once installed).

sudo apt-get install udisks 

Once installed, you can detach a USB drive with the following commands.

sudo udisks --unmount /dev/sdb1 sudo udisks --detach /dev/sdb 

The first line unmounts it. Just like any other partition you can still remount it at this point. The second line detaches it. After this it is powered down and you have to remove/reinsert it to remount.

Читайте также:  Windows xp theme linux mint

To clarify, sdb is the device and sdb1, sdb2, sdb3, etc. are partitions on the device. Also, you will need to unmount all mount points before you attempt to detach the device. Usually with a USB stick/drive there is only one but it is a warning you should know about none the less.

Getting the device name from the mount point would require you pull it from mount or something.

Источник

How to remove a USB drive without worry if its been unmounted?

Sometimes I unplug my usb drive only to find out files were not written to it. I suppose the only way to ensure files are written to it is to right click on the USB drive on the desktop and then select «un-mount», but sometimes I forget. What is the best way to ensure files are written to the USB drive instantly? This way I can remove the USB drive as soon as I notice the LED light on the USB drive stopped blinking. OS: CentOS 6

Probably the best you can do is to mount with the sync option. However, it’s always safer to unmount a file system.

This is just something you have to remember to do. I’ve never seen anything available that can do what you’re asking.

@slm, if it was mac os x, you simply wait for the usb drive to stop blinking if it has a led light on it for example. ( all my usb drives have lights ). and then i’d remove it. why can’t it be like that in centos linux as well ?

2 Answers 2

If you use the sync mount option on the removable drive, all writes are written to the disk immediately, so you won’t lose data from not-yet-written files. It’s a bad idea, but it does what you’re asking, kind of.

Note that sync does not guarantee that you won’t lose data. Unmounting a removable drive also ensures that no application has a file open. If you don’t unmount before unplugging, you won’t notice if you have unsaved data until it’s too late. Unmounting while a file is open also increases the chance of corruption, both at the filesystem level (the OS may have queued some operations until the file is closed) and at the application level (e.g. if the application puts a lock file, it won’t be removed).

Furthermore, sync is bad for the lifetime of the device. Without the sync option, the kernel reorders writes and writes them in batches. With the sync option, the kernel writes every sector in the order requested by the applications. On cheap flash media that doesn’t reallocate sectors (meaning pretty much any older USB stick, I don’t know if it’s still true of recent ones), the repeated writes to the file allocation table on (V)FAT or to the journal on a typical modern filesystem can kill the stick pretty fast.

Читайте также:  Linux настройка nat iptables

Therefore I do not recommend using the sync mount option.

On FAT filesystems, you can use the flush mount option. This is intermediate between async (the default) and sync : with the flush option, the kernel flushes all writes as soon as the drive becomes idle, but it does not preserve the order of writes (so e.g. all writes to the FAT are merged).

Источник

How do I soft remove a usb port?

cat /proc/interrupts | grep 16: 16: 31 0 0 0 0 0 0 0 IR-IO-APIC 16-fasteoi ehci_hcd:usb3 
root@blackserver:/sys/devices/pci0000:00/0000:00:1a.0/usb3# echo -n 1 > remove 

gives me an error «bash: echo: write error: Invalid argument» yet dmesg output says «usb 3-1: USB disconnect, device number 2» yet still the device is using the interrupt. Is this a bug or is my approach wrong? EDIT:

Bus 004 Device 002: ID 8087:8001 Intel Corp. Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 003 Device 002: ID 8087:8009 Intel Corp. Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 004: ID 2109:0812 VIA Labs, Inc. VL812 Hub Bus 002 Device 003: ID 2109:0812 VIA Labs, Inc. VL812 Hub Bus 002 Device 002: ID 174c:3074 ASMedia Technology Inc. ASM1074 SuperSpeed hub Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply Bus 001 Device 009: ID 045e:0745 Microsoft Corp. Nano Transceiver v1.0 for Bluetooth Bus 001 Device 008: ID 046d:0826 Logitech, Inc. HD Webcam C525 Bus 001 Device 007: ID 2109:2812 VIA Labs, Inc. VL812 Hub Bus 001 Device 006: ID 045e:02d1 Microsoft Corp. XBOX One Controller for Windows Bus 001 Device 004: ID 2109:2812 VIA Labs, Inc. VL812 Hub Bus 001 Device 003: ID 174c:2074 ASMedia Technology Inc. ASM1074 High-Speed hub Bus 001 Device 002: ID 0b05:17cb ASUSTek Computer, Inc. Broadcom BCM20702A0 Bluetooth Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
kelvin@blackserver:~$ dmesg | grep :1a [ 0.178287] pci 0000:00:1a.0: [8086:8cad] type 00 class 0x0c0320 [ 0.178310] pci 0000:00:1a.0: reg 0x10: [mem 0xefd3b000-0xefd3b3ff] [ 0.178369] pci 0000:00:1a.0: PME# supported from D0 D3hot D3cold [ 0.178403] pci 0000:00:1a.0: System wakeup disabled by ACPI [ 0.675933] DMAR: Setting identity map for device 0000:00:1a.0 [0xade98000 - 0xadea6fff] [ 0.676154] iommu: Adding device 0000:00:1a.0 to group 7 [ 0.837462] ehci-pci 0000:00:1a.0: EHCI Host Controller [ 0.837481] ehci-pci 0000:00:1a.0: new USB bus registered, assigned bus number 3 [ 0.837509] ehci-pci 0000:00:1a.0: debug port 2 [ 0.842160] ehci-pci 0000:00:1a.0: cache line size of 64 is not supported [ 0.842174] ehci-pci 0000:00:1a.0: irq 16, io mem 0xefd3b000 [ 0.853306] ehci-pci 0000:00:1a.0: USB 2.0 started, EHCI 1.00 [ 0.857162] usb usb3: SerialNumber: 0000:00:1a.0 
root@blackserver:/sys/devices/pci0000:00/0000:00:1a.0# echo -n 1 > remove 
[65207.355668] ehci-pci 0000:00:1a.0: remove, state 4 [65207.355680] usb usb3: USB disconnect, device number 1 [65207.355682] usb 3-1: USB disconnect, device number 2 [65207.360110] ehci-pci 0000:00:1a.0: USB bus 3 deregistered [65207.475341] iommu: Removing device 0000:00:1a.0 from group 7 

No other error messages and the USB controller is no longer listed in lspci or devices shown in lsusb.

Источник

Оцените статью
Adblock
detector