封云亭 发表于 2018-5-12 12:40:03

Redhat 5裸设备配置方法

  在Redhat 5 之前的版本中,系统通过/etc/sysconfig/rawdevices配置raw的控制文件,通过/etc/init.d/rawdevices来管理raw设备的启动和关闭。而在Redhat 5之后,原来的raw设备接口已经取消了,redhat 5中通过udev规则进行配置。 要配置,需要编辑/etc/udev/rules.d/60-raw.rules 这个文件。
  下面给出一个添加raw设备的测试过程。
  1.现在虚拟机上添加一个硬盘。 我们仅做测试,所以分10M。
  2. 启动我们的虚拟机,连上后查看磁盘情况
# fdisk -l
  Disk /dev/sda: 16.1 GB, 16106127360 bytes
  255 heads, 63 sectors/track, 1958 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Device Boot      Start         End      Blocks   IdSystem
  /dev/sda1   *         201      1958    14121135   83Linux
  /dev/sda2               1         200   1606468+82Linux swap / Solaris
  Partition table entries are not in disk order
  Disk /dev/sdb: 10 MB, 10485760 bytes
  64 heads, 32 sectors/track, 10 cylinders
  Units = cylinders of 2048 * 512 = 1048576 bytes
  Disk /dev/sdb doesn't contain a valid partition table
  这里的/dev/sdb 因为是刚加上来的硬盘,还没有格式化。
  3. 分区/dev/sdb
# fdisk /dev/sdb
  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  Building a new DOS disklabel. Changes will remain in memory only,
  until you decide to write them. After that, of course, the previous
  content won't be recoverable.
  Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
  Command (m for help): n
  Command action
  e   extended
  p   primary partition (1-4)
  p
  Partition number (1-4): 1
  First cylinder (1-10, default 1):
  Using default value 1
  Last cylinder or +size or +sizeM or +sizeK (1-10, default 10):
  Using default value 10
  Command (m for help): w
  The partition table has been altered!
  Calling ioctl() to re-read partition table.
  Syncing disks.
  查看格式化之后的硬盘情况:
# fdisk -l
  Disk /dev/sda: 16.1 GB, 16106127360 bytes
  255 heads, 63 sectors/track, 1958 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Device Boot      Start         End      Blocks   IdSystem
  /dev/sda1   *         201      1958    14121135   83Linux
  /dev/sda2               1         200   1606468+82Linux swap / Solaris
  Partition table entries are not in disk order
  Disk /dev/sdb: 10 MB, 10485760 bytes
  64 heads, 32 sectors/track, 10 cylinders
  Units = cylinders of 2048 * 512 = 1048576 bytes
  Device Boot      Start         End      Blocks   IdSystem
  /dev/sdb1               1          10       10224   83Linux
#
  4. 修改/etc/udev/rules.d/60-raw.rules文件
# more /etc/udev/rules.d/60-raw.rules
  # Enter raw device bindings here.
  #
  # An example would be:
  #   ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"
  # to bind /dev/raw/raw1 to /dev/sda, or
  #   ACTION=="add", ENV{MAJOR}=="8", ENV{MINOR}=="1", RUN+="/bin/raw /dev/raw/raw2 %M %m"
  # to bind /dev/raw/raw2 to the device with major 8, minor 1.
  设备名称:
  ACTION==&quot;add&quot;, KERNEL=&quot;<device name>&quot;, RUN+=&quot;/bin/raw /dev/raw/rawX %N&quot;
  主/次号码:
  ACTION==&quot;add&quot;, ENV{MAJOR}=&quot;A&quot;, ENV{MINOR}=&quot;B&quot;, RUN+=&quot;/bin/raw /dev/raw/rawX %M %m&quot;
  用你需要绑定的设备名称替换 <device name>(如:/dev/sda1)。&quot;A&quot; 和 &quot;B&quot; 是设备的主/次号码,X 是系统使用的 raw 设备号码。在设置的时候,主次号码是可选的。 如果不指定,默认从1,1开始,
  如:/dev/raw/raw1:bound to major 1, minor 1
  现在我们把/dev/sdb1 知道到raw1上,就可以在/etc/udev/rules.d/60-raw.rules文件里添加如下内容:
  ACTION==&quot;add&quot;, KERNEL==&quot;sdb1&quot;,RUN+=&quot;/bin/raw /dev/raw/raw1 %N&quot;
  5. 重启服务:
# start_udev
  Starting udev:            
  6. 查看raw设备:
# ls -lrt /dev/raw
  total 0
  crw------- 1 root root 162, 1 Aug8 06:56 raw1
# raw -aq
  /dev/raw/raw1:bound to major 1, minor 1
  如果我们添加了下面的语句:
  ACTION==&quot;add&quot;, ENV{MAJOR}==&quot;8&quot;,ENV{MINOR}==&quot;1&quot;,RUN+=&quot;/bin/raw /dev/raw/raw1 %M %m&quot;
  那么就会显示我们指定的Major和minor。
# ls -lrt /dev/raw
  total 0
  crw-rw---- 1 dave tianlesoftware 162, 1 Aug8 08:06 raw1
# raw -aq
  /dev/raw/raw1:bound to major 8, minor 1
  7. 设置raw设备的用户和权限信息
  在/etc/udev/rules.d/60-raw.rules文件里添加如下信息:
  ACTION==&quot;add&quot;, KERNEL==&quot;raw1&quot;, OWNER=&quot;dave&quot;, GROUP=&quot;tianlesoftware&quot;, MODE=&quot;660&quot;
  如果有多个raw设备,可以写成:
  ACTION==&quot;add&quot;, KERNEL==&quot;raw&quot;, OWNER=&quot;dave&quot;, GROUP=&quot;tianlesoftware&quot;, MODE=&quot;660&quot;
  在Oracle 中使用raw设备时,如果裸设备对应的属组不是oracle,裸设备将无法供oracle使用。
  查看结果:
# start_udev
  Starting udev:                                 
# ls -lrt /dev/raw
  total 0
  crw-rw---- 1 dave tianlesoftware 162, 1 Aug8 06:59 raw1
# raw -aq
  /dev/raw/raw1:bound to major 1, minor 1
  8. 取消raw 映射
  把major and minor设成0,就可以取消裸设备的绑定。
# raw /dev/raw/raw9 0 0
页: [1]
查看完整版本: Redhat 5裸设备配置方法