Wise people learn when they can; fools learn when they must - Arthur Wellesley

Wednesday, 22 February 2017

RHEL-6 (6) KNOW YOUR SYSTEM-P6 (USB)


RHEL-6 (6)
               KNOW YOUR SYSTEM-P6

USB DRIVE IN LINUX:
How to detect a USB drive in my system?
How to know the usb device name on my system?
How to know which File system is on usb drive?
How to get the usb controller info?
What to do if usb drive is If USB not detecting on my system?
How to mount a usb drive on my system?
How to eject the usb from my system?
How to unmount the usb from my system?
How to format the usb from my system?
How to make the USb drive usable in Windows as well as Linux?
What to do if unable to umount the usb?

Insert a usb drive and

[root@rhel6-client1 /]# tail -f /var/log/messages
Feb 15 01:14:21 rhel6-client1 dbus: avc:  received policyload notice (seqno=2)
Feb 15 01:14:22 rhel6-client1 dbus: avc:  received policyload notice (seqno=2)
Feb 15 01:14:22 rhel6-client1 dbus: [system] Reloaded configuration
Feb 15 01:15:56 rhel6-client1 kernel: Probing for vmci/PCI.
Feb 15 01:15:56 rhel6-client1 kernel: vmci 0000:00:07.7: PCI INT A -> GSI 16 (level, low) -> IRQ 16
Feb 15 01:15:56 rhel6-client1 kernel: Found vmci/PCI at 0x1080, irq 16.
Feb 15 01:15:56 rhel6-client1 kernel: VMCI: using capabilities 0xc.
Feb 15 01:15:56 rhel6-client1 kernel: Registered vmci device.
Feb 15 01:15:56 rhel6-client1 kernel: fuse init (API version 7.13)
Feb 15 12:35:20 rhel6-client1 kernel: lp0: using parport0 (interrupt-driven).
Feb 15 12:36:29 rhel6-client1 kernel: usb 1-1: new high speed USB device number 2 using ehci_hcd
Feb 15 12:36:30 rhel6-client1 kernel: usb 1-1: New USB device found, idVendor=8564, idProduct=1000
Feb 15 12:36:30 rhel6-client1 kernel: usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Feb 15 12:36:30 rhel6-client1 kernel: usb 1-1: Product: Mass Storage Device
Feb 15 12:36:30 rhel6-client1 kernel: usb 1-1: Manufacturer: JetFlash
Feb 15 12:36:30 rhel6-client1 kernel: usb 1-1: SerialNumber: 2EJYGXRU
Feb 15 12:36:30 rhel6-client1 kernel: usb 1-1: configuration #1 chosen from 1 choice
Feb 15 12:36:30 rhel6-client1 kernel: Initializing USB Mass Storage driver...
Feb 15 12:36:30 rhel6-client1 kernel: scsi3 : SCSI emulation for USB Mass Storage devices
Feb 15 12:36:30 rhel6-client1 kernel: usbcore: registered new interface driver usb-storage
Feb 15 12:36:30 rhel6-client1 kernel: USB Mass Storage support registered.
Feb 15 12:36:31 rhel6-client1 kernel: scsi 3:0:0:0: Direct-Access     JetFlash Transcend 32GB   8.07 PQ: 0 ANSI: 4
Feb 15 12:36:31 rhel6-client1 kernel: sd 3:0:0:0: Attached scsi generic sg2 type 0
Feb 15 12:36:31 rhel6-client1 kernel: sd 3:0:0:0: [sdb] 62939136 512-byte logical blocks: (32.2 GB/30.0 GiB)
Feb 15 12:36:31 rhel6-client1 kernel: sd 3:0:0:0: [sdb] Write Protect is off
Feb 15 12:36:31 rhel6-client1 kernel: sd 3:0:0:0: [sdb] Assuming drive cache: write through
Feb 15 12:36:31 rhel6-client1 kernel: sd 3:0:0:0: [sdb] Assuming drive cache: write through
Feb 15 12:36:31 rhel6-client1 kernel: sdb: sdb1
Feb 15 12:36:31 rhel6-client1 kernel: sd 3:0:0:0: [sdb] Assuming drive cache: write through
Feb 15 12:36:31 rhel6-client1 kernel: sd 3:0:0:0: [sdb] Attached SCSI removable disk
Feb 15 12:37:02 rhel6-client1 kernel: usb 1-1: USB disconnect, device number 2
OR
[root@rhel6-server ~]# dmesg |grep -i usb

Find the USB device name and FS,

[root@rhel6-client1 /]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00098740

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64         447     3072000   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3             447         577     1048576   83  Linux
Disk /dev/sdb: 32.2 GB, 32224837632 bytes  çç
199 heads, 57 sectors/track, 5548 cylinders
Units = cylinders of 11343 * 512 = 5807616 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9c03e0e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        5549    31469440    c  W95 FAT32 (LBA) ççUSB FS

[root@rhel6-client1 /]# blkid
/dev/sda6: UUID="a05fc3a5-ce73-4940-be2d-4a9c3a67e6b5" TYPE="ext4"
/dev/sda1: UUID="130956bb-09d8-4347-ba01-4a49f295793e" TYPE="ext4"
/dev/sda2: UUID="a94a74bc-fa8a-4b79-b593-88d973bcff06" TYPE="ext4"
/dev/sda3: UUID="3cee01e7-9c88-46df-bcab-ed3dc8b5af17" TYPE="ext4"
/dev/sda5: UUID="f80fe581-a59e-42d7-b0d6-e3db16bfbb16" TYPE="swap"
/dev/sdb1: LABEL="ANURAG" UUID="56BB-292E" TYPE="vfat" çç

