Hi I'm trying to detect ro filesystem mainly for root partition
This is portable system using usb as OS disk
The state is readonly, I cannot write anything
touch /tmp
touch: setting times of '/tmp': Read-only file system
lsblk output
lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 28.7G 0 disk
├─sdb1 8:17 1 512M 0 part /boot/efi
└─sdb2 8:18 1 15.5G 0 part /
This is the json output
{
"blockdevices": [
{
"name": "sdb",
"kname": "sdb",
"path": "/dev/sdb",
"maj:min": "8:16",
"fsavail": null,
"fssize": null,
"fstype": null,
"fsused": null,
"fsuse%": null,
"fsver": null,
"mountpoint": null,
"label": null,
"uuid": null,
"ptuuid": "cc59543f-1263-436b-b654-441947b5d432",
"pttype": "gpt",
"parttype": null,
"parttypename": null,
"partlabel": null,
"partuuid": null,
"partflags": null,
"ra": 128,
"ro": false,
"rm": true,
"hotplug": true,
"model": "SanDisk_3.2Gen1",
"serial": "0401915ccab85f2287ceb131fd353892d7ae4b148e3eff697bb2af15fdab6e26684500000000000000000000899c7a1b00827b18915581076eab2054",
"size": "28.7G",
"state": "running",
"owner": "root",
"group": "disk",
"mode": "brw-rw----",
"alignment": 0,
"min-io": 512,
"opt-io": 0,
"phy-sec": 512,
"log-sec": 512,
"rota": true,
"sched": "mq-deadline",
"rq-size": 2,
"type": "disk",
"disc-aln": 0,
"disc-gran": "0B",
"disc-max": "0B",
"disc-zero": false,
"wsame": "0B",
"wwn": null,
"rand": true,
"pkname": null,
"hctl": "52:0:0:0",
"tran": "usb",
"subsystems": "block:scsi:usb:pci",
"rev": "1.00",
"vendor": " USB ",
"zoned": "none",
"dax": false,
"children": [
{
"name": "sdb1",
"kname": "sdb1",
"path": "/dev/sdb1",
"maj:min": "8:17",
"fsavail": "506M",
"fssize": "511M",
"fstype": "vfat",
"fsused": "5M",
"fsuse%": "1%",
"fsver": "FAT32",
"mountpoint": "/boot/efi",
"label": null,
"uuid": "6729-75FE",
"ptuuid": "cc59543f-1263-436b-b654-441947b5d432",
"pttype": "gpt",
"parttype": "c12a7328-f81f-11d2-ba4b-00a0c93ec93b",
"parttypename": "EFI System",
"partlabel": null,
"partuuid": "54ce8d01-e9bc-434b-9971-5d31ded28098",
"partflags": null,
"ra": 128,
"ro": false,
"rm": true,
"hotplug": true,
"model": null,
"serial": null,
"size": "512M",
"state": null,
"owner": "root",
"group": "disk",
"mode": "brw-rw----",
"alignment": 0,
"min-io": 512,
"opt-io": 0,
"phy-sec": 512,
"log-sec": 512,
"rota": true,
"sched": "mq-deadline",
"rq-size": 2,
"type": "part",
"disc-aln": 0,
"disc-gran": "0B",
"disc-max": "0B",
"disc-zero": false,
"wsame": "0B",
"wwn": null,
"rand": true,
"pkname": "sdb",
"hctl": null,
"tran": null,
"subsystems": "block:scsi:usb:pci",
"rev": null,
"vendor": null,
"zoned": "none",
"dax": false
},
{
"name": "sdb2",
"kname": "sdb2",
"path": "/dev/sdb2",
"maj:min": "8:18",
"fsavail": "8.1G",
"fssize": "15.2G",
"fstype": "ext4",
"fsused": "6.2G",
"fsuse%": "41%",
"fsver": "1.0",
"mountpoint": "/",
"label": null,
"uuid": "f769a7b6-9d09-4bc7-9249-85f50d4a1c2e",
"ptuuid": "cc59543f-1263-436b-b654-441947b5d432",
"pttype": "gpt",
"parttype": "0fc63daf-8483-4772-8e79-3d69d8477de4",
"parttypename": "Linux filesystem",
"partlabel": null,
"partuuid": "0cf31261-d5f9-4182-894c-283bd8fb62ad",
"partflags": null,
"ra": 128,
"ro": false,
"rm": true,
"hotplug": true,
"model": null,
"serial": null,
"size": "15.5G",
"state": null,
"owner": "root",
"group": "disk",
"mode": "brw-rw----",
"alignment": 0,
"min-io": 512,
"opt-io": 0,
"phy-sec": 512,
"log-sec": 512,
"rota": true,
"sched": "mq-deadline",
"rq-size": 2,
"type": "part",
"disc-aln": 0,
"disc-gran": "0B",
"disc-max": "0B",
"disc-zero": false,
"wsame": "0B",
"wwn": null,
"rand": true,
"pkname": "sdb",
"hctl": null,
"tran": null,
"subsystems": "block:scsi:usb:pci",
"rev": null,
"vendor": null,
"zoned": "none",
"dax": false
}
]
}
]
}
in lsblk RO column it shown as 0
in the json format readonly also mark as false
But when check in /proc/mounts it shown as ro ( /dev/sdb2 )
cat /proc/mounts
/dev/sdb2 / ext4 ro,relatime,errors=remount-ro 0 0
/dev/sdb1 /boot/efi vfat rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 0
So lsblk cannot read the correct state ?
Running from debian 11
lsblk from util-linux 2.36.1
I need the output for notification, preferably using lsblk since it has json format.
I also found that /proc/mounts sometime have strange record for non root
# correct fstab but here different disk in same mount
# 2 of them ro , 1 of them rw
/dev/sdk1 /mnt/disk-***0G ext4 ro,noatime 0 0
/dev/sdo1 /mnt/disk-***0G ext4 ro,noatime 0 0
/dev/sdq1 /mnt/disk-***0G ext4 rw,noatime 0 0
Test on findmnt
├─/mnt/disk-***0G /dev/sdk1 ext4 ro,noatime
│ └─/mnt/disk-***0G /dev/sdo1 ext4 ro,noatime
│ └─/mnt/disk-***0G /dev/sdq1 ext4 rw,noatime
│ └─/mnt/disk-***0G /dev/sdl1 ext4 rw,noatime
Non root disk mount with UUID with this options
It's not that important to stale the OS if it is error, but need to know if it is error.
defaults,nofail,noatime,x-systemd.device-timeout=10s,errors=continue 0 0
lsblk
only displays whether the device itself is read-only. Ascat /proc/mounts
is showing that it is read-only, it has been mounted as such via/etc/fstab
, themount
command, or some other method. – Nasir Riley Aug 10 '23 at 01:06lsblk
shows the device as being not read-only because it isn't whereascat /proc/mounts
shows the filesystem as being read-only because it is. You said yourself in a reply to the answer below that the/etc/fstab
has the optionerrors=remount-ro
. – Nasir Riley Aug 10 '23 at 11:35