# Gpart does not see USB stick



## balanga (Mar 19, 2017)

When I insert a particular USB stick, a msg comes up and it is identified as da1, but `gpart` does not see it. How do I access it under FreeBSD? It shows up OK in Windows.


----------



## aragats (Mar 19, 2017)

balanga said:


> it is identified as da1, but  gpart  does not see it


What do you mean by saying _*does not see*_? Have you run: `$ gpart show /dev/da1`?
If you don't have /dev/da1s1, that most probably means the flash drive is formatted without partitioning.


----------



## Phishfry (Mar 19, 2017)

Maybe it is formatted with NTFS and you would need Fuse.


----------



## Phishfry (Mar 20, 2017)

Actually NTFS shows up under `gpart show`. I had to try it to see. It will not mount without fuse.


```
root@DELL:~ # gpart show da0
=>       1  30031249  da0  MBR  (14G)
         1        31       - free -  (16K)
        32  30031218    1  ntfs  (14G)
```


----------



## aragats (Mar 20, 2017)

Phishfry said:


> Actually NTFS shows up under  gpart show


Right, because there is a _*partition*_ with NTFS, but what if you create a filesystem directly on /dev/da0?
Such preformatted USB flashdrives are rare nowadays, but they used to be "popular" some time ago.


----------



## balanga (Mar 20, 2017)

aragats said:


> What do you mean by saying _*does not see*_? Have you run: `$ gpart show /dev/da1`?
> If you don't have /dev/da1s1, that most probably means the flash drive is formatted without partitioning.



It looks like there are no partitions on it, but I can access it from Windows. I can boot from it also.
.
I want to copy the data onto a smaller stick - it's only using 2GB out of 128GB!! as 

Clonezilla won't let me back it up because it sees no partitions, and while FreeBSD recognises it when it's plugged in, I see no way of accessing it as it doesn't show up using `gpart`.


----------



## balanga (Mar 20, 2017)

Phishfry said:


> Maybe it is formatted with NTFS and you would need Fuse.



It is NTFS formatted, but it doesn't show up with `gpart` because there are no partitions.


----------



## aragats (Mar 20, 2017)

balanga said:


> Clonezilla won't let me back it up because it sees no partitions


First you should use ntfsresize(8) to shrink down the filesystem. Alternatively you can do it in Windows via Disk Manager.
Then you can use `dd if=/dev/da1 of=backup.img bs=1M count=2048` to back it up (and then copy to another flash drive).
(Of course, you should check the actual size to use it with the _*count*_ option).


----------



## balanga (Mar 20, 2017)

Thanks for pointing out ntfsresize(8) - never heard of it before... Unfortunately it doesn't work - says

```
NTFS signature is missing
ERROR(22): Opening '/dev/da1' as NTFS failed: Invalid argument
```

Windows Disk Manager shows the device but the option for shrinking is greyed out.

As for the `dd` command how do I work out the value of *count* ?


----------



## aragats (Mar 20, 2017)

balanga said:


> As for the  dd command how do I work out the value of *count* ?


bs = block size, if you set it to 1M, correspondingly, with count=1024 you'll copy 1M x 1024 = 1G.

However, if you're not able to resize, you'll have to copy the entire volume, in such case just omit _*count*_, `dd` will copy until the end.


----------



## balanga (Mar 25, 2017)

Is there any way to mount a USB stick which  is formatted NTFS (or even FAT32) if it has no partition on it?

`gpart` does not see it, but `camcontrol devlist` does.


----------



## aragats (Mar 25, 2017)

For NTFS install sysutils/fusefs-ntfs, then
	
	



```
# kldload fuse
# ntfs-3g /dev/da1 /your/mount/point
```
For FAT32 you don't need fuse, just
	
	



```
# mount -t msdosfs /dev/da1 /your/mount/point
```


----------



## balanga (Mar 25, 2017)

Check the title of the thread. The device is not seen by `gpart`.


----------



## aragats (Mar 25, 2017)

balanga said:


> The device is not seen by gpart.


