disklabelの不思議 (3) scsictl
2008/04/09(水) 28:26 NetBSD はてブ情報 はてブに登録 はてブ数

ddなどでディスクをつぶしてon-diskなラベルとin-coreなラベルに齟齬が発生した場合に、USB経由のディスクならば一度抜いて再度挿せばon-diskとin-coreの整合性がとれるという話の続きです。

抜き差しなんてしなくてもscsictlで同じことができるよ、というのをIRCで教えてもらいました。

具体的にはscsictlのdetach, scanを使います。

まずは、on-disk, in-coreで齟齬が発生した状況を作ります。
eeepc# dd if=/dev/zero of=/dev/rsd1d count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.001 secs (512000 bytes/sec)
eeepc# disklabel -r sd1
disklabel: could not read existing label
eeepc# disklabel sd1                        
# /dev/rsd1d:
中略
4 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:  31388609        63     4.2BSD      0     0     0  # (Cyl.      0*-  15326*)
 c:  31388609        63     unused      0     0        # (Cyl.      0*-  15326*)
 d:  31388672         0     unused      0     0        # (Cyl.      0 -  15326*)
eeepc#
on-diskはラベルがなく、in-coreは古いラベルを表示しています。

dmesgでみると
sd1 at scsibus1 target 0 lun 0: <Generic, USB SD Reader, 1.00> disk removable
となっていますのでscsictlに与えるdeviceはscsibus1, targetは0, lunは0だとわかります。
eeepc# scsictl /dev/scsibus1 detach 0 0
sd1 detached
sd1が切り離されました。それではdisklabel sd1はどうでしょうか?
eeepc# disklabel sd1
disklabel: /dev/rsd1d: Device not configured
当然、デバイスがないので失敗します。

再度sd1を使えるようにscsictlのscanを実行します。
eeepc# scsictl /dev/scsibus1 scan 0 0  
sd1 at scsibus1 target 0 lun 0: <Generic, USB SD Reader, 1.00> disk removable
sd1: fabricating a geometry
sd1: 15326 MB, 15326 cyl, 64 head, 32 sec, 512 bytes/sect x 31388672 sectors
sd1: fabricating a geometry
sd1がattachされたようなのでdisklabelを見ます。
eeepc# disklabel sd1                   
# /dev/rsd1d:
中略
4 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:  31388672         0     4.2BSD      0     0     0  # (Cyl.      0 -  15326*)
 d:  31388672         0     unused      0     0        # (Cyl.      0 -  15326*)
disklabel: boot block size 0
disklabel: super block size 0
ddでつぶされてon-diskなラベルがないため、fictitiousなin-coreラベルが作られました。

なるほど、抜き差し不要でラベルの同期ができるscsictlコマンドは覚えておいて損はないですね。

なお、sd1は次のようなデバイス階層で接続されていました。
mainbus0 (root)
  pci0 at mainbus0 bus 0: configuration mode 1
    ehci0 at pci0 dev 29 function 7: Intel 82801FB/FR USB EHCI Controller (rev. 0x04)
      usb4 at ehci0: USB revision 2.0
        uhub4 at usb4
          umass1 at uhub4 port 3 configuration 1 interface 0
            scsibus1 at umass1: 2 targets, 3 luns per target
              sd1 at scsibus1 target 0 lun 0: <Generic, USB SD Reader, 1.00> disk removable

名前:  非公開コメント   

  • TB-URL  http://www.tokuda.net/diary/0573/tb/

今日のボク
2008/04/09(水) 20:59 今日のボク はてブ情報 はてブに登録 はてブ数

今日は自由帳と学童の連絡帳を忘れて帰ってきましたよ。

毎日何かを忘れて帰ってくるね。

明日から授業だそうです。

名前:  非公開コメント   

  • TB-URL  http://www.tokuda.net/diary/0572/tb/

disklabelの不思議 (2) fictitious
2008/04/09(水) 8:31 NetBSD はてブ情報 はてブに登録 はてブ数

