Handeling removable disks under ESATA

From GammaSphere DAQ
Revision as of 15:31, September 20, 2021 by Copp (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

These are (terse) write-ups of how to mount/unmount, as well a format disks, on the gs and dgs machines using the ESATA interface (works for usb as well).

To mount a Disk

power disk up and type 'dmesg' to see what device name the computer chose. You should see something like this at the bottom of the list: (NOTE: it may take a little while before the disk is recognized!!)

.
.
.
[1624926.943952] usb 2-1: Product: STORE N GO
[1624926.943954] usb 2-1: Manufacturer: Verbatim
[1624926.943956] usb 2-1: SerialNumber: 07A3130929761542
[1624926.944802] scsi22 : usb-storage 2-1:1.0
[1624927.978847] scsi 22:0:0:0: Direct-Access     Verbatim STORE N GO       5.00 PQ: 0 ANSI: 0 CCS
[1624927.983253] sd 22:0:0:0: Attached scsi generic sg8 type 0
[1624928.496834] sd 22:0:0:0: [sdd] 7827456 512-byte logical blocks: (4.00 GB/3.73 GiB)
[1624928.498952] sd 22:0:0:0: [sdd] Write Protect is off
[1624928.498955] sd 22:0:0:0: [sdd] Mode Sense: 03 41 00 00
[1624928.501080] sd 22:0:0:0: [sdd] No Caching mode page present
[1624928.501084] sd 22:0:0:0: [sdd] Assuming drive cache: write through
[1624928.508574] sd 22:0:0:0: [sdd] No Caching mode page present
[1624928.508577] sd 22:0:0:0: [sdd] Assuming drive cache: write through
[1624928.530109]  sdd: sdd1
[1624928.535695] sd 22:0:0:0: [sdd] No Caching mode page present
[1624928.535698] sd 22:0:0:0: [sdd] Assuming drive cache: write through
[1624928.535701] sd 22:0:0:0: [sdd] Attached SCSI removable disk
[1624928.869338] SELinux: initialized (dev sdd1, type vfat), uses genfs_contexts
[1625347.268862] SELinux: initialized (dev sdd1, type vfat), uses genfs_contexts

or use

 lsblk

to see what disks are there. Not all systems have this handy utility.

then do

 sudo e2label /dev/sdd1

to see if the disk has an identifying label (see how to give a partition an identifying label below); which you can then use as

 mkdir ~/esata/`sudo e2label /dev/sdd1`
 sudo /bin/mount /dev/sdd1 ~/esata/`sudo e2label /dev/sdd1`
 lsblk
 df | grep `sudo e2label /dev/sdd1`


To Unmount the Disk Again

 sync;sync;sync
 sudo /bin/umount /dev/sdd1

If you cannot unmount the disk, make sure you (or someone else) have not cd'ed to the disk in some window somewhere. Sometimes 'lsof | grep cwd' is useful in order to reveal who is cd'ed to the disk


Trouble Unmounting a USB Disk

Sometimes a user has cd'ed to a USB disk in some window (shell) and then if someone else tries to unmount the disk they will get a message like this:

 umount: /media/120514a: umount failed: Operation not permitted

The solution is to find the offending process and kill it cold. If the disk is labeled '120514a', then the steps are:

  lsof | grep 120514a

you might see something like this

 bash       8367       dgs  cwd       DIR       8,49    20480   61341743 /media/120514a/user/cs

you can now kill this offending process as

  kill -9 8367

and then you can do

  umount /media/120514a

To Format a Disk

WARNING: do not format the wrong disk, our you could get into big trouble!! If you are uncertain about how to format a disk, it is best to ask for help.

follow the procedure under 'to mount a disk:' to find the device name. Here we will assume '/dev/sdd'

partition the disk using fdisk:

 sudo /sbin/fdisk /dev/sdd

typically, for a new disk, you would simply say:

 p
 n
 p
 1
 hit return for default
 hit return for default
 w

this will create the partition '/dev/sdd1' which we will now impose a linux EXT4 file system on as

sudo /sbin/mkfs.ext4 -m 0 /dev/sdd1

to be able to write to the 5% of the disk that is normally reserved for root. For a data disk this is OK, but for a system disk it is a bad idea.

On some machines this takes a long time (e.g., scientific linux) , on others it is very fast (e.g., fedora 15)

It is a good idea to give the disk a UNIQUE label that makes sense to you, maybe just the date and a serial character:

 sudo /sbin/e2label /dev/sdd1  20120611a

With this label, if this disk is mounted automatically as a usb disk, it will then come up as /media/20120611a

You can now mount the disk using the instructions under 'to mount a disk:'

 sudo /bin/mount /dev/sdd1 ~/data1

for other than root to be able to write to the disk, do this

 sudo mkdir ~/data1/user
 sudo chmod a+rwx ~/data1/user

you should now see something like this

 ls -l ~/data1
 total 20
 drwx------. 2 root root 16384 Jun 11 11:04 lost+found/
 drwxrwxrwx. 2 root root  4096 Jun 11 11:30 user/

and anyone can write to '~/data1/user'. now unmount again as

 sudo /bin/umount /dev/sdd1


Setting up Sudo

reminder for system managers regarding how sudo is set up for the above procedures to work


visudo

 Cmnd_Alias ESATAFORMAT = /sbin/e2label, /sbin/fdisk, /sbin/mkfs.ext4, /bin/mkdir, /bin/chmod
 gamuser ALL=ESATAFORMAT
 dgs     ALL=ESATAFORMAT
 Cmnd_Alias ESATAMOUNT = /bin/mount, /bin/umount
 gamuser ALL=ESATAMOUNT
 dgs     ALL=ESATAMOUNT

your system manager may or may not be friendly enough to let you do this...