What gpart has to do with mounting???
The commands mentioned above always worked. As I mentioned in previous comments, such paritionless USB drive were very common several years ago.


----------



## balanga (Mar 25, 2017)

I get 

```
NTFS signature is missing;
Failed to mount '/dev/da1'; Invalid argument
The device '/dev/da1' doesn't seem to have a vaild NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?
```


----------



## aragats (Mar 26, 2017)

Maybe it's not NTFS. Microsoft likes exFAT too. You may try sysutils/exfat-utils.
	
	



```
# mount.exfat /dev/da1 /your/mount/point
```


----------



## aragats (Mar 26, 2017)

OK, I've just formatted a USB flash drive with NTFS without partitioning it and copied some files into it, see:
	
	



```
[b]$ dmesg | tail[/b]
ugen1.5: <Kingston> at usbus1
umass0: <Kingston DT Micro, class 0/0, rev 2.00/1.00, addr 5> on usbus1
umass0:  SCSI over Bulk-Only; quirks = 0xc100
umass0:4:0: Attached to scbus4
da0 at umass-sim0 bus 0 scbus4 target 0 lun 0
da0: <Kingston DT Micro PMAP> Removable Direct Access SPC-2 SCSI device
da0: Serial Number 1C6F654E59A2BCB0B904021C
da0: 40.000MB/s transfers
da0: 14996MB (30712320 512 byte sectors)
da0: quirks=0x2<NO_6_BYTE>
[b]$ ll /dev/da0*[/b]
crw-r-----  1 root  operator   0xb6 Mar 25 19:56 /dev/da0
[b]$ gpart show /dev/da0[/b]
gpart: No such geom: /dev/da0.
[b]$ sudo ntfs-3g /dev/da0 /mnt/tmp/
$ ll /mnt/tmp/[/b]
drwxrwxrwx  1 root  wheel   4.0K Mar 25 19:55 .
drwxr-xr-x  9 root  wheel     9B Jan 15 08:39 ..
-rwxrwxrwx  1 root  wheel    17K Mar 25 19:55 1.txt
-rwxrwxrwx  1 root  wheel   1.8K Mar 25 19:55 apple.txt
-rwxrwxrwx  1 root  wheel   524B Mar 25 19:55 billers.txt
-rwxrwxrwx  1 root  wheel    97K Mar 25 19:55 errors.txt
-rwxrwxrwx  1 root  wheel   847B Mar 25 19:55 pkg.txt
-rwxrwxrwx  1 root  wheel   1.4K Mar 25 19:55 test.txt
-rwxrwxrwx  1 root  wheel   7.8K Mar 25 19:55 timers.txt
```
As you can see, it `ntfs-3g` perfectly works although `gpart` (reasonably) does not recognize it.


----------



## aragats (Mar 26, 2017)

balanga , you can simply check what filesystem you actually have:
	
	



```
$ head -c 10 /dev/da1
```
If it's NTFS, you'll get: xx*NTFS*xx, if its exFAT, then correspondingly xx*EXFAT*xx.


----------



## balanga (Mar 27, 2017)

`dmesg tail`

```
info: [drm] Initialized i915 1.6.0 20080730 for drmn0 on minor 0
info: [drm] Enabling RC6 states: RC6 on, RC6p off, RC6pp off
ugen2.3: <Innostor> at usbus2
umass1: <Innostor PenDrive, class 0/0, rev 2.10/0.01, addr 3> on usbus2
umass1:  SCSI over Bulk-Only; quirks = 0x8100
umass1:7:1: Attached to scbus7
da1 at umass-sim1 bus 1 scbus7 target 0 lun 0
da1: <Innostor Innostor 1.00> Removable Direct Access SPC-4 SCSI device
da1: Serial Number 000000000000000668
da1: 40.000MB/s transfers
da1: 121896MB (249644974 512 byte sectors)
da1: quirks=0x12<NO_6_BYTE,NO_RC16>
root@FreeBSD:~ # dmesg | tail
ugen2.3: <Innostor> at usbus2
umass1: <Innostor PenDrive, class 0/0, rev 2.10/0.01, addr 3> on usbus2
umass1:  SCSI over Bulk-Only; quirks = 0x8100
umass1:7:1: Attached to scbus7
da1 at umass-sim1 bus 1 scbus7 target 0 lun 0
da1: <Innostor Innostor 1.00> Removable Direct Access SPC-4 SCSI device
da1: Serial Number 000000000000000668
da1: 40.000MB/s transfers
da1: 121896MB (249644974 512 byte sectors)
da1: quirks=0x12<NO_6_BYTE,NO_RC16>
```
`camcontrol devlist`