藤原さんから
label: fictitious
っていう行が(これは良きにはからったものだよ)という意味になっているかどうか、つまり本当に、「良きにはからった時」だけに表示されるかが気になるのですが、自分では実はまだ確めたことがないのです。
というコメントをいただいたので試してみました。

まず、ddでMBRとラベルをつぶし(dd if=/dev/zero of=/dev/rsd1d bs=512k count=10)、fdisk, disklabel -rで確認します。
eeepc# fdisk sd1
fdisk: primary partition table invalid, no magic in sector 0
fdisk: Cannot determine the number of heads
Disk: /dev/rsd1d
NetBSD disklabel disk geometry:
cylinders: 31, heads: 64, sectors/track: 32 (2048 sectors/cylinder)
total sectors: 64000

BIOS disk geometry:
cylinders: 31, heads: 64, sectors/track: 32 (2048 sectors/cylinder)
total sectors: 64000

Partition table:
0: <UNUSED>
1: <UNUSED>
2: <UNUSED>
3: <UNUSED>
Bootselector disabled.
No active partition.
eeepc#
eeepc# disklabel -r sd1
disklabel: could not read existing label
eeepc#
たしかにon-diskなラベルはありませんね。では、in-coreラベルを作ってもらい、それを表示してもらいましょう。
eeepc# disklabel sd1
# /dev/rsd1d:
type: SCSI
disk: ClipDrive       
label: fictitious
flags: removable
bytes/sector: 512
sectors/track: 32
tracks/cylinder: 64
sectors/cylinder: 2048
cylinders: 31
total sectors: 64000
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0 

4 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:     64000         0     4.2BSD      0     0     0  # (Cyl.      0 -     31*)
 d:     64000         0     unused      0     0        # (Cyl.      0 -     31*)
disklabel: boot block size 0
disklabel: super block size 0
eeepc#
おぉ、labelにfictitiousが表示されてます。

それでは、このラベルをon-diskに書いてしまい、disklabel -rで確認してみます。
eeepc# disklabel -i -I sd1
partition> P
4 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:     64000         0     4.2BSD      0     0     0  # (Cyl.      0 -     31*)
 d:     64000         0     unused      0     0        # (Cyl.      0 -     31*)
partition> W
Label disk [n]? y
Label written
partition> Q
eeepc#
eeepc# disklabel -r sd1   
# /dev/rsd1d:
type: SCSI
disk: ClipDrive       
label: fictitious
flags: removable
bytes/sector: 512
sectors/track: 32
tracks/cylinder: 64
sectors/cylinder: 2048
cylinders: 31
total sectors: 64000
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0 

4 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:     64000         0     4.2BSD      0     0     0  # (Cyl.      0 -     31*)
 d:     64000         0     unused      0     0        # (Cyl.      0 -     31*)
eeepc#
あれ? on-diskラベルでもfictitiousって表示されます。

あぁ、そうでした。label: factitousっていうのをそのままラベルとして書いてしまったので当然on-diskにもその文字列が書き込まれてしまったのですね (sd1はUSBメモリですが、抜き差ししても同じ表示)。

じゃぁ、disklabel -eでlabelを空文字列にしてみると、って試してみたら、on-diskでもin-coreでも空文字列が表示されます。当たり前か。

つまり、disklabelがfictitiousを表示するのはon-diskなラベルが存在しないときだけ、それ以外のときにはon-diskなラベルに書かれたlabelに相当する文字列をそのまま表示する (on-diskにfictitiousって文字列が入っていればそれを表示する)、ということのようです。

利用する上ではdisklabelを書くときにはlabel: fictitiousをそのままにしない (たとえば日付などを入れる) 習慣をつけておくと、後から役に立つかもなぁ、と思いました。

1: makoto fujiwara 2008年04月09日(水) 午後4時25分

その文字をそのままにしておくと、書いてしまう、なんて思っても見ませんでした。良く分りましたね。すごい。というか書くときに ficticious だったら、何か別の文字にしておいてよねって send-br したい気分


名前:  非公開コメント   

  • TB-URL  http://www.tokuda.net/diary/0571/tb/