0

Using CentOS 8.5

I tried this on a new disk with no data or partition tables.

GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-4194270, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-4194270, default = 4194270) or {+-}size{KMGTP}: +500M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/nvme0n7.
The operation has completed successfully.
[root@workstation ~]# 
[root@workstation ~]# lsblk -fp
NAME                    FSTYPE      LABEL UUID                                   MOUNTPOINT
/dev/sr0                                                                         
/dev/nvme0n1                                                                     
├─/dev/nvme0n1p1        xfs               c932c155-e3a9-4852-aad1-d545778b46c6   /boot
└─/dev/nvme0n1p2        LVM2_member       KwN1Pf-Jf3R-l7HW-Qed3-DLSl-olMr-rVdD3n 
  ├─/dev/mapper/cl-root xfs               e6d63656-cd58-40a8-aadf-b0416e36c8d4   /
  ├─/dev/mapper/cl-swap swap              3b26e208-9846-4c20-8b90-60bb0ce68869   [SWAP]
  └─/dev/mapper/cl-home xfs               7cb2b8a0-fe6b-4c6c-9d8f-124780be79c9   /home
/dev/nvme0n2                                                                     
/dev/nvme0n3                                                                     
/dev/nvme0n4                                                                     
/dev/nvme0n5                                                                     
/dev/nvme0n6                                                                     
/dev/nvme0n7                                                                     
└─/dev/nvme0n7p1        xfs               25552944-4b61-44d6-a1bd-ca0ae3cfc89f   
/dev/nvme0n8                                                                     
/dev/nvme0n9                                                                     
[root@workstation ~]# 

As you can see, the partition already has xfs filesystem created on it. I thought I have to use mkfs.xfs after using fdisk or gdisk.

Cruise5
  • 456
  • 3
  • 17

1 Answers1

1

No, gdisk doesn't format newly created partitions to XFS so there are two options:

  • The disk wasn't empty. If there was a partition table and a partition with XFS previously that wasn't wiped before removing and the newly created partition starts on the same sector the old one started, you'll see the filesystem on the newly created partition.
  • lsblk uses cached data from udev and udev can be wrong sometimes, you can use blkid -p /dev/nvme0n7p1 which actually reads the data from the partition to check for filesystem.

Btw. I recommend using fdisk which supports GPT too and shows a warning when a newly created partition already contains a filesystem signature and allows you to remove the signature:

Created a new partition 1 of type 'Linux filesystem' and of size 499 MiB.
Partition #1 contains a xfs signature.

Do you want to remove the signature? [Y]es/[N]o:

In general it is a good idea to use wipefs to remove filesystem signatures before removing the partitions with fdisk or parted.

Vojtech Trefny
  • 16,922
  • 6
  • 24
  • 48
  • You are right. I deleted the partition on the disk using `gdisk` and then used `z` option in expert mode to remove the partition tables. I thought deleting the partition would be enough to remove filesystem. If I use `fdisk`, how would I create a gpt partition and set LVM on ? – Cruise5 Jan 30 '22 at 15:04
  • Partitioning tools usually don't wipe the filesystem signatures, `fdisk` also doesn't do that when deleting the partition, you should use `wipefs`. You can create a GPT partition table with `g` with `fdisk`. Rest should be very similar to `gdisk` (`n` to create partition, `t` to set partition type etc.). – Vojtech Trefny Jan 30 '22 at 16:01
  • `wipefs` doesn't delete the filesystem nor the data. I want to erase data and everything from the partition. From man page: "wipefs can erase filesystem, raid or partition-table signatures (magic strings) from the specified device to make the signatures invisible for libblkid. wipefs does not erase the filesystem itself nor any other data from the device." – Cruise5 Jan 30 '22 at 21:57
  • Yes, `wipefs` removes only the signature. If you want to remove the data you should use something like `shred`, see [this answer](https://unix.stackexchange.com/questions/252593/how-can-i-securely-delete-the-contents-of-a-thumb-drive-so-data-cant-be-recover/252606#252606) for more details. (We are now very offtopic for this question, if you have further questions, you should ask a new one.) – Vojtech Trefny Jan 31 '22 at 06:09