```
root@FreeBSD:~ # camcontrol devlist
<M4-CT256M4SSD3 07MH>              at scbus1 target 0 lun 0 (ada0,pass0)
<AHCI SGPIO Enclosure 1.00 0001>   at scbus3 target 0 lun 0 (ses0,pass1)
<ST910082 8AS 0100>                at scbus6 target 0 lun 0 (da0,pass2)
<Innostor Innostor 1.00>           at scbus7 target 0 lun 0 (da1,pass3)
```
`ll /dev/da0*`

```
root@FreeBSD:~ # ll /dev/da1*
crw-r-----  1 root  operator  0xa8 Mar 27 15:05 /dev/da1
```
`gpart show da1`

```
root@FreeBSD:~ # gpart show da1
gpart: No such geom: da1.
```
`ntfs-3g /dev/da1 /mnt/ntfs/`

```
NTFS signature is missing.
Failed to mount '/dev/da1': Invalid argument
The device '/dev/da1' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?
```
`ll /mnt/ntfs`

```
root@FreeBSD:~ # ll /mnt/ntfs
total 0
```
`head -c 10 /dev/da1`

```
root@FreeBSD:~ # head -c 10 /dev/da1
AKEO�1����
```


----------



## balanga (Mar 27, 2017)

`dir e:`

```
Volume in drive E is GRTMPVOL_EN
 Volume Serial Number is E652-0E33

 Directory of E:\

20/02/2016  08:14    <DIR>          $OEM$
23/02/2016  09:14        11,663,064 7ira09ww.exe
21/08/2015  12:31        10,077,032 7kra26ww.exe
04/03/2016  03:14                 0 AUTOEXEC.BAT
20/02/2016  08:14               110 AUTORUN.INF
20/02/2016  08:19           260,288 BOOTMGR
04/03/2016  03:14                 0 CONFIG.SYS
27/03/2017  15:29                 0 dirlist
20/02/2016  08:14    <DIR>          DOCS
20/02/2016  08:14    <DIR>          DOTNETFX
19/04/2002  17:20               299 fc.bat
20/04/2002  02:20             2,397 fcw.cnt
31/12/2004  17:25           313,344 fcw.exe
19/04/2002  17:20            25,218 fcw.fch
20/04/2002  02:20           173,755 fcw.hlp
05/03/2016  09:38            12,825 fcw.hst
19/04/2002  17:20             1,078 fcw.ico
01/12/2007  15:43             2,805 fcw.ini
20/02/2016  08:19    <DIR>          I386
20/02/2016  08:17            47,564 ntdetect.com
20/02/2016  08:19    <DIR>          OEM
20/02/2016  08:19            34,652 README.HTM
20/02/2016  08:19         1,314,816 SETUP.EXE
20/02/2016  08:19            85,792 SETUPXP.HTM
20/02/2016  08:19    <DIR>          SUPPORT
20/02/2016  08:19           551,316 txtsetup.sif
20/02/2016  08:19    <DIR>          VALUEADD
20/02/2016  08:19                10 WIN51
20/02/2016  08:19                10 WIN51IP
20/02/2016  08:19                10 WIN51IP.SP3
              23 File(s)     24,566,385 bytes
               7 Dir(s)  127,031,459,840 bytes free
```

It is NTFS although I don't know how to display that form the command line...


----------



## SirDice (Mar 27, 2017)

