在讓PC的ArchLinux可以自動掛載USB儲存裝置後,
覺得網樂通上面要手動實在太不人性化了。
在看 /etc/rc.sysinit 時看到 mdev,
echo /sbin/mdev > /proc/sys/kernel/hotplug
表示有新裝置接上時會叫mdev處理。
找到設定檔 /etc/mdev.conf 裡面寫
sd[a-z].* root:disk 660 */lib/mdev/usbdisk_link
表示會去執行 /lib/mdev/usbdisk_link 處理,
660後面的* 表示接上和移除都會執行一次。
可是連/lib/mdev 資料夾都沒有,
所以原來的系統才會什麼事都沒做。
用 /lib/mdev/usbdisk_link 找到 Gentoo Wiki:Mdev/Automount USB/automount
可是貼上去還是不會動,
因為裡面採用的是目前還沒裝的 pmount。
只好手動改成if判斷的mount。
script附在文章最後,
在關鍵行加上LED燈號變化超好用的,
可以馬上知道有沒有掛成功。
另外在 /etc/lircrc 加上下面的程式碼(未測試),
就可以用i鍵umount
begin
button = KEY_INFO
prog = irexec
repeat = 0
config = sync;for i in `find /media -name sd*`;do umount $i;done
flags = quit
end
接著中場休息編譯一下exfat套件。
原本很高興只有需要fuse,
結果編譯時特別需要 scons。
結果還是遇到之前用IPv6 kernel一樣的問題,
抓原始碼時會找到IPv6的位址去。
但是現在編套件比較要緊,
手動抓下原始碼包放在PKGBUILD旁,
兩個都順利編完。
接下來解決大魔王IPv6問題。
找了一下HiNet的IPv6資料,
好像沒有馬上可以用的方式。
接下來試著取消eth0的IPv6,
結果蠢蠢的下了這個指令:
ip link set eth0 down
結果就只能用遙控器重開機了。
但是還是無效。
接著懷疑到DHCP的 udhcp。
最後在Askubuntu找到
Prefer A (IPv4) DNS lookups before AAAA(IPv6) lookups提到下面這行到 /etc/resolv.conf
options single-request
順利解決。
可是這時候還有個問題,
udhcp會自動更新 /etc/resolv.conf。
ArchWiki上只有 dhcpcd 的方式,
提到 udhcp 是依據 /usr/share/udhcpc/default.script 執行。
所以在 echo -n > $RESOLV_CONF 之後加上
#Only IPv4, no IPv6
echo "options single-request" > $RESOLV_CONF
收工。
可是好像 samba 連不上,之後再說。
#### /lib/mdev/usbdisk_link ####
參考:https://wiki.gentoo.org/wiki/Mdev/Automount_USB/automount
#!/bin/busybox ash
#
remove_action () {
#
# Unmount the device. The user should really unmount it before
# disconnecting
umount ${1}
#
# Delete the directory in ${mountdir}
rm -rf ${2}
}
# At bootup, "mdev -s" is called. It does not pass any environmental
# variables other than MDEV. If no ACTION variable is passed, exit
# the script.
#
# Execute only if the device already exists; otherwise exit
if [ ! -b ${MDEV} ] ; then exit 0 ; fi
#
# Make mountdir a var in case the pmount default directory ever changes
mountdir="/media"
#
# Flag for whether or not we have a partition. 0=no, 1=yes, default no
partition=0
#
# File descriptors 0, 1, and 2 are closed before launching this script.
# Many linux utilities are hard-coded to work with these file descriptors.
# So we need to manually open them.
0< /dev/fd0
1> /dev/fd1
#
# Note that the redirect of stderr to a temporary logfile in /dev/shm in
# append mode is commented out. Uncomment if you want to debug problems.
# 2>> /dev/shm/mdev_err.txt
#
# Uncomment next line for debug data dump to /dev/shm/mdevlog.txt.
# env >> /dev/shm/mdevlog.txt
#
# Check for various conditions during an "add" operation
if [ "X${ACTION}" == "Xadd" ] ; then
#
# Flag for mounting if it's a regular partition
if [ "X${DEVTYPE}" == "Xpartition" ] ; then
partition=1 ;
#
# Further checks if DEVTYPE is disk; looking for weird setup where the
# entire USB key is formatted as one partition, without the standard
# partition table.
elif [ "X${DEVTYPE}" == "Xdisk" ] ; then
#
# If it's "disk", check for string "FAT" in first 512 bytes of device.
# Flag as a partition if the string is found.
if dd if=${MDEV} bs=512 count=1 2>/dev/null | grep "FAT" 1>/dev/null ; then
partition=1
fi
fi
fi
#
# check for various conditions during a "remove" operation
if [ "X${ACTION}" == "Xremove" ] ; then
#
# Check for a disk or regular partition
if [ "X${DEVTYPE}" == "Xpartition" ] || [ "X${DEVTYPE}" == "Xdisk" ] ; then
#
# Flag for unmounting if device exists in /proc/mounts mounted somewhere
# under the ${mountdir} directory (currently hardcoded as "/media"). It
# really should be unmounted manually by the user before removal, but
# people don't always remember.
if grep "^/dev/${MDEV} ${mountdir}/" /proc/mounts 1>/dev/null ; then
partition=1
fi
fi
#
# If the user has manually unmounted a device before disconnecting it, the
# directory is no longer listed in /proc/mounts. This makes things more
# difficult. The script has to walk through ${mountdir} and remove all
# directories that don't show up in /proc/mounts
for dir in $( ls ${mountdir} )
do
if [ -d ${mountdir}/${dir} ]; then
if ! grep " ${mountdir}/${dir} " /proc/mounts ; then
rm -rf ${mountdir}/${dir}
fi
fi
done
fi
#
####
if test -n `lsblk -o KNAME,FSTYPE|grep ${MDEV}|awk '{ print $2}'` ;then
partition=1;
fi
####
# If not flagged as a partition, bail out.
if [ ${partition} -ne 1 ] ; then exit 0 ; fi
#
# The "add" action.
if [ "X${ACTION}" == "Xadd" ] ; then
#
# Create the directory in ${mountdir}
mkdir -p ${mountdir}/${MDEV}
#
# Mount the directory in ${mountdir}
## pmount --umask 007 --noatime /dev/${MDEV}
####
fstype=`lsblk -o KNAME,FSTYPE|grep ${MDEV}|awk '{ print $2}'`
if [ ${fstype} == "vfat" ] ; then
mount -t vfat -o rw,codepage=950,iocharset=utf8,fmask=0666 /dev/${MDEV} ${mountdir}/${MDEV}
elif [ ${fstype} == "ntfs" ] ; then
mount -t ntfs-3g -o rw,noatime,codepage=950,iocharset=utf8,fmask=0666 /dev/${MDEV} ${mountdir}/${MDEV}
elif [ ${fstype} == "exfat" ] ; then
mount -t exfat -o rw,codepage=950,iocharset=utf8,fmask=0666 /dev/${MDEV} ${mountdir}/${MDEV}
else
mount -t auto -o sync /dev/${MDEV} ${mountdir}/${MDEV}
fi
####
# The "remove" action.
elif [ "X${ACTION}" == "Xremove" ] ; then
#
# Get info from /proc/mounts, and call remove_action to unmount the
# device and remove the associated directory
procmounts=$(grep "^/dev/${MDEV} ${mountdir}/" /proc/mounts)
remove_action ${procmounts}
fi
沒有留言:
張貼留言