vermaden / scripts

Various scripts I wrote when using FreeBSD/Linux/UNIX systems for 15+ years.
https://vermaden.wordpress.com
146 stars 26 forks source link

Possibly adding script to format USB drives #12

Open lispstudent opened 1 year ago

lispstudent commented 1 year ago

Hello,

I have been using some of your script and learning from them quite a bit. I searched for a script to format a usb pen drive, e.g. fat32, but could not find any. Would you consider adding such script?

Many thanks,

vermaden commented 1 year ago

Hi,

there is no such script in my repo as its just a single command:

// FAT32 - the -L is for LABEL

# newfs_msdos -L 32GB /dev/da0

// exFAT - the -n is for LABEL

# mkexfatfs -n 32GB /dev/da0

// NTFS - the -L is for LABEL

# mkntfs -L 32GB -Q -F /dev/da0

The mkexfatfs(8) was installed by sysutils/exfat-utils package.

The mkntfs(8) was installed by sysutils/fusefs-ntfs package.

The newfs_msdos(8) is in the FreeBSD Base System.

The more important part is to clean the drive before creating new filesystem as it may be improperly detected.

// CLEAN

# gpart destroy -F da0
# dd < /dev/zero > /dev/da0 bs=1m status=progress count=16

Hope that helps.

Regards, vermaden

lispstudent commented 1 year ago

Thank you for the thorough examples.

I do use those commands manually several times a day, since I need to scan documents from a common scanner here at the university department, of which there are no drivers for FreeBSD (so, no network scanning).

I walk up to the room, insert an available USB stick, do the scanning, walk back, copy the files, and need to reformat the drive so that I can return it blank.

At some point I may have 3 or 4 USB stick inserted. I was hoping to have a script to:

  1. List all available USB sticks inserted,
  2. Ask me which one to format
  3. Ask which kind of format
  4. Ask for a label
  5. Force eject the drive, if somehow was still mounted
  6. Format the given device with the chosen format and label, according the standard you shown
  7. Print some kind of confirmation, such as "Ok to remove".

I know, if one does this only once in a blue moon, it is not worth it to write a script.