0

using
Ubuntu 20.04.4 LTS (Focal Fossa)
GNU bash, version 5.1.16(1)

List all drives: UNmounted and mounted

lsblk --noheadings --raw | awk '{print substr($0,0,4)}' | uniq -c | grep 1 | awk '{print "/dev/"$2}' ;

/dev/loop
/dev/sda
/dev/sda1
/dev/sda2
/dev/sda5
/dev/sdb
/dev/sdb1
/dev/sdc
/dev/sdd
/dev/sdd1

From above bash, we have 2 usb sticks c and d as:
/dev/sdc FAT (32-bit version)
/dev/sdd
/dev/sdd1 FAT (32-bit version)

How come sdd has 2 entries?
/dev/sdd
/dev/sdd1 FAT (32-bit version)

How to format usb sdc to get 2 entries like sdd above?

Why?

Because it seems that 2 entries behaves better for
UNmounting usb manually via DISKs and
mounting usb via a bash script below.

Show UNmounted drives and Show Extended Partition Types:

lsblk --noheadings --raw -o NAME,MOUNTPOINT | awk '$1~/[[:digit:]]/ && $2 == ""' ;

Show stats: UNmounted drives and Extended Partition Type:

lsblk --noheadings --raw | awk '$1~/s.*[[:digit:]]/ && $7==""' ;

Mount drives via bash. Then do virus scanning:
lsblk --noheadings --raw | awk '{print substr($0,0,4)}' | uniq -c | grep 1 | awk '{print "/dev/"$2}' | grep -E "(/dev/sd.)[[:digit:]]" | xargs -I{} -n1 udisksctl mount -b {} ;

Mounted /dev/sdd1 at /media/u3/USBstick

/dev/sdc FAT (32-bit version)
is manually UNmounted and
above bash script does not mount /dev/sdc

/dev/sdd
/dev/sdd1 FAT (32-bit version)
is manually UNmounted and
above bash script works.
Mounts sdd

Target is to have bash script mount all drives before a virus scan.

Explain.
Why sdc is only 1 entry versus 2 for sdd?
/dev/sdc FAT (32-bit version)
/dev/sdd
/dev/sdd1 FAT (32-bit version)

Explain.
How to format sdc?
So sdc responds to above bash mount script
like sdd responds.

--

joseph22
  • 157
  • 1
  • 9
  • `sdd` is a whole block device. `sdd1` is the first partition within the device. See a table in [this answer](https://unix.stackexchange.com/a/705262/108618). A setup where there is no partition table and a filesystem takes the whole device is called "superfloppy". See this question: [Uses of single-partition disk configuration](https://superuser.com/q/1181320/432690). The fact you and your script are confused kinda confirms what I said in my answer there. – Kamil Maciorowski Jun 10 '22 at 04:09
  • 1. Formatting usb by DISKs results in unwanted 'superfloppy' ```sdc``` meaning ```sdc1``` is absent . 2. Format usb by ```sudo mkfs.vfat /dev/sdc``` results with message ```mkfs.fat 4.1 (2017-01-24)``` and ```mkfs.vfat: unable to open /dev/sdc: No medium found```. How to format usb? to reach the target ```sdc``` with ```sdc1``` being the first partition within the device. i understand 'Programs may expect a partition table first, a filesystem later.' i understand this means the mount script expects ```sdc``` with partition ```sdc1``` . – joseph22 Jun 10 '22 at 14:07
  • FYI: `$ lsblk -o PATH` replaces most parts of your initial thing ending in "awk". – Hannu Jun 10 '22 at 17:38
  • Hi Hannu, ```$ lsblk -o PATH``` works, meaning, List all drives: UNmounted and mounted, but 16 items were Listed and are of no interest, being ```/dev/loop0``` to ```/dev/loop15``` . The first script of 102 characters shortens uninteresting data to 1 item ```/dev/loop```. i read ```/dev/loopX``` are virtual devices, read only, connected to the snapd service, extra loop devices added for every software you install using "snap" and ```/dev/loopX``` can be removed by uninstalling the app via snapd. Any ideas how to format usb? to get ```sdc``` and ```sdc1``` . – joseph22 Jun 10 '22 at 20:18

0 Answers0