It's probably a dynamic volume.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa363785(v=vs.85).aspx#dynamic_disks


----------



## aragats (Mar 27, 2017)

balanga , would you report the output of `head -c [b]100[/b] /dev/da1`?
I suspect it's FAT32, since AKEO could be a program name used to create bootable USB drive. You probably will see FAT32 further in the boot record.


----------



## balanga (Mar 27, 2017)

`head -c 200 /dev/da1`

```
AKEO�1�����|���������H���-������Ph0|���f1���A����rm��}�&�?|    u�����X��}�����Z}�n}����u=��$u8�>�}
                                 ��}����}�>�}u�����}�h��r}�~}�eZ�|�m�x��}�R���Of��s��`
```


----------



## aragats (Mar 27, 2017)

Since there is no FAT32 signature, I think SirDice is right, it's a dynamic volume.


----------



## balanga (Mar 27, 2017)

`chkdsk e:`


```
The type of the file system is NTFS.
Volume label is GRTMPVOL_EN.

CHKDSK is verifying files (stage 1 of 3)...
 0 percent complete. (0 of 7936 file records processed)    
 1 percent complete. (794 of 7936 file records processed)    
 2 percent complete. (1588 of 7936 file records processed)    
 3 percent complete. (2381 of 7936 file records processed)    
 4 percent complete. (3175 of 7936 file records processed)    
 5 percent complete. (3968 of 7936 file records processed)    
 6 percent complete. (4762 of 7936 file records processed)    
 7 percent complete. (5556 of 7936 file records processed)    
 8 percent complete. (6349 of 7936 file records processed)    
 9 percent complete. (7143 of 7936 file records processed)    
  7936 file records processed.                                        

Windows has checked the file system and found no problems.

 124821462 KB total disk space.
    683624 KB in 7692 files.
      1888 KB in 201 indexes.
         0 KB in bad sectors.
     77694 KB in use by the system.
     65536 KB occupied by the log file.
 124058256 KB available on disk.

      4096 bytes in each allocation unit.
  31205365 total allocation units on disk.
  31014564 allocation units available on disk.
