加载中…
正文 字体大小:

How to use multiple MBR partitions in NetBSD

(2013-03-01 14:45:34)
Couple of days ago i asked a question on netbsd-users list as to how to use multiple MBR partitions in NetBSD.

See the main thread along with associated replies http://mail-index.netbsd.org/netbsd-users/2013/02/23/msg012530.html

The mail responses and internet search results were interesting as they highlighted: . the group think . the conventional wisdom of experienced users . newbies continue to take the easy way out . rtfm has a new meaning 'read the four manuals' (netbsd, openbsd, dragonflybsd and freebsd).

The answer seemed like "use the whole disk" (one single MBR partition), when installing netbsd, although the freebsd installer would warn.

However, i did not get the answer or answers or pointers that i was looking for. i thank all the people who attempted a response.

The situation is rather simple: you buy a laptop and there is a good chance you have another OS pre-installed (not applicable in my case). you resize and create enough space to install NetBSD. you retain the pre-installed OS in many cases to avoid 'voiding' the warranty and thus after sales service.

Now, i am a Gentoo Linux user on my netbook and i prefer to keep the partitions as

/dev/sda1 /boot   64 MB
 /dev/sda2 swap  4096 MB
 /dev/sda3 /     8192 MB
 /dev/sda4 /data rest-of-disk MB

Effectively, i have a bunch of symbolic links for 'distfiles/', 'mail/', 'conf/', '/var/pgdata/' etc. Anything important goes to /data and i'd back that up.

Summary, "i know the partition where my important data is and i know how my backups have to be sized" !

As i started exploring and using NetBSD (in the past i have always used FreeBSD for appliance software development and networking related stuff), i wanted to transfer the same 'usage pattern' to my NetBSD environment.

What really struck me was that most of the documentation and blogs are silent on this.

A NetBSD specific mapping to the partition layout i highlighted above would look like

 wd0  
    wd0a  /
    wd0b  swap
    wd0d  entire-disk

The question then is, what is the tag or label or numbering scheme for the second MBR partition on disk (wd0) ?

rtfm (read the four manuals) will highlight to me that in openbsd, the two partitions would be like ad4s1 and ad4s2. but in netbsd ?

The output of 'fdisk' command is shown below.

# fdisk

Disk: /dev/rwd0d
NetBSD disklabel disk geometry:
cylinders: 620181, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 625142448

BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 625142448

Partitions aligned to 2048 sector boundaries, offset 63

Partition table:
0: NetBSD (sysid 169)
    start 63, size 32767937 (16000 MB, Cyls 0-2039/181/62), Active
1: NetBSD (sysid 169)
    start 32768000, size 592374448 (289245 MB, Cyls 2039/181/63-38913/80/63)
        PBR is not bootable: All bytes are identical (0x00)
2: <UNUSED>
3: <UNUSED>
Bootselector disabled.
First active partition: 0

The current status of 'disklabel' looks like # disklabel wd0


# /dev/rwd0d:
type: unknown
disk: ST9320325AS   
label:
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 16
sectors/cylinder: 1008
cylinders: 620181
total sectors: 625142448
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0        # microseconds
track-to-track seek: 0    # microseconds
drivedata: 0

16 partitions:
       size    offset     fstype [fsize bsize cpg/sgs]
 a:  25205040        63     4.2BSD   2048 16384     # (Cyl.      0*-  25005*)
 b:   7562897  25205103       swap                     # (Cyl.  25005*-  32507*)
 c:  32767937        63     unused               # (Cyl.      0*-  32507*)
 d: 625142448            unused               # (Cyl.      0 - 620180)

It seems there is no way to guess what the numbering scheme is, but since this is such a common requirement.

So, i went and read the man(ual) page for 'fdisk', after fdisk is the utility to work with MBR partitions (aka DOS partitions). After not finding what i was looking for, scanned the SEE ALSO section which mentioned - mbr(8) and mbrlabel(8).

The mbr(8) man page did not load (no entry for mbr in the manual). However, the man page for 'mbrlabel(8)' seemed useful.

An excerpt here "mbrlabel is used to update a netbsd disklabel from the mbr labels found on the disks that were previously used on dos/windows systems (or other mbr using systems)."

Perhaps this holds the key to the 'elusive' (secret) numbering scheme used for other mbr partitions. So, i issued the command

