2011年7月24日日曜日

CentOS 6.0 で NIC と ethX の対応を変更する

CentOS 5 以下では、/etc/sysconfig/network-scripts/ifcfg-ethX の HWADDR= に MAC アドレスを指定することで、NIC と ethX の対応関係を変更することができました。しかし、CentOS 6.0 では、HWADDR= による入れ替えはできなくなりました。
CentOS 6.0 では、/etc/udev/rules.d/S70-persistent-net.rules の NAME= により、入れ替えを行うことができます。
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:8b:6c", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:8b:6d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
なお、ifcfg-ethX に、HWADDR= を指定することはできるものの、実際の MAC と一致しているかどうかのチェックのみ行うようになっています。
/etc/sysconfig/network-scripts/ifup-eth より抜粋します。
...
# bail out, if the MAC does not fit
if [ -n "${HWADDR}" ]; then
    FOUNDMACADDR=$(get_hwaddr ${REALDEVICE})
    if [ "${FOUNDMACADDR}" != "${HWADDR}" -a "${FOUNDMACADDR}" != "${MACADDR}" ]; then
            echo $"Device ${DEVICE} has different MAC address than expected, ignoring."
            exit 1
    fi
fi
...
上記が CentOS 6.0 の記述内容ですが、CentOS 5 では次のようになっており、rename_device() という関数により入れ替えが行われていました。
...
# remap, if the device is bound with a MAC address and not the right device num
# bail out, if the MAC does not fit
if [ -n "${HWADDR}" ]; then
    FOUNDMACADDR=`get_hwaddr ${REALDEVICE}`
    if [ "${FOUNDMACADDR}" != "${HWADDR}" ]; then
        curdev=`get_device_by_hwaddr ${HWADDR}`
        if [ -n "$curdev" ]; then
          rename_device "${REALDEVICE}" "${HWADDR}" "${curdev}" || {
            echo $"Device ${DEVICE} has different MAC address than expected, ignoring."
            exit 1
          }
        else
            echo $"Device ${DEVICE} has different MAC address than expected, ignoring."
            exit 1
        fi
    fi
fi
...
参考URL: https://access.redhat.com/kb/docs/DOC-17338

2011-08-07追記
固定化する方法について、書きましたので、よろしければ参照ください。
CentOS 6.0 で NIC と ethX の対応を固定化する

CentOS 6.0 で NIC 交換した場合の挙動

以前、CentOS 4 および CentOS 5 について「NIC 交換時の CentOS における kudzu の挙動」という記事を書きましたが、CentOS 6.0 の場合にはどうなるのか実験してみました。
今回も、VMware の設定ファイルをいじって実験しています。

MAC を変更して再起動したら、eth0 ではなくて eth1 になってしまいました。
[root@centos6 ~]# cat /etc/redhat-release 
CentOS Linux release 6.0 (Final)
[root@centos6 ~]# ls /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@centos6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE="eth0"
HWADDR="00:0C:29:A3:8B:6B"
NM_CONTROLLED="yes"
ONBOOT="no"
[root@centos6 ~]# cat /etc/udev/rules.d/70-persistent-net.rules 
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:8b:6b", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:8b:69", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
[root@centos6 ~]# ifconfig eth0
eth0: error fetching interface information: Device not found
[root@centos6 ~]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:A3:8B:69
CentOS 5 や 4 と違って、/etc/sysconfig/network-scripts/ifcfg-eth* が自動で増えたり書き換わることはないのですが、udev のルールファイルが自動更新されます。
素直に下記のように変更して、システムを再起動すれば、対処できます。
[root@centos6 ~]# cat /etc/udev/rules.d/70-persistent-net.rules 
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000) (custom name provided by external tool)
# SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:8b:6b", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:8b:69", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

[root@centos6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE="eth0"
HWADDR="00:0C:29:A3:8B:69"
NM_CONTROLLED="yes"
ONBOOT="no"
[root@centos6 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:A3:8B:69
わたしは初回、udev のほうに気をとられて、ifcfg-eth* の中の HWADDR の書き換えを忘れてハマりました。ご注意ください。

なお、70-persistent-net.rules ファイルを自動書き換えしているのは、/lib/udev/write_net_rules です。シェルスクリプトなので、眺めてみると、メカニズムが垣間見えて良いかも。


2011-08-07追記
固定化する方法について、書きましたので、よろしければ参照ください。
CentOS 6.0 で NIC と ethX の対応を固定化する

2011年7月18日月曜日

CentOS 6 で ntfs をマウントする

CentOS 6 においても、標準では ntfs をマウントできませんが、RHEL6 向けの EPEL が既に存在しているので、ntfs-3g をインストールすれば、マウントできるようになります。

http://download.fedora.redhat.com/pub/epel/6/

まずは、ここの epel-release-6-5.noarch.rpm をインストールします。そうすると、/etc/yum.repos.d/epel.repo が出来ますが、1点注意する必要があり、デフォルトで EPEL からアップデートしないように、/etc/yum.repos.d/epel.repo の [epel] を enabled=0 に変更します。
[epel]
...
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

ここまで準備が出来たら、ntfs-3g をインストールします。
# yum install ntfs-3g --enablerepo=epel
あとは、マウントするだけです。-t ntfs を指定してマウントすればいいです。
# mount -t ntfs /dev/sdb1 /mnt_sdb1

2011-08-07追記
CentOS 5 の場合も同様で、http://download.fedora.redhat.com/pub/epel/5/ から epel-release-5-4.noarch.rpm を拾ってきて、同様の手順でいけます。

2011-09-25追記
CentOS で、いまさら古いカーネルを使う人もいないでしょうけど、ntfs-3g は FUSE ベースなので、kernel-2.6.18-164.el5 以上である必要があります。
[root@centos5 ~]# grep FUSE /boot/config-2.6.18-128.el5 
# CONFIG_FUSE_FS is not set
[root@centos5 ~]# grep FUSE /boot/config-2.6.18-164.el5 
CONFIG_FUSE_FS=m
このように、kernel-2.6.18-164.el5 (CentOS 5.4) から FUSE が有効化されています。

2012-05-26追記
リンク切れになってましたので、追記です。
http://fedoraproject.org/wiki/EPEL
こちらの、The newest version of 'epel-release' for EL5 から epel-release-5-4.noarch を入手すれば良いです。EL6 も同様に。

2014-05-04追記
RHEL7.0 RC を試しましたが、今迄と同様に ntfs-3g は同梱されてはおらず、EPEL から提供されるようです。既に EL7 向けの beta 版 EPEL が公開されており、そちらから ntfs-3g をインストールしたところ、NTFS 領域をマウントできました。
http://developerblog.redhat.com/2014/02/20/rhel-7-beta-extra-packages/

2015-02-10追記
その後、RHEL7/CentOS7 向けの EPEL がリリース済みで、ntfs-3g が利用できます。なお、RHEL7 向けの ntfs-3g は、fstrim が可能になっています。
http://ftp.iij.ad.jp/pub/linux/fedora/epel/7/x86_64/repoview/epel-release.html

2015-11-17追記
ログイン必要ですが、Red Hat 社の Knowledgebase もあったのでメモ。
Red Hat Enterprise Linux で NTFS サポートを有効にする方法
人気ブログランキングへ にほんブログ村 IT技術ブログへ