# newfs creates ext2fs not ufs partition



## Dave Lister (May 29, 2020)

I have a USB drive that I want to use for testing linux distros and backing up data both for linux and FreeBSD.  It is divided like this:-


```
gpart show da0
=>       63  240353217  da0  MBR  (115G)
         63       1985       - free -  (993K)
       2048   16384000    1  fat32  [active]  (7.8G)
   16386048   12288000    2  linux-swap  (5.9G)
   28674048  106954752    3  linux-data  (51G)
  135628800  104724480    4  linux-data  (50G)
```

The fat32 is for installing test linux distros and is flagged as boot, with the swap and 51G linux data to use with that.
Partition 4 ( 50G) I want to use with FreeBSD.  

I tried :-

```
newfs -U /dev/da0s4
```

which seemed to work but then when I checked with:-

```
fstyp /dev/da0s4
```

it tells me that it is ext2fs and also, I cannot mount /dev/ext2fs/FreebsdData from PLACES in the Desktop GUI.
However, I was able mount it as superuser and write a test.txt file to it, also there was a .snap directory created on it.

I have also tried deleting the partition then trying to create a new one with:-

```
gpart add -t freebsd-ufs da0
```
but a parameter was incorrect, presumably the "freebsd-ufs" bit so I also tried:-

```
gpart add -t freebsd da0
```
which seemed to work but I still couldn't mount the partition.

It's a but frustrating, as I think I have followed the Handbook correctly but can't see where I am going wrong. Is it simply a case that you can't mix linux and unix filesystems on a single device?


----------



## bjs (May 29, 2020)

After you made the partition, did you format it before trying to mount it????


----------



## eldaemon (May 29, 2020)

I am guessing `fstyp` is broken and it's actually UFS. Can you confirm the filesystem is indeed UFS or EXT2?


----------



## George (May 29, 2020)

"gpart add -t freebsd" is not the same as "gpart add -t freebsd-ufs". See gpart()
If you want a ufs2 file system, I would suggest using partition type "freebsd-ufs". Once you have that, add a file system to it with newfs.

Can you show your current output of `gpart show da0`?


----------



## Dave Lister (May 29, 2020)

Elazar said:


> "gpart add -t freebsd" is not the same as "gpart add -t freebsd-ufs". See gpart()
> If you want a ufs2 file system, I would suggest using partition type "freebsd-ufs". Once you have that, add a file system to it with newfs.
> 
> Can you show your current output of `gpart show da0`?



Output is the same 

```
=>       63  240353217  da0  MBR  (115G)
         63       1985       - free -  (993K)
       2048   16384000    1  fat32  [active]  (7.8G)
   16386048   12288000    2  linux-swap  (5.9G)
   28674048  106954752    3  linux-data  (51G)
  135628800  104724480    4  linux-data  (50G)
```


----------



## Dave Lister (May 29, 2020)

Another attempt. /dev/da0s4 is present and /mnt is completely empty. Here is the current gpart status, I will delete partition 4 then add it again.


```
# gpart show da0
=>       63  240353217  da0  MBR  (115G)
         63       1985       - free -  (993K)
       2048   16384000    1  fat32  [active]  (7.8G)
   16386048   12288000    2  linux-swap  (5.9G)
   28674048  106954752    3  linux-data  (51G)
  135628800  104724480    4  linux-data  (50G)
```

Delete partition 4

```
# gpart delete -i 4 da0
da0s4 deleted
```

show the result

```
# gpart show da0
=>       63  240353217  da0  MBR  (115G)
         63       1985       - free -  (993K)
       2048   16384000    1  fat32  [active]  (7.8G)
   16386048   12288000    2  linux-swap  (5.9G)
   28674048  106954752    3  linux-data  (51G)
  135628800  104724480       - free -  (50G)
```

add new ufs partition

```
# gpart add -t freebsd-ufs da0
gpart: Invalid argument
```

This is the result as I got before. I know what the handbook says, but if I use:-

```
# gpart -t freebsd da0
da0s4 added
```

Then gpart show

```
# gpart show da0
=>       63  240353217  da0  MBR  (115G)
         63       1985       - free -  (993K)
       2048   16384000    1  fat32  [active]  (7.8G)
   16386048   12288000    2  linux-swap  (5.9G)
   28674048  106954752    3  linux-data  (51G)
  135628800  104724480    4  freebsd  (50G)
```

it may not be correct but it is better than the last one. Howver if I use fstyp to check the format.

```
# fstype /dev/da0s4
ext2fs
```

So try to reformat to UFS2:-

```
newfs -O 2 da0s4
```