[root@rhel6-client1 /]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 57.7M  0 rom
sda      8:0    0   20G  0 disk
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    3G  0 part /opt
├─sda3   8:3    0    1G  0 part /home
├─sda4   8:4    0    1K  0 part
├─sda5   8:5    0    1G  0 part [SWAP]
└─sda6   8:6    0 14.6G  0 part /
sdb      8:16   1   30G  0 disk
└─sdb1   8:17   1   30G  0 part çç

Find the USB device controller,

[root@rhel6-client1 /]# lspci -v | grep HCI
02:00.0 USB controller: VMware USB1.1 UHCI Controller (prog-if 00 [UHCI])
02:06.0 USB controller: VMware USB2 EHCI Controller (prog-if 20 [EHCI])
        Subsystem: VMware USB2 EHCI Controller

If USB not detected then,

[root@rhel6-client1 /]# modprobe usb-uhci
[root@rhel6-client1 /]# modprobe usb-ohci
[root@rhel6-client1 /]# modprobe usb-storage

[root@rhel6-client1 /]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              15G  3.2G   11G  23% /
tmpfs                 937M   72K  937M   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
/dev/sda3            1008M   34M  924M   4% /home
/dev/sda2             2.9G   69M  2.7G   3% /opt

Mount the USB device,

[root@rhel6-client1 /]# mount /dev/sdb1 /media/
[root@rhel6-client1 /]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              15G  3.2G   11G  23% /
tmpfs                 937M   72K  937M   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
/dev/sda3            1008M   34M  924M   4% /home
/dev/sda2             2.9G   69M  2.7G   3% /opt
/dev/sdb1              31G  4.3G   26G  15% /media

Ejecting a USB drive,

[root@rhel6-server ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom
sda      8:0    0   20G  0 disk
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    3G  0 part /opt
├─sda3   8:3    0    1G  0 part /home
├─sda4   8:4    0    1K  0 part
├─sda5   8:5    0    1G  0 part [SWAP]
└─sda6   8:6    0 14.6G  0 part /
sdb      8:16   0   20G  0 disk
sdc      8:32   0   20G  0 disk
sdd      8:48   1  7.2G  0 disk
└─sdd1   8:49   1  7.2G  0 part çç

[root@rhel6-server ~]# eject /dev/sdd
OR
[root@rhel6-client1 /]# udisks --detach /dev/sdb

Umount a USB drive,

[root@rhel6-client1 /]# udisks --unmount /dev/sdb
OR
[root@rhel6-client1 /]# umount /media/

HOW TO FORMAT A USB DRIVE:

[root@rhel6-server ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom
sda      8:0    0   20G  0 disk
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    3G  0 part /opt
├─sda3   8:3    0    1G  0 part /home
├─sda4   8:4    0    1K  0 part
├─sda5   8:5    0    1G  0 part [SWAP]
└─sda6   8:6    0 14.6G  0 part /
sdb      8:16   0   20G  0 disk
sdc      8:32   0   20G  0 disk
sdd      8:48   1  7.2G  0 disk
└─sdd1   8:49   1  7.2G  0 part çç

[root@rhel6-server ~]# fdisk -l |grep -i "^disk"
Disk /dev/sda: 21.5 GB, 21474836480 bytes
Disk identifier: 0x00098740
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
Disk identifier: 0x00000000
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
Disk identifier: 0x00000000
Disk /dev/sdd: 7761 MB, 7761035264 bytes çç
Disk identifier: 0x00000000
[root@rhel6-server ~]#
[root@rhel6-server ~]# mount /dev/sdd1 /media/
[root@rhel6-server ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              15G  6.5G  7.2G  48% /
tmpfs                 497M   72K  497M   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
/dev/sda3            1008M   34M  924M   4% /home
/dev/sda2             2.9G   69M  2.7G   3% /opt
.host:/               108G  103G  5.3G  96% /mnt/hgfs
/dev/sdd1             7.3G   16K  7.3G   1% /media çç

Unmounts before formatting,

[root@rhel6-server ~]# umount /media/

[root@rhel6-server ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              15G  6.5G  7.2G  48% /
tmpfs                 497M   72K  497M   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
/dev/sda3            1008M   34M  924M   4% /home
/dev/sda2             2.9G   69M  2.7G   3% /opt
.host:/               108G  103G  5.3G  96% /mnt/hgfs

Now format it,

[root@rhel6-server ~]# mkfs.ext4 /dev/sdd1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
474208 inodes, 1894780 blocks
94739 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1941962752
58 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

That was nice, but now it is unusable in windows b’coz of “ext4” FS.

After re-inserting in windows, it will not recognize by windows and we will force to format the drive.
Do a format to use it in windows.

But I want to use it in both Linux and Windows…!!

[root@rhel6-server ~]# mkfs.vfat /dev/sdd1
mkfs.vfat 3.0.9 (31 Jan 2010)
     
[root@rhel6-server ~]# cd /media/
[root@rhel6-server media]# touch 123
[root@rhel6-server ~]# umount /media
umount: /media: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@rhel6-server ~]# fuser -c /media/
/media/:              7367

[root@rhel6-server ~]# ps -ef | grep 7367
root      7367  7314  0 18:33 pts/0    00:00:00 vi /media/qqq
root      7399  7374  0 18:34 pts/1    00:00:00 grep 7367

We can see that a “vi” is open in that volume. Either we can complete the task and close “vi’ gracefully, or

[root@rhel6-server ~]# kill -9 7314

[root@rhel6-server ~]# umount /media

Now it is detecting in windows and showing the file “123” as well.





No comments:

Post a Comment