Why?


Search This Blog

Thursday, May 21, 2015

Format and Mount USB Flash Drive in Centos 6.6



Format and Mount USB Flash Drive in Centos 6.6

I am using this solely for my Linux box to backup files. So in this case I am using etx4. If I was going to use this for Linux and PC I would have used another file system, like FAT32.

I am using the PNY 128GB USB 3.0 stick in this example.

If you don’t have the package “parted” installed already, please do so with:

# yum -y install parted

Plug USB stick in and identify what device it is.

# fdisk -l
Disk /dev/sdf: 137.4 GB, 137438953472 bytes
255 heads, 63 sectors/track, 16709 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: 0x00000000

From the above output I can see my PNY 128GB USB stick as /dev/sdf. Now let’s clean this so we can get a fresh partition table on it and then format it. The dd command below should erase the 1MB of data on the stick, removing the partition information. **NOTE make sure you have the correct device or you will nuke the wrong drive.

# dd if=/dev/zero of=/dev/sdf bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.00843536 s, 124 MB/s

Now let’s put a partition on it with parted.

# parted /dev/sdf
GNU Parted 2.1
Using /dev/sdf
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

Type p then press enter key to see what’s on there already.

(parted) p
Error: /dev/sdf: unrecognised disk label
(parted)

Perfect. Nothing there. Now use mklabel to label it.

(parted) mklabel gpt
(parted)

Now see whats on it.

(parted) p
Model: PNY USB 3.0 FD (scsi)
Disk /dev/sdf: 137GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted)

Sweet. We now have it labeled and can format it. First let’s get out of parted.

(parted) q
#

Now let’s format it with ext4 file system

# mkfs.ext4 /dev/sdf
mke2fs 1.41.12 (17-May-2010)
/dev/sdf is entire device, not just one partition!
Proceed anyway? (y,n) y

Be patient. When finished the last few lines should like:

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
#

Now let’s get this mounted so we can us it. Lest make directory for the mount point first.

# mkdir /mnt/usb

Now mount it.

# mount -t ext4 /dev/sdf /mnt/usb

Make sure it’s there.

# df -h
/dev/sdf              126G   60M  120G   1% /mnt/usb

Now let’s add the mount to the fstab file for auto mounting, like on reboot.

# vi /etc/fstab

And add the following line to the bottom of the file.

/dev/sdf      /mnt/usb      ext4      defaults        0 0

Now let’s make sure this will load at boot, without rebooting.

# umount /mnt/usb
# df -h

We should not see our USB stick mounted anymore. Now check for auto mounting.

# mount -a
# df -h
/dev/sdf              126G   60M  120G   1% /mnt/usb

So got everything working now. Let’s check the speed of this new USB stick. I have renamed a windows 7 iso file to blob.iso and copied that to my /root directory on this server (server with the USB stick mounted now). /root is on a Samsung 128GB SSD connected to mother board SATA 3 controller. I have also copied this file to /myriad which is a zfs raidz2 pool with 4 WD RED 3TB drives in it connected to mother board SATA 3 controller. Will now copy this file from each of those locations, and then from the USB stick to each location, using rsync. This will allow us to get some real world speed test.

BTW: The copy of this file from /root to /myriad was:

# rsync -h --progress /root/blob.iso /myraid/blob.iso
blob.iso
       3.32G 100%  263.30MB/s    0:00:12 (xfer#1, to-check=0/1)

sent 3.32G bytes  received 31 bytes  265.59M bytes/sec
total size is 3.32G  speedup is 1.00
#

Now for the USB test from /root

# rsync -h --progress /root/blob.iso /mnt/usb/blob.iso
blob.iso
       3.32G 100%  130.25MB/s    0:00:24 (xfer#1, to-check=0/1)

sent 3.32G bytes  received 31 bytes  99.10M bytes/sec
total size is 3.32G  speedup is 1.00
#

Now for the USB test from /myriad

# rsync -h --progress /myraid/blob.iso /mnt/usb/blob.iso
blob.iso
       3.32G 100%  194.95MB/s    0:00:16 (xfer#1, to-check=0/1)

sent 3.32G bytes  received 31 bytes  135.51M bytes/sec
total size is 3.32G  speedup is 1.00
#

Now from USB to /root

# rsync -h --progress /mnt/usb/blob.iso /root/blob2.iso
blob.iso
       3.32G 100%  172.74MB/s    0:00:18 (xfer#1, to-check=0/1)

sent 3.32G bytes  received 31 bytes  170.25M bytes/sec
total size is 3.32G  speedup is 1.00
#

Now from USB to /myriad

# rsync -h --progress /mnt/usb/blob.iso /myraid/blob2.iso
blob.iso
       3.32G 100%  131.75MB/s    0:00:24 (xfer#1, to-check=0/1)

sent 3.32G bytes  received 31 bytes  135.51M bytes/sec
total size is 3.32G  speedup is 1.00
#

Final results:

From /root to /myraid = 265.59M bytes/sec
From /root to /mnt/usb = 99.10M bytes/sec (write to USB from SSD)
From /myriad to /mnt/usb = 135.51M bytes/sec (write to USB from zfs pool)
From /mnt/usb to /root = 170.25M bytes/sec (read from USB to SSD)
From /mnt/usb to /myriad = 135.51M bytes/sec (read from USB to zfs pool)

I expected to see the the SSD (/root) to have the fastest in both read and write. Not sure why I have such a slow read from on that. Will have to check that out. You can also see i got the same numbers on read and write with the /myraid (zfs pool), like exactly the same! Again more testing needed on this as well. I am thinking my zfs pool numbers have something to do with the RAM/Cache.

Not as fast as I would have hoped for but livable. I tried a SanDisk USB 3.0 stick a few weeks back and was getting like 40MB reads and 20MB writes. I quickly returned that stick. This new PNY is over 4x faster, and half the price compared to the Staples SanDisk to the Amazon online ordered PNY.

My system for testing is:
  • Gigabyte Z97N iTX Mother Board
  • i5 4590 3.3GHZ 6MB Cache CPU
  • Cool Master Hyper 212 EVO CPU Cooler
  • 8GB (2x4GB) DDR3 1866MHZ Corsair Vengeance RAM
  • 1x 128GB Samsung PRO SSD used for boot and OS
  • 4x WD RED 3TB SATA III in zfs raidz2 pool
  • Antec 450 WATT 80 PLUS Power Supply
  • Fractal Design Node 304 Case

Major software used on this box:
  • Centos 6.6 (fully updated and patched)
  • Asterisk 11.17.1
  • Plex Media Server 0.9.12.1
  • KVM 2.6.32-504.16.2.el6.x86_64
  • SAMBA 3.6.23-14.el6_6
  • NFS 1.2.3-54.el6

Wanting to get in future:
  • More RAM (so I can start playing more with my KVM)
  • 10GB Ethernet (more is better)

I use this box for my home phone, media server, NAS, and KVM server. I have been very happy with it and it does whatever I have asked of it, unlike my ex girlfriend.



No comments:

Post a Comment