I am trying to encrypt with LUKS and format the storage device with BTRFS format on Fedora Linux 39. I referred to Fedora’s document[1], and my past article blog article about encrypting and encrypting with LUKS and formatting 1 TB HDD with BTRFS[2].
Then I got an error. Let me explain it.
As an initial state, the SSD was detected as /dev/sda1 with the label by the lsblk command.
$ lsblk -r -p -o NAME,TYPE,FSTYPE,UUID,SIZE,LABEL
...
/dev/sda disk 1.8T
/dev/sda1 part exfat BAB8-C8F1 1.8T My\x20Passport
...
Following the [1], as preparation before formatting the SSD, I filled random data into the storage device.
$ sudo dmsetup info luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
Name: luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
State: ACTIVE
Read Ahead: 4096
Tables present: LIVE
Open count: 0
Event number: 0
Major, minor: 253, 1
Number of targets: 1
UUID: CRYPT-LUKS2-c522db23e7514fa6a9a6a45dc06878fc-luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
Then I got the following error when trying to format the storage with BTRFS.
$ sudo mkfs.btrfs -L my-passport-ssd-2tb /dev/mapper/luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
btrfs-progs v6.7.1
See https://btrfs.readthedocs.io for more information.
NOTE: several default settings have changed in version 5.15, please make sure
this does not affect your deployments:
- DUP for metadata (-m dup)
- enabled no-holes (-O no-holes)
- enabled free-space-tree (-R free-space-tree)
ERROR: error during mkfs: Operation not permitted
Now I noticed the /dev/sda and /dev/sda1 lines disappeared in the output of the following lsblk command.
$ lsblk -r -p -o NAME,TYPE,FSTYPE,UUID,SIZE,LABEL
Do you have any ideas about how to fix the error by the above mkfs.btrfs command?
I rebooted the OS. The /dev/sda and /dev/sda1 appeared again by the lsblk command.
$ lsblk -r -p -o NAME,TYPE,FSTYPE,UUID,SIZE,LABEL
NAME TYPE FSTYPE UUID SIZE LABEL
/dev/sda disk 1.8T
/dev/sda1 part crypto_LUKS c522db23-e751-4fa6-a9a6-a45dc06878fc 1.8T
/dev/zram0 disk 8G
/dev/nvme0n1 disk 1.8T
/dev/nvme0n1p1 part vfat D0B0-4455 600M
/dev/nvme0n1p2 part ext4 1072bb16-2ca1-4502-8bda-750ad467f25f 1G
/dev/nvme0n1p3 part crypto_LUKS 09538e5a-f802-40a6-bc22-328604dc2312 1.8T
/dev/mapper/luks-09538e5a-f802-40a6-bc22-328604dc2312 crypt btrfs be430ab5-ebda-4f4f-a01e-427d18fb12f1 1.8T fedora_localhost-live
$ sudo cryptsetup luksOpen /dev/sda1 luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
Enter passphrase for /dev/sda1:
The lsblk still showed the /dev/sda and /dev/sda1.
$ lsblk -r -p -o NAME,TYPE,FSTYPE,UUID,SIZE,LABEL
NAME TYPE FSTYPE UUID SIZE LABEL
/dev/sda disk 1.8T
/dev/sda1 part crypto_LUKS c522db23-e751-4fa6-a9a6-a45dc06878fc 1.8T
/dev/mapper/luks-c522db23-e751-4fa6-a9a6-a45dc06878fc crypt 1.8T
/dev/zram0 disk 8G
/dev/nvme0n1 disk 1.8T
/dev/nvme0n1p1 part vfat D0B0-4455 600M
/dev/nvme0n1p2 part ext4 1072bb16-2ca1-4502-8bda-750ad467f25f 1G
/dev/nvme0n1p3 part crypto_LUKS 09538e5a-f802-40a6-bc22-328604dc2312 1.8T
/dev/mapper/luks-09538e5a-f802-40a6-bc22-328604dc2312 crypt btrfs be430ab5-ebda-4f4f-a01e-427d18fb12f1 1.8T fedora_localhost-live
Another error “ERROR: superblock magic doesn’t match” was printed with the “ERROR: error during mkfs: Operation not permitted”.
$ ls -l /dev/mapper/luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
lrwxrwxrwx. 1 root root 7 Sep 27 23:25 /dev/mapper/luks-c522db23-e751-4fa6-a9a6-a45dc06878fc -> ../dm-1
$ sudo mkfs.btrfs -L my-passport-ssd-2tb /dev/mapper/luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
btrfs-progs v6.7.1
See https://btrfs.readthedocs.io for more information.
ERROR: superblock magic doesn't match
NOTE: several default settings have changed in version 5.15, please make sure
this does not affect your deployments:
- DUP for metadata (-m dup)
- enabled no-holes (-O no-holes)
- enabled free-space-tree (-R free-space-tree)
ERROR: error during mkfs: Operation not permitted
The /dev/sda and /dev/sda1 disappeared.
$ lsblk -r -p -o NAME,TYPE,FSTYPE,UUID,SIZE,LABEL
NAME TYPE FSTYPE UUID SIZE LABEL
/dev/zram0 disk 8G
/dev/nvme0n1 disk 1.8T
/dev/nvme0n1p1 part vfat D0B0-4455 600M
/dev/nvme0n1p2 part ext4 1072bb16-2ca1-4502-8bda-750ad467f25f 1G
/dev/nvme0n1p3 part crypto_LUKS 09538e5a-f802-40a6-bc22-328604dc2312 1.8T
/dev/mapper/luks-09538e5a-f802-40a6-bc22-328604dc2312 crypt btrfs be430ab5-ebda-4f4f-a01e-427d18fb12f1 1.8T fedora_localhost-live
btrfs-progs 6.7.1 is kinda old, current Fedora 39 btrfs-progs is 6.11. Maybe there’s a bug that’s been fixed since the older version? I suggest dnf update or at least make sure kernel, btrfs-progs, and cryptsetup are all up to date.
If you still get the error, looks to me like the drive is vanishing off the USB bus for some reason. Please run this command:
Still another idea is to use mkfs.btrfs -vvv --nodiscard and see if that works? And if not the multiple v’s will add some verbose messages, hopefully providing a hint why it fails.
Then I got the same error with the previous one below.
$ lsblk -r -p -o NAME,TYPE,FSTYPE,UUID,SIZE,LABEL
NAME TYPE FSTYPE UUID SIZE LABEL
/dev/sda disk 1.8T
/dev/sda1 part crypto_LUKS c522db23-e751-4fa6-a9a6-a45dc06878fc 1.8T
/dev/zram0 disk 8G
/dev/nvme0n1 disk 1.8T
/dev/nvme0n1p1 part vfat D0B0-4455 600M
/dev/nvme0n1p2 part ext4 1072bb16-2ca1-4502-8bda-750ad467f25f 1G
/dev/nvme0n1p3 part crypto_LUKS 09538e5a-f802-40a6-bc22-328604dc2312 1.8T
/dev/mapper/luks-09538e5a-f802-40a6-bc22-328604dc2312 crypt btrfs be430ab5-ebda-4f4f-a01e-427d18fb12f1 1.8T fedora_localhost-live
$ sudo cryptsetup luksUUID /dev/sda1
c522db23-e751-4fa6-a9a6-a45dc06878fc
$ sudo cryptsetup luksOpen /dev/sda1 luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
Enter passphrase for /dev/sda1:
$ sudo dmsetup info luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
Name: luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
State: ACTIVE
Read Ahead: 4096
Tables present: LIVE
Open count: 0
Event number: 0
Major, minor: 253, 1
Number of targets: 1
UUID: CRYPT-LUKS2-c522db23e7514fa6a9a6a45dc06878fc-luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
$ sudo mkfs.btrfs -L my-passport-ssd-2tb /dev/mapper/luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
btrfs-progs v6.10.1
See https://btrfs.readthedocs.io for more information.
ERROR: superblock magic doesn't match
Performing full device TRIM /dev/mapper/luks-c522db23-e751-4fa6-a9a6-a45dc06878fc (1.82TiB) ...
NOTE: several default settings have changed in version 5.15, please make sure
this does not affect your deployments:
- DUP for metadata (-m dup)
- enabled no-holes (-O no-holes)
- enabled free-space-tree (-R free-space-tree)
ERROR: error during mkfs: Operation not permitted
First, I rebooted the OS to show the /dev/sda and /dev/sda1 in the result of the lsblk, and ran the cryptsetup luksOpen.
$ lsblk -r -p -o NAME,TYPE,FSTYPE,UUID,SIZE,LABEL
NAME TYPE FSTYPE UUID SIZE LABEL
/dev/sda disk 1.8T
/dev/sda1 part crypto_LUKS c522db23-e751-4fa6-a9a6-a45dc06878fc 1.8T
/dev/zram0 disk 8G
/dev/nvme0n1 disk 1.8T
/dev/nvme0n1p1 part vfat D0B0-4455 600M
/dev/nvme0n1p2 part ext4 1072bb16-2ca1-4502-8bda-750ad467f25f 1G
/dev/nvme0n1p3 part crypto_LUKS 09538e5a-f802-40a6-bc22-328604dc2312 1.8T
/dev/mapper/luks-09538e5a-f802-40a6-bc22-328604dc2312 crypt btrfs be430ab5-ebda-4f4f-a01e-427d18fb12f1 1.8T fedora_localhost-live
$ sudo cryptsetup luksOpen /dev/sda1 luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
Enter passphrase for /dev/sda1:
Then I got the following error “checksum verify failed”.
$ sudo mkfs.btrfs -L my-passport-ssd-2tb -vvv --nodiscard /dev/mapper/luks-c522db23-e751-4fa6-a9a6-a45dc06878fc
btrfs-progs v6.10.1
See https://btrfs.readthedocs.io for more information.
NOTE: several default settings have changed in version 5.15, please make sure
this does not affect your deployments:
- DUP for metadata (-m dup)
- enabled no-holes (-O no-holes)
- enabled free-space-tree (-R free-space-tree)
checksum verify failed on 1081344 wanted 0xf6e2b79f found 0xefa6c526
ERROR: cannot read chunk root
ERROR: open ctree failed
$ echo $?
1
[16041.271039] kernel: scsi host0: uas_eh_device_reset_handler FAILED err -19
[16041.271049] kernel: sd 0:0:0:0: Device offlined - not ready after error recovery
This gist of all that is the device it confused and stops responding. That’s why it works after a reboot, or if you just unplug the device from USB and then plug it back in.
What’s the solution? Well, I’m not sure if this is a uas incompatibility problem, or a bus power problem. You might have to try both.
I use an externally powered hub for my USB drives in enclosures and it solved all problems. But it’s possible in your case that won’t work, so I suggest borrowing a powered USB hub to see if it fixes the problem or not before you buy one.
Another possibility is disabling UAS. It’s possible to disable it entirely for all devices, or set a quirk for the specific drive you’re working with, and then uas is only disabled for that device.
After seeing your comment, just in case, I ran the commands again to create LUKS format for the SSD from the badblocks command again, and I also tried running the mkfs.btrfs command on another Laptop. But the result was the same, showing the same error.
My original report was on my Framework Laptop 13 Intel 11 Gen. Now I tried the mkfs.btrfs command on my other laptop Lenovo X1 Carbon. In both laptops, Fedora Linux 39 and the btrfs-progs-6.10.1-1.fc39.x86_64 are installed.
I will try what you told me. I will borrow or buy a powered USB hub. For “a possible uas incompatibility problem”, did you mean it was an incompatibility of the USB interface device or the SSD storage device?
Do you think trying with a powered USB hub may solve both “a uas incompatibility problem, and a bus power problem”?
I noticed that the btrfs-progs’s new version 6.11 RPM was released on Fedora 39,[1][2]. So, install and tried it. However, the mkfs.btrfs command failed with the same error.
I’m not a USB expert, but a feature of USB hubs is they “normalize” the command and data streams between host and device. I can’t tell from the errors if these are UAS errors or insufficient power supply errors.
It’s probably easier to figure out how to disable the UAS driver (just blacklist the driver) than borrow a USB hub. But try one, if that doesn’t work then try the other.
As a suggestion, you could use the entire disk instead of a partition: /dev/sda instead of /dev/sda1. It should not matter here, but as the current setup is not working for you and that’s what I usually do, it might be worth a try. Note that this will erase all the other partitions on the disk.
I bought a USB hub + universal power adapter at a local electrical shop. I tried to use these ones now. However, I feel a smell of smoke from the hole in the USB hub. Perhaps, the combination between the USB hub and universal power adapter was bad. So, I may go to the electrical shop to ask again.
Then I tried to format the disk with BTRFS. Once I tried to format with exfat, and failed. I need to run the mkfs.btrfs -f option. Then I got the following error.
$ sudo cryptsetup luksUUID /dev/sda1
35b57833-b9f7-4f09-871a-483453831949
$ sudo cryptsetup luksOpen /dev/sda1 luks-35b57833-b9f7-4f09-871a-483453831949
Enter passphrase for /dev/sda1:
$ sudo mkfs.btrfs -L my-passport-ssd-2tb /dev/mapper/luks-35b57833-b9f7-4f09-871a-483453831949
btrfs-progs v6.11
See https://btrfs.readthedocs.io for more information.
ERROR: /dev/mapper/luks-35b57833-b9f7-4f09-871a-483453831949 appears to contain an existing filesystem (exfat)
ERROR: use the -f option to force overwrite of /dev/mapper/luks-35b57833-b9f7-4f09-871a-483453831949
$ sudo mkfs.btrfs -f -L my-passport-ssd-2tb /dev/mapper/luks-35b57833-b9f7-4f09-871a-483453831949
btrfs-progs v6.11
See https://btrfs.readthedocs.io for more information.
Performing full device TRIM /dev/mapper/luks-35b57833-b9f7-4f09-871a-483453831949 (1.82TiB) ...
NOTE: several default settings have changed in version 5.15, please make sure
this does not affect your deployments:
- DUP for metadata (-m dup)
- enabled no-holes (-O no-holes)
- enabled free-space-tree (-R free-space-tree)
ERROR: error during mkfs: Operation not permitted
The sudo dmesg --follow-new outputted the following result during the mkfs.btrfs.
[ 923.007086] usb 2-1: reset SuperSpeed Plus Gen 2x1 USB device number 2 using xhci_hcd
[ 953.214751] usb 2-1: reset SuperSpeed Plus Gen 2x1 USB device number 2 using xhci_hcd
[ 988.923181] xhci_hcd 0000:00:0d.0: Timeout while waiting for setup device command
[ 994.555336] xhci_hcd 0000:00:0d.0: Timeout while waiting for setup device command
[ 994.763032] usb 2-1: device not accepting address 2, error -62
[ 1000.187277] xhci_hcd 0000:00:0d.0: Timeout while waiting for setup device command
[ 1005.819187] xhci_hcd 0000:00:0d.0: Timeout while waiting for setup device command
[ 1006.027146] usb 2-1: device not accepting address 2, error -62
[ 1011.451093] xhci_hcd 0000:00:0d.0: Timeout while waiting for setup device command
[ 1017.083272] xhci_hcd 0000:00:0d.0: Timeout while waiting for setup device command
[ 1017.291087] usb 2-1: device not accepting address 2, error -62
[ 1022.715035] xhci_hcd 0000:00:0d.0: Timeout while waiting for setup device command
[ 1028.347033] xhci_hcd 0000:00:0d.0: Timeout while waiting for setup device command
[ 1028.554893] usb 2-1: device not accepting address 2, error -62
[ 1028.571761] usb 2-1: USB disconnect, device number 2
[ 1028.571833] sd 0:0:0:0: Device offlined - not ready after error recovery
[ 1028.572026] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=105s
[ 1028.572031] sd 0:0:0:0: [sda] tag#0 CDB: Write(10) 2a 00 e8 df 7b 09 00 05 98 00
[ 1028.572034] I/O error, dev sda, sector 3906960137 op 0x1:(WRITE) flags 0x800 phys_seg 1432 prio class 2
[ 1028.572052] Buffer I/O error on dev dm-1, logical block 3906925321, lost async page write
[ 1028.572058] Buffer I/O error on dev dm-1, logical block 3906925322, lost async page write
[ 1028.572062] Buffer I/O error on dev dm-1, logical block 3906925323, lost async page write
[ 1028.572065] Buffer I/O error on dev dm-1, logical block 3906925324, lost async page write
[ 1028.572068] Buffer I/O error on dev dm-1, logical block 3906925325, lost async page write
[ 1028.572072] Buffer I/O error on dev dm-1, logical block 3906925326, lost async page write
[ 1028.572075] Buffer I/O error on dev dm-1, logical block 3906925327, lost async page write
[ 1028.572094] Buffer I/O error on dev dm-1, logical block 3906925328, lost async page write
[ 1028.572098] Buffer I/O error on dev dm-1, logical block 3906925329, lost async page write
[ 1028.572103] Buffer I/O error on dev dm-1, logical block 3906925330, lost async page write
After the above error, I ran the following commands. There was no entry about the SSD. And the usb_storage was loaded with “2 uas”. Not sure why it is “2 uas” rather than “1 uas”.
$ lsusb -tv
/: Bus 001.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/1p, 480M
ID 1d6b:0002 Linux Foundation 2.0 root hub
/: Bus 002.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M
ID 1d6b:0003 Linux Foundation 3.0 root hub
/: Bus 003.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/12p, 480M
ID 1d6b:0002 Linux Foundation 2.0 root hub
|__ Port 007: Dev 002, If 0, Class=Video, Driver=uvcvideo, 480M
ID 0bda:5634 Realtek Semiconductor Corp.
|__ Port 007: Dev 002, If 1, Class=Video, Driver=uvcvideo, 480M
ID 0bda:5634 Realtek Semiconductor Corp.
|__ Port 009: Dev 003, If 0, Class=Vendor Specific Class, Driver=[none], 12M
ID 27c6:609c Shenzhen Goodix Technology Co.,Ltd.
|__ Port 010: Dev 004, If 0, Class=Wireless, Driver=btusb, 12M
ID 8087:0032 Intel Corp. AX210 Bluetooth
|__ Port 010: Dev 004, If 1, Class=Wireless, Driver=btusb, 12M
ID 8087:0032 Intel Corp. AX210 Bluetooth
/: Bus 004.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M
ID 1d6b:0003 Linux Foundation 3.0 root hub