It formats. So check with gpart show.

```
# gpart show da0
=>       63  240353217  da0  MBR  (115G)
         63       1985       - free -  (993K)
       2048   16384000    1  fat32  [active]  (7.8G)
   16386048   12288000    2  linux-swap  (5.9G)
   28674048  106954752    3  linux-data  (51G)
  135628800  104724480    4  freebsd  (50G)
```
still good, but fstype still shows it as ext2fs. So, try to mount it:-

```
# mkdir /mnt/da0s4
# chown 1001:1001 /mnt/da0s4
# mount -t ufs /dev/da0s4 /mnt/da0s4
```

so far no errors, but I can't see the partition with Caja the desktop file manager. but as root I can copy a text file into /mnt/da0s4 and there is a .snap directory that has been created there also.  As the user I can go into /mnt/da0s4 via a terminal and open the text file but it is read only. I'm at a bit of a loss at this point.

EDIT: After reboot, the FreebsdData partition (da0s4) appears under PLACES on the Desktop, but when I try to open it Caja reports:-

```
Unable to mount the volume 'FreebsdData'
Details
mount: /dev/ext2fs/Freebsd:
Operation not supported by device.
```


----------



## memreflect (May 30, 2020)

Dave Lister said:


> I have a USB drive that I want to use for testing linux distros and backing up data both for linux and FreeBSD.  It is divided like this:-
> 
> 
> ```
> ...


Your partition scheme is MBR, not GPT or BSD, so that's going to make things a little more complicated.  To get a single UFS partition, you need to first create a new slice of type *freebsd*.  You already did this using

```
# gpart add -t freebsd da0
da0s4 added
```
You can print the names of the slices rather than the indices using

```
# gpart show -p da0
=>       63  240353217      da0  MBR  (115G)
         63       1985           - free -  (993K)
       2048   16384000    da0s1  fat32  [active]  (7.8G)
   16386048   12288000    da0s2  linux-swap  (5.9G)
   28674048  106954752    da0s3  linux-data  (51G)
  135628800  104724480    da0s4  freebsd  (50G)
```
The *freebsd* slice type is treated sort of like a separate disk, so you need to additionally execute

```
# gpart create -s BSD da0s4
da0s4 created
```
as if it was a disk containing no partition table.  That will create a new BSD disklabel (another type of partition scheme like MBR and GPT), and you can then add your UFS partition:

```
# gpart add -t freebsd-ufs da0s4
da0s4a added
# gpart show -p da0s4
=>       0  104724480   da0s4  BSD  (50G)
         0  104724480  da0s4a  freebsd-ufs  (50G)
```

After that, you can use newfs(8) to format your UFS partition.

You should also notice that the offset column is 0.  Like I said, *freebsd* slice types are treated a lot like separate disks, so the offset of the *freebsd* slice does not apply to its contents, but its size does.  While they're not entirely like real disks, it can be helpful to think of them like that, so you know which commands to use (e.g. create/destroy vs. add/delete; backup/restore works as well).  It also means that whenever you have a BSD disklabel, you won't see its contents unless you explicitly request them; they're entirely separate from the main partition table on the real disk.

If you mess up creating a partition/slice, you can use `gpart delete -i $index $disk` to remove it (remember `gpart show` prints indices by default if you need help determining what the index is for a specific partition).  If you want to erase an empty partition table, use `gpart destroy $disk`.  If the partition table is not empty, you will be required to use `gpart destroy -F $disk`, or you can just delete each of the partitions individually and then use `gpart destroy $disk`.

If you're worried about your data, you should investigate "memory disks".  Essentially you can use truncate(1) to create a file of whatever size you want, and that can act as the disk image.  Then you'd use mdconfig(8) to create a "memory disk" using that disk image.  You can then operate on the memory disk as if it was a real disk.


----------



## Dave Lister (May 30, 2020)

memreflect said:


> Your partition scheme is MBR, not GPT or BSD, so that's going to make things a little more complicated.  To get a single UFS partition, you need to first create a new slice of type *freebsd*.  You already did this using
> 
> ```
> # gpart add -t freebsd da0
> ...



That was great, thanks, it was very informative and worked a charm.  I needed to use chown to assign user & group permissions and reboot, but now the BSD partition appears on the desktop after boot up, opens when clicked and the user can read & write files to it.  Within the filesystem it appears as /media/disk rather than /mnt/da0s4 as I thought it would.  I deleted /mnt/da0s4 and that seemingly had no deleterious effects on the new drive. Thanks again, I appreciate the time taken to write such detailed instructions.


----------