```

This is a USB stick. It's an installation/recovery disk for Windows XP, probably created from an ISO file.


----------



## aragats (Mar 27, 2017)

Yes, it may be NTFS or whatever, but the filesystem on a dynamic volume, you'll need to let the OS know how to deal with it.
I don't have experience with dynamic volumes though.
It could be useful to have the output of:
	
	



```
# hexdump -n 2048 -C /dev/da1
```


----------



## balanga (Mar 27, 2017)

http://paste2.org/BaPVv1Xk


----------



## aragats (Mar 27, 2017)

It looks that the flash drive was created by Rufus https://rufus.akeo.ie/ (do you see _*akeo*_ in the domain name?).
That guy uses his own customized MBR, here he describes it.
As per your, balanga , `hexdump` output, the partition table's first entry has 0xFF type (assuming that's a regular MBR with a partition table starting from 0x1BE (446)).

[EDIT] I was wrong, see below.


----------



## aragats (Mar 27, 2017)

I was wrong, it does show the NTFS partiton type 0x07 (looked at a wrong address):
	
	



```
000001b0 20 55 53 42 2e 00 00 00 23 7b 6a 54 00 00 81 20 | USB....#{jT... |
000001c0 21 00 [b]07[/b] fe ff ff 00 08 00 00 ae 3f e1 0e 00 00 |!..........?....|
```
That means your NTFS partition is located at the address encoded by 0x202100 CHS address:
H=32, S=33, C=0.


----------



## aragats (Mar 28, 2017)

OK, everything is clear now.
As per the partition table data:
	
	



```
000001c0 21 00 07 fe ff ff [b]00 08 00 00 ae 3f e1 0e[/b] 00 00
```
The start sector is 0x00000800=2048 and the number of sectors in the partition is 0x0EE13fAE=249642926, which gives 249642926 x 512 = 127817178112 ≈ 128GB (correct!).
Thus it's a regular NTFS partition starting from sector 2048. It is not recognized since the MBR is not standard. I don't know how to mount such a partition (using offset?). At the moment the only way I envision is to backup the original MBR and write a standard MBR to that flash drive, mount the NTFS partition, do whatever you want, then umount it and restore the original MBR:
	
	



```
# dd if=/dev/da1 of=org.mbr bs=446 count=1
# dd of=/dev/da1 if=standard.mbr bs=446 count=1
```
Most probably somebody will come up with a smarter idea how to deal with it.


----------



## balanga (Mar 28, 2017)

I wish I knew the geography of hard disk that well.... 

I'll give this a try after I copy the USB stick using `dd`. Where should I look for 
standard.mbr
?


----------



## balanga (Mar 28, 2017)

Will /boot/mbr be OK?


----------



## balanga (Mar 28, 2017)

aragats said:


> ```
> # dd if=/dev/da1 of=org.mbr bs=446 count=1
> # dd of=/dev/da1 if=standard.mbr bs=446 count=1
> ```




I get 
	
	



```
dd: /dev/da1: Invalid argument
```

When I first tried it on another system, it completely hung and I had to do a hard reset.


----------



## aragats (Mar 28, 2017)

balanga said:


> dd: /dev/da1: Invalid argument


That's very strange!
Regarding the MBR: I got another idea, I can provide an MBR from a bootable USB flash with Windows 7 installer, but created by a Microsoft tool. Thus yours may remain botable and become visible to FreeBSD. But if you cannot `dd`...


----------



## aragats (Mar 28, 2017)

balanga said:


> dd: /dev/da1: Invalid argument


OK, `dd` doesn't like bs=446, since the actual block size of the device is 512 (however, that's not a problem in Linux).

I've compared your MBR with one from the MS Windows 7 installer, the only difference is the following 4 bytes:
	
	



```
000001B0   20 55 53 42  2E 00 00 00  [b]FF 04 35 00[/b]   // your flash drive
000001B0   20 55 53 42  2E 00 00 00  [b]23 7B 6A 54[/b]   // MS installer
```
You can do the following:
	
	



```
# dd if=/dev/da1 of=org.mbr bs=512 count=1
$ cp org.mbr org.mbr.backup
$ hexedit mbr.org     # change those 4 bytes
# dd of=/dev/da1 if=org.mbr bs=512 count=1
```
and re-insert your flash drive.
You'll need editors/hexedit or any hex editor to replace those 4 bytes.

By the way, even with the current MBR file(1) shows the correct info, you can try:
	
	



```
$ file -s /dev/da1
/dev/da1: DOS/MBR boot sector; partition 1 : ID=0x7, active 0x81, start-CHS (0x0,32,33), end-CHS (0x3ff,254,63), startsector 2048, 249642926 sectors
```


----------



## balanga (Nov 27, 2017)

aragats said:


> OK, `dd` doesn't like bs=446, since the actual block size of the device is 512 (however, that's not a problem in Linux).
> 
> I've compared your MBR with one from the MS Windows 7 installer, the only difference is the following 4 bytes:
> 
> ...



Apologies for not getting back. I went on vacation before being able to try your suggestion


----------



## balanga (Nov 27, 2017)

I've just found the source from which I created my 128GB Windows XP SP3 USB  stick... I did a search for the label which was written when the stick was created using Rufus the label being *GRTMPVOL_EN* which led me here. Now I've been able to recreate the disks contents on a 1GB disk enabling me to free up the 128GB disk.

I still get the same response from `gpart show` ie. no sign of da0, but it does show up under `camcontrol devlist` as well as `dmesg`.

`file -s /dev/da1` shows:-

```
/dev/da1: DOS/MBR boot sector; partition 1 : ID=0x7, active 0x81, start-CHS (0x0,32,33), end-CHS (0x7e,254,63), startsector 2048, 2044928 sectors
```

The MBR retrieved using `dd` is slightly different, but I'll change the four bytes you mentioned and see what happens... Should I then expect the drive to show up under `part show`?


----------

