{"id":113,"date":"2008-03-14T14:05:59","date_gmt":"2008-03-14T12:05:59","guid":{"rendered":"http:\/\/robert.kolatzek.org\/wblog\/?p=113"},"modified":"2008-03-14T14:05:59","modified_gmt":"2008-03-14T12:05:59","slug":"autofstab_mount","status":"publish","type":"post","link":"https:\/\/blog.kolatzek.org\/wblog\/113\/autofstab_mount","title":{"rendered":"automatic fstab &amp; mount -a"},"content":{"rendered":"<p>How to create \/etc\/fstab automaticly?\u00a0 &#8218;How to create \/etc\/fstab automaticly?&#8216; I was asked once by my brother (aka &#8222;Will&#8220;). My answer was very simple (like my english): &#8222;By using a Bash script&#8220;. But there are no good bash scripts to do it&#8230; (Knoppix etc does it too, but not as preciesly as my brother would like to). So he wrote it by himself&#8230;\u00a0 What does it do?<\/p>\n<p>1) It checks what do you have in \/etc\/fstab<br \/>\n2) It checks which partitions you have (Known types: Linux = auto [kernel driver will decide], Windows = fat32 [vfat], Windows NT partitions = NTFS [using ntfs-g3 driver &#8211; you should have it in your system], Linux swap partitions)<br \/>\n3) It makes dirs in \/mnt\/ (or other -&gt; see options) and mount -a<br \/>\n4) Also swap partitions<\/p>\n<p>How to use it?<\/p>\n<p>1) Put the script in a file like \/etc\/rd.d\/fstab_and_mnt.sh<br \/>\n2) Edit and change options<br \/>\n# Mountpoint:<br \/>\nMountPoint=mnt<br \/>\n#NTFS Driver avalible options: ntfs-3g; fuse; ntfs<br \/>\nNtfsDriver=ntfs-3g<br \/>\n3) chmod file with 755: &#8222;chmod 755 \/etc\/rd.d\/fstab_and_mnt.sh&#8220;<br \/>\n4) Run: &#8222;\/etc\/rd.d\/fstab_and_mnt.sh rebuild&#8220;<\/p>\n<p>=================== Script follows ============================<\/p>\n<p><!--more--><\/p>\n<p>#!\/bin\/bash<\/p>\n<p>#Of course \/mnt, but: mnt, for check in Script. If change to: media; not: \/media.<br \/>\nMountPoint=mnt<\/p>\n<p>#NTFS Driver avalible options: ntfs-3g; fuse; ntfs<br \/>\nNtfsDriver=ntfs-3g<\/p>\n<p>path=${path}<br \/>\nif [ -f \/usr\/bin\/gawk ]; then awk=\/usr\/bin\/gawk; fi<br \/>\nif [ -f \/usr\/bin\/awk ]; then awk=\/usr\/bin\/awk; fi<\/p>\n<p>if [ ! -d \/$MountPoint ]; then mkdir \/$MountPoint; fi<\/p>\n<p>Mout_DRV() {<br \/>\nblkid | while read -r device ; do<br \/>\ndev_name=&#8220;`echo &#8222;$device&#8220; | $awk &#8218;{print $1}&#8216; | cut -d &#8222;:&#8220; -f-1`&#8220;<br \/>\ndev_mount=&#8220;`echo &#8222;$dev_name&#8220; | sed &#8222;s\/dev\/$MountPoint\/&#8220;`&#8220;<br \/>\nfor i in $device; do if echo $i | grep -q &#8222;^TYPE&#8220;; then dev_sys=`echo $i | sed &#8222;s\/&#8220;\/\/g&#8220; | cut -d &#8222;=&#8220; -f2-`; fi; done<br \/>\nif [ $dev_sys ==\u00a0 &#8222;swap&#8220; ]; then<br \/>\necho $dev_name swap swap defaults 0 0 &gt;&gt;\/etc\/fstab<br \/>\nswapon $dev_name&gt;\/dev\/null 2&gt;&amp;1 &amp; swapon -a&gt;\/dev\/null 2&gt;&amp;1<br \/>\ncontinue<br \/>\nfi<br \/>\nif [ $dev_sys == &#8222;ntfs&#8220; ]; then dev_sys=$NtfsDriver; fi<\/p>\n<p>if [ ! -d $dev_mount ]; then mkdir $dev_mount; fi<\/p>\n<p>echo -e $dev_name\u00a0\u00a0\u00a0 $dev_mount $dev_sys rw,noauto,user,$1 0 0 &gt;&gt;\/etc\/fstab<\/p>\n<p>done<br \/>\n}<\/p>\n<p>Mout_DRV exec&gt;\/dev\/null<\/p>\n<p>Create_CD() {<br \/>\ndev_name=\/dev\/$1<br \/>\ndev_mount=\/$MountPoint\/$1<br \/>\nif [ ! -d \/$MountPoint\/$1 ]; then mkdir \/$MountPoint\/$1; fi<br \/>\necho $dev_name\u00a0\u00a0\u00a0 $dev_mount auto ro,noauto,user,exec 0 0 &gt;&gt;\/etc\/fstab<br \/>\n}<\/p>\n<p>for i in cdrom cdrom1; do if [ -L \/dev\/$i ]; then Create_CD $i&gt;\/dev\/null; fi; done<\/p>\n<p>RebuildFstab() {<br \/>\necho -n&gt;\/tmp\/fstab.tmp<br \/>\ncat \/etc\/fstab | while read line; do<br \/>\nline1=&#8220;`echo -e $line | $awk &#8218;{print $1}&#8217;`&#8220;<br \/>\nline2=&#8220;`echo -e $line | $awk &#8218;{print $2}&#8217;`&#8220;<br \/>\nline3=&#8220;`echo -e $line | $awk &#8218;{print $3}&#8217;`&#8220;<br \/>\nif grep -w -q &#8222;^$line1&#8220; \/tmp\/fstab.tmp; then if grep -w -q $line3 \/tmp\/fstab.tmp; then continue; fi; fi<br \/>\nif [ $(dirname ${line1}) != &#8222;\/dev&#8220; ]; then<br \/>\necho $line&gt;&gt;\/tmp\/fstab.tmp;<br \/>\nelse<br \/>\nif [ -e $line1 ]; then<br \/>\necho $line&gt;&gt;\/tmp\/fstab.tmp<br \/>\nelse<br \/>\numount $line2&gt;\/dev\/null 2&gt;&amp;1<br \/>\nrm -fr $line2<br \/>\nfi<br \/>\nfi<br \/>\ndone<br \/>\nmv -f \/tmp\/fstab.tmp \/etc\/fstab<br \/>\n}<br \/>\nif ! grep -w -q rebuild \/proc\/cmdline ; then RebuildFstab&gt;\/dev\/null; fi<\/p>\n<p>exit<\/p>\n<p>=================== Script ends ============================<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to create \/etc\/fstab automaticly?\u00a0 &#8218;How to create \/etc\/fstab automaticly?&#8216; I was asked once by my brother (aka &#8222;Will&#8220;). My answer was very simple (like my english): &#8222;By using a Bash script&#8220;. But there are no good bash scripts to do it&#8230; (Knoppix etc does it too, but not as preciesly as my brother would [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[65,74],"class_list":["post-113","post","type-post","status-publish","format-standard","hentry","category-software","tag-linux","tag-opensource","entry"],"_links":{"self":[{"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":0,"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kolatzek.org\/wblog\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}