Welcome to the Linux Foundation Forum!

Write protected error when mounting a loop device with a GPT and single partition

I'm trying to mount a loop device that I've created with the following steps but receive an error telling me that the fs is of an unknown type. If I don't add a partition to the fs it will mount as expected.

$ sudo dd if=/dev/zero of=secOps bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 0.244399 s, 2.2 GB/s
$ sudo mkfs.ext4 secOps
mke2fs 1.42.9 (28-Dec-2013)
secOps is not a block special device.
Proceed anyway? (y,n) y
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768 inodes, 131072 blocks
6553 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=134217728
4 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
$ sudo gdisk secOps
GPT fdisk (gdisk) version 0.8.10

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

Creating new GPT entries.

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y

Command (? for help): n
Partition number (1-128, default 1):
First sector (34-1048542, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-1048542, default = 1048542) or {+-}size{KMGTP}: +256M
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): p
Disk secOps: 1048576 sectors, 512.0 MiB
Logical sector size: 512 bytes
Disk identifier (GUID): 941146DD-99DB-4A90-B400-8D7D1534AF21
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1048542
Partitions will be aligned on 2048-sector boundaries
Total free space is 524221 sectors (256.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          526335   256.0 MiB   8300  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 secOps.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
$ sudo losetup /dev/loop0 secOps
$ sudo lsblk
NAME      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda         8:0    0   20G  0 disk
├─sda1      8:1    0  200M  0 part /boot/efi
└─sda2      8:2    0 19.8G  0 part /
loop0       7:0    0  512M  0 loop
└─loop0p1 259:0    0  256M  0 loop
$ sudo blkid
/dev/sda1: SEC_TYPE="msdos" UUID="8939-51F5" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="c8b5c89a-17ed-480e-b9f6-0e811c16fee3"
/dev/sda2: LABEL="root" UUID="a8ee4848-df7a-4cc9-a9f0-07e423353d28" TYPE="xfs" PARTUUID="e8d78e3d-29f6-44f1-bd31-977ffd4b3d7d"
/dev/loop0: PTTYPE="gpt"
/dev/loop0p1: PARTLABEL="Linux filesystem" PARTUUID="b0ad9144-89bf-49ce-9038-f70d9d69d7ea"

I notice here that the partition does not have a UUID. Why might that be?

And then when attempting to mount the loop device.

$ sudo mount /dev/loop0 /secOpsMnt/
mount: /dev/loop0 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'

Comments

  • luisviveropena
    luisviveropena Posts: 1,249

    Hi @GRO 108 , I have the following questions:

    1.- What OS and version are you working with?

    2.- Did you do "losetup -f" before using /dev/loop0 ? "losetup -f" gives the first available loop device. And it's probably you are messing something up if /dev/loop0 was busy. This is how it looks on Ubuntu 20.04:

    luis@ubuntu20:~$ sudo losetup -f
    /dev/loop9

    ==> That means I could start working with /dev/loop9, not anything below that.

    So, just to check on it:

    luis@ubuntu20:~$ ls -l /dev/loop*
    brw-rw---- 1 root disk 7, 0 Kun 19 18:25 /dev/loop0
    brw-rw---- 1 root disk 7, 1 Kun 19 18:25 /dev/loop1
    brw-rw---- 1 root disk 7, 2 Kun 19 18:25 /dev/loop2
    brw-rw---- 1 root disk 7, 3 Kun 19 18:25 /dev/loop3
    brw-rw---- 1 root disk 7, 4 Kun 19 18:25 /dev/loop4
    brw-rw---- 1 root disk 7, 5 Kun 19 18:26 /dev/loop5
    brw-rw---- 1 root disk 7, 6 Kun 19 18:26 /dev/loop6
    brw-rw---- 1 root disk 7, 7 Kun 19 18:26 /dev/loop7
    brw-rw---- 1 root disk 7, 8 Kun 19 18:26 /dev/loop8
    brw-rw---- 1 root disk 7, 9 Kun 19 19:12 /dev/loop9
    crw-rw---- 1 root disk 10, 237 Kun 19 18:25 /dev/loop-control

    And lsblk shows that /dev/loop0 is being used:

    luis@ubuntu20:~$ lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    loop0 7:0 0 49,8M 1 loop /snap/snap-store/433
    loop1 7:1 0 27,1M 1 loop /snap/snapd/7264
    loop2 7:2 0 55M 1 loop /snap/core18/1705
    loop3 7:3 0 62,1M 1 loop /snap/gtk-common-themes/1506
    loop4 7:4 0 240,8M 1 loop /snap/gnome-3-34-1804/24
    loop5 7:5 0 29,9M 1 loop /snap/snapd/8542
    loop6 7:6 0 55M 1 loop /snap/core18/1880
    loop7 7:7 0 49,8M 1 loop /snap/snap-store/467
    loop8 7:8 0 255,6M 1 loop /snap/gnome-3-34-1804/36
    sda 8:0 0 15G 0 disk
    ├─sda1 8:1 0 512M 0 part /boot/efi
    ├─sda2 8:2 0 1K 0 part
    └─sda5 8:5 0 14,5G 0 part /
    sr0 11:0 1 57,7M 0 rom /media/luis/VBox_GAs_6.1.10

    So, please unmont the device and start again.

    Many regards,
    Luis.

  • GRO 108
    GRO 108 Posts: 46

    Hi @luisviveropena

    1. CentOS 7 - kernel version 3.10.0-1127.10.1.el7.x86_64
    2. I did know previous to running these steps that the /dev/loop0 device was free

    I was able to mount the loop-device with a fs attached but no GPT or partition. After running gdisk and adding those it wasn't possible to mount it.

  • coop
    coop Posts: 916

    I will try to repeate your steps later, but please note you did mkfs.ext4 on the file, sec04fs or whatever you called it, then you tried to moutnt dev/loop0 after you wiped out the entire disk with gpart as it said it did. So why should there be a fs there now? A quick glance tells me the mkfs.ext4 was discarded. It would certainly be the case if you did say "mkfs.ext4 /dev/sde ; then ran fdisk to set up partitions on sde ; and then tried to mount any of them, include /dev/sde1 .

  • GRO 108
    GRO 108 Posts: 46

    Oh that's what it is :tired_face: Thanks for pointing that out @coop

Categories

Upcoming Training