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.

  1. $ sudo dd if=/dev/zero of=secOps bs=1M count=512
  2. 512+0 records in
  3. 512+0 records out
  4. 536870912 bytes (537 MB) copied, 0.244399 s, 2.2 GB/s
  1. $ sudo mkfs.ext4 secOps
  2. mke2fs 1.42.9 (28-Dec-2013)
  3. secOps is not a block special device.
  4. Proceed anyway? (y,n) y
  5. Discarding device blocks: done
  6. Filesystem label=
  7. OS type: Linux
  8. Block size=4096 (log=2)
  9. Fragment size=4096 (log=2)
  10. Stride=0 blocks, Stripe width=0 blocks
  11. 32768 inodes, 131072 blocks
  12. 6553 blocks (5.00%) reserved for the super user
  13. First data block=0
  14. Maximum filesystem blocks=134217728
  15. 4 block groups
  16. 32768 blocks per group, 32768 fragments per group
  17. 8192 inodes per group
  18. Superblock backups stored on blocks:
  19. 32768, 98304
  20.  
  21. Allocating group tables: done
  22. Writing inode tables: done
  23. Creating journal (4096 blocks): done
  24. Writing superblocks and filesystem accounting information: done
  1. $ sudo gdisk secOps
  2. GPT fdisk (gdisk) version 0.8.10
  3.  
  4. Partition table scan:
  5. MBR: not present
  6. BSD: not present
  7. APM: not present
  8. GPT: not present
  9.  
  10. Creating new GPT entries.
  11.  
  12. Command (? for help): o
  13. This option deletes all partitions and creates a new protective MBR.
  14. Proceed? (Y/N): Y
  15.  
  16. Command (? for help): n
  17. Partition number (1-128, default 1):
  18. First sector (34-1048542, default = 2048) or {+-}size{KMGTP}:
  19. Last sector (2048-1048542, default = 1048542) or {+-}size{KMGTP}: +256M
  20. Current type is 'Linux filesystem'
  21. Hex code or GUID (L to show codes, Enter = 8300):
  22. Changed type of partition to 'Linux filesystem'
  23.  
  24. Command (? for help): p
  25. Disk secOps: 1048576 sectors, 512.0 MiB
  26. Logical sector size: 512 bytes
  27. Disk identifier (GUID): 941146DD-99DB-4A90-B400-8D7D1534AF21
  28. Partition table holds up to 128 entries
  29. First usable sector is 34, last usable sector is 1048542
  30. Partitions will be aligned on 2048-sector boundaries
  31. Total free space is 524221 sectors (256.0 MiB)
  32.  
  33. Number Start (sector) End (sector) Size Code Name
  34. 1 2048 526335 256.0 MiB 8300 Linux filesystem
  35.  
  36. Command (? for help): w
  37.  
  38. Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
  39. PARTITIONS!!
  40.  
  41. Do you want to proceed? (Y/N): Y
  42. OK; writing new GUID partition table (GPT) to secOps.
  43. Warning: The kernel is still using the old partition table.
  44. The new table will be used at the next reboot.
  45. The operation has completed successfully.
  1. $ sudo losetup /dev/loop0 secOps
  2. $ sudo lsblk
  3. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  4. sda 8:0 0 20G 0 disk
  5. ├─sda1 8:1 0 200M 0 part /boot/efi
  6. └─sda2 8:2 0 19.8G 0 part /
  7. loop0 7:0 0 512M 0 loop
  8. └─loop0p1 259:0 0 256M 0 loop
  1. $ sudo blkid
  2. /dev/sda1: SEC_TYPE="msdos" UUID="8939-51F5" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="c8b5c89a-17ed-480e-b9f6-0e811c16fee3"
  3. /dev/sda2: LABEL="root" UUID="a8ee4848-df7a-4cc9-a9f0-07e423353d28" TYPE="xfs" PARTUUID="e8d78e3d-29f6-44f1-bd31-977ffd4b3d7d"
  4. /dev/loop0: PTTYPE="gpt"
  5. /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.

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

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 1,272

    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.

  • 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.

  • 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 .

  • Posts: 46

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

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training