将Debian fstab转换为通过linux-base使用UUID?

前端之家收集整理的这篇文章主要介绍了将Debian fstab转换为通过linux-base使用UUID?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们有一些Debian 5系统仍在fstab中使用/ dev / hda.我们想将它们转换为使用UUID.这应该是通过“ linux-base”软件包(postinst)自动完成的,但由于某些原因它并没有开始(可能有人已经运行它并且它保存了一些状态而不去做).

虽然通过手动编辑一堆文件可以切换到UUID,但以某种方式编写脚本会很有用. debconf和debconf-set-choices的各种咒语似乎都不起作用.

基本上,如何调用Debian提供的脚本来执行所有UUID转换?

解决方法

Per Gabor Vincze,来自 Ubuntu forums的脚本似乎做了一个不错的代码
  1. #!/bin/bash
  2. # This script will change all entries of the form /dev/sd* in /etc/fstab to their appropriate UUID names
  3. # You must have root privelages to run this script (use sudo)
  4. if [ `id -u` -ne 0 ]; then # Checks to see if script is run as root
  5. echo "This script must be run as root" >&2 # If it isn't,exit with error
  6. exit 1
  7. fi
  8.  
  9. cp /etc/fstab /etc/fstab.backup
  10. sed -n 's|^/dev/\([sh]d[a-z][0-9]\).*|\1|p' </etc/fstab >/tmp/devices # Stores all /dev entries from fstab into a file
  11. while read LINE; do # For each line in /tmp/devices
  12. UUID=`ls -l /dev/disk/by-uuid | grep "$LINE" | sed -n 's/^.* \([^ ]*\) -> .*$/\1/p'` # Sets the UUID name for that device
  13. sed -i "s|^/dev/${LINE}|UUID=${UUID}|" /etc/fstab # Changes the entry in fstab to UUID form
  14. done </tmp/devices
  15. cat /etc/fstab # Outputs the new fstab file
  16. printf "\n\nWrite changes to /etc/fstab? (y/n) "
  17. read RESPONSE;
  18. case "$RESPONSE" in
  19. [yY]|[yY][eE][sS]) # If answer is yes,keep the changes to /etc/fstab
  20. echo "Writing changes to /etc/fstab..."
  21. ;;
  22. [nN]|[nN][oO]|"") # If answer is no,or if the user just pressed Enter
  23. echo "Aborting: Not saving changes..." # don't save the new fstab file
  24. cp /etc/fstab.backup /etc/fstab
  25. rm /etc/fstab.backup
  26. ;;
  27. *) # If answer is anything else,exit and don't save changes
  28. echo "Invalid Response" # to fstab
  29. echo "Exiting"
  30. cp /etc/fstab.backup /etc/fstab
  31. rm /etc/fstab.backup
  32. exit 1
  33. ;;
  34. esac
  35. rm /tmp/devices
  36. echo "DONE!"

猜你在找的Linux相关文章