Skip to contentSkip to conversation

Determine if a given fs is a btrfs fs

DISCUSSION Felix Blanke 3 participants 5 messages Oct 24, 2010 – Oct 25, 2010 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hi,

I've some btrfs fs which are encrypted with loopaes.

I decrypt them in a script during bootup. Now I want to determine if the decrypted fs is a btrfs fs. If not I missspelled the password and I can handle that error in my script.

Thanks for any help!

Felix

#1 lore raw

Here are some cues...
p4 jerome # file -s /dev/mapper/vgP4RAID5-openwrt /dev/mapper/vgP4RAID5-openwrt: symbolic link to `../dm-22' p4 jerome # file -s /dev/dm-22
/dev/dm-22: BTRFS Filesystem (label "p4-openwrt", sectorsize 4096, nodesize 4096, leafsize 4096)
p4 jerome # btrfs device scan /dev/dm-22
Scanning for Btrfs filesystems in '/dev/dm-22'
p4 jerome # echo $?
0
p4 jerome # btrfs device scan /dev/sda
Scanning for Btrfs filesystems in '/dev/sda'
ERROR: unable to scan the device '/dev/sda'
p4 jerome # echo $?
11
p4 jerome # blkid | grep btrfs /dev/mapper/vgP4RAID5-openwrt: LABEL=3D"p4-openwrt" UUID=3D"9a68f4cc-4bda-4cdb-9726-481b340f742c" UUID_SUB=3D"37bfc8b8-c8aa-415e-bbb3-cbb50cca2ab7" TYPE=3D"btrfs" p4 jerome #

On Sun, Oct 24, 2010 at 4:24 PM, Felix Blanke <[email protected]> w= rote:

Quoted 5 lines

Hi,

I've some btrfs fs which are encrypted with loopaes.

I decrypt them in a script during bootup. Now I want to determine if =

the decrypted fs

Quoted 1 line

is a btrfs fs. If not I missspelled the password and I can handle tha=

t error in my

Quoted 9 lines

script.

Thanks for any help!

Felix
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs=

" in

Quoted 3 lines

the body of a message to [email protected]
More majordomo info at =A0http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

On Sun, Oct 24, 2010 at 5:32 PM, J=E9r=F4me Poulin <jeromepoulin@gmail.= com> wrote:
=2E..

Quoted 4 lines

p4 jerome # btrfs device scan /dev/dm-22 Scanning for Btrfs filesystems in '/dev/dm-22' p4 jerome # echo $?
0

This is OK.

Quoted 5 lines

p4 jerome # btrfs device scan /dev/sda Scanning for Btrfs filesystems in '/dev/sda'
ERROR: unable to scan the device '/dev/sda' p4 jerome # echo $?
11

=2E..
But isn't that error misleading, btrfs scan was succesfully able to scan /dev/sda, but, it doesn't contain btrfs, right?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 1 line · On Mon, Oct 25, 2010 at 6:31 AM, J=E9r=F4me Poulin <jeromepoulin@gmail.= com>…

On Sun, Oct 24, 2010 at 5:32 PM, J=E9r=F4me Poulin <jeromepoulin@gmai=

Quoted 7 lines · l.com> wrote:

...

Quoted 4 lines

p4 jerome # btrfs device scan /dev/dm-22 Scanning for Btrfs filesystems in '/dev/dm-22' p4 jerome # echo $?
0

This is OK.

Quoted 8 lines
Quoted 5 lines

p4 jerome # btrfs device scan /dev/sda Scanning for Btrfs filesystems in '/dev/sda'
ERROR: unable to scan the device '/dev/sda' p4 jerome # echo $?
11

...
But isn't that error misleading, btrfs scan was succesfully able to scan /dev/sda, but, it doesn't contain btrfs, right?

imo, the best way is:

# root must be btrfs else silent return
[ "$(blkid -s TYPE -o value ${root})" =3D btrfs ] || return 0

at least that the way i do it in my initramfs hook; seems to be reliabl= e.

C Anthony
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Hi,

that was a good hint, thanks a lot!

The best at that solution is that it works for all filesystems: Just te= st if the
output of $type (type=3Dblkid -s TYPE -o value $loopdev) is empty (''= ), then it is no
filesystem and the loopaes password was wrong or the device/fs is broke= n.

=46elix

Quoted 7 lines · C Anthony Risinger

Date: Mon, 25 Oct 2010 08:29:58 -0500
From: C Anthony Risinger <[email protected]>
To: J=E9r=F4me Poulin <[email protected]>
Cc: linux-btrfs <[email protected]>
Subject: Re: Determine if a given fs is a btrfs fs
=20
On Mon, Oct 25, 2010 at 6:31 AM, J=E9r=F4me Poulin <jeromepoulin@gmai=

Quoted 1 line · l.com> wrote:
Quoted 1 line

On Sun, Oct 24, 2010 at 5:32 PM, J=E9r=F4me Poulin <jeromepoulin@gm=

Quoted 15 lines · ail.com> wrote:
Quoted 7 lines

...

Quoted 4 lines

p4 jerome # btrfs device scan /dev/dm-22 Scanning for Btrfs filesystems in '/dev/dm-22' p4 jerome # echo $?
0

This is OK.

Quoted 8 lines
Quoted 5 lines

p4 jerome # btrfs device scan /dev/sda Scanning for Btrfs filesystems in '/dev/sda'
ERROR: unable to scan the device '/dev/sda' p4 jerome # echo $?
11

...
But isn't that error misleading, btrfs scan was succesfully able to scan /dev/sda, but, it doesn't contain btrfs, right?

Quoted 7 lines

=20
imo, the best way is:
=20

# root must be btrfs else silent return
[ "$(blkid -s TYPE -o value ${root})" =3D btrfs ] || return 0
=20
at least that the way i do it in my initramfs hook; seems to be relia=

ble.

Quoted 4 lines

=20
C Anthony
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs=

" in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

---end quoted text---
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html