# mbrlabel wd0

Found 4.2BSD partition; size 32767937 (15999 MB), offset 63
  skipping existing unused partition at slot c.
Found 4.2BSD partition; size 592374448 (289245 MB), offset 32768000
  adding 4.2BSD partition to slot e.

16 partitions:
       size    offset     fstype [fsize bsize cpg/sgs]
 a:  25205040        63     4.2BSD   2048 16384     # (Cyl.      0*-  25005*)
 b:   7562897  25205103       swap                     # (Cyl.  25005*-  32507*)
 c:  32767937        63     unused               # (Cyl.      0*-  32507*)
 d: 625142448            unused               # (Cyl.      0 - 620180)

Not updating disk label.

The response was encouraging, as the output clearly shows the detected mbr partitions and that the second mbr partition would be added to 'slot e'.

Lets go ahead and try to update the disklable using the mbrlabel command.

# mbrlabel -r -w wd0

Found 4.2BSD partition; size 32767937 (15999 MB), offset 63
  skipping existing unused partition at slot c.
Found 4.2BSD partition; size 592374448 (289245 MB), offset 32768000
  adding 4.2BSD partition to slot e.

16 partitions:
       size    offset     fstype [fsize bsize cpg/sgs]
 a:  25205040        63     4.2BSD   2048 16384     # (Cyl.      0*-  25005*)
 b:   7562897  25205103       swap                     # (Cyl.  25005*-  32507*)
 c:  32767937        63     unused               # (Cyl.      0*-  32507*)
 d: 625142448            unused               # (Cyl.      0 - 620180)
 e:     16384  32768000     4.2BSD   1024  8192    16  # (Cyl.  32507*-  32524*)

Updating in-core and on-disk disk label.

The output seems encouraging. However, there were somethings that needed explanation and correction.

Note that the size of slot e is not correct. it should be 592374448, given the span (2039/181/63 - 38913/80/63).

The query i have is, "what is the difference between 'in-core' and 'on-disk' disklabel" ? and why do we need two representations ?

Given the fact that the size is specified in sectors, i interactively edited the disklabel entry and wrote it out. Running the 'disklabel wd0' command confirmed the updated entry.

# /dev/rwd0d:
type: unknown
disk: ST9320325AS   
label:
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 16
sectors/cylinder: 1008
cylinders: 620181
total sectors: 625142448
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0        # microseconds
track-to-track seek: 0    # microseconds
drivedata: 0

16 partitions:
       size    offset     fstype [fsize bsize cpg/sgs]
 a:  25205040        63     4.2BSD   2048 16384     # (Cyl.      0*-  25005*)
 b:   7562897  25205103       swap                     # (Cyl.  25005*-  32507*)
 c:  32767937        63     unused               # (Cyl.      0*-  32507*)
 d: 625142448            unused               # (Cyl.      0 - 620180)
 e: 592374448  32768000     4.2BSD   1024  8192    16  # (Cyl.  32507*- 620180)

However, the question that still remains in my mind is, does disklabel update both the 'in-core' and 'on-disk' disklabel ?

Anyway, the requisite information is now available to work with 'newfs' and 'mount_ffs'.

# newfs wd0e
and for 'mount_ffs'
# mount -v /dev/wd0e /data

the corresponding entry appended in '/etc/fstab' file looks like this

/dev/wd0e  /data  ffs rw  1 2

Conclusion 'mbrlabel' is the command that helps insert MBR partition details in the diskabel. The new labels can be used with newfs and mount_ffs commands.

Now, at every boot, the second MBR partition will be mounted and i can work with my data.

The backups sizing and operations will be tasked to the second MBR partition and the data therein (including pkgsrc and src).

Since i intend to run netbsd-current (like i always use gentoo snapshot), if i run into any serious issue, i can just update the first MBR partition without worrying about the data (couple of files and symbolic links need to be taken care of though).

ToDo i need to ask around and learn more about the significance of 'in-core' and 'on-disk' disklabel. Also get a good idea about the various disklabel options.

Hope this blog post will help other 'netbsd newbies' figure out possible solution to the situation i encountered.

xie xie !


阅读 评论 收藏 转载 喜欢 打印举报
已投稿到:
  • 评论加载中,请稍候...
发评论

       

    验证码: 请点击后输入验证码 收听验证码

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有