force recheck on reboot – fsck

If you want to force a fsck re-check on reboot, then just

touch /forcefsck

 

Enhanced by Zemanta

Set some disk params to be safe

It is always “Better safe than sorry” so, here are some things you
should do..

First check fstab, if you have partitions other than root then use UUID instead of device:

 UUID=a8f13a0d-3f1f-42e4-b076-f44b4163306c /mnt/Backup     ext4 defaults,relatime 1 2

Then entries for all your mounts should be like above.
Points to note here :

Disk is mounted using the UUID and not with /dev/sdXX. This ensures
that even if your disk ids change, you will be able to mount them. To
get the partition UUID, you can execute :

lsblk -f
#OR
blkid /dev/sdXX

disk mouting params include relatime ( this is really optional and
depends on your personal preference.) When this option is set, basically
the acess time for the file and directories are update only on writes.
There is also a noatime option, but that has its own demerits. By
default the option is “atime” which means for each acess (even reads)
there will be a write ( to update the atime). So, setting this should
improve performance.
Make sure that last param is 2 and not zero. This would mean that
fsck checks are done and they are done after “/” checks

Now, we do little more to make sure that we are not delayed with fsck
every time the system boots. So, lets check some params for the
patitions, using tune2fs:

tune2fs -l /dev/sdXX |egrep -i '(Check|mount count)'

You should see output like below :

Mount count:              0
Maximum mount count:      40     
Last checked:             Wed Sep  4 08:37:24 2013     
Check interval:           2592000 (1 month)     
Next check after:         Fri Oct  4 08:37:24 2013

Here, points to note::

  • maximum mount count is set. This means that after every 40 mounts, the disk will be checked.
  • Check interval is set, so it means that after 1 month disk will be checked even if it was not mounted for 40 times in this period.

Now, if you dont have those, then you can execute:

 tune2fs -c 40 /dev/sdXX             # to set maximum mount count
tune2fs -i 1m /dev/sdXX             # to set the check interval
tune2fs -c 40 -i 1m /dev/sdXX       # to set both of above.

Now, one thing to keep in mind is to make sure that if you have multiple
partitions, which will be the case, then sparse the interval durations
and do not plan on using the same duration. This will ensure that your
fsck checks at boot time do not “ALL” happen on the same day, same time.

Was a bit tad longer than usual but thats all for today.
(In case you are still worried then you can always check for bad blocks with command “badblocks” and if you too worried then you should google
for “Why Linux does not need defragmentation”)

 

 

Enhanced by Zemanta

Script to add all the partitions to the fstab.

Script to add all the partitions to the fstab.

I wrote a simple script today to get all the partitions on all the disks and then create fstab entry with them. The script also gets the UUID and uses the same to make the entry 🙂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash -
#===============================================================================
#
#          FILE:  mount_add_all.sh
#
#         USAGE:  ./mount_add_all.sh
#
#   DESCRIPTION:  Find all the <a class=\"zem_slink freebase/en/disk_partitioning\" title=\"Disk partitioning\" rel=\"wikipedia\" href=\"http://en.wikipedia.org/wiki/Disk_partitioning\">disk partitions</a> and all those that are not present
#                 in the fstab.
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  <a class=\"zem_slink\" title=\"Digital Inspiration\" rel=\"homepage\" href=\"http://amit-agarwal.co.in\">Amit Agarwal</a> (AKA), amit.agarwal@amit-agarwal.co.in
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  06/19/2010 10:44:34 PM IST
#      REVISION:  0.1
#===============================================================================
file=\"/tmp/fstab\"
disk_types=(hd sd)
count=${#disk_types}

find_disks ()
{
echo ${#disk_types} $count
for i in $(seq 1 $count)
do
(( j=i-1 ))
echo $i $j
echo $j ${disk_types[0]} ${disk_types[1]}
disk_array[$j]=$(ls <a class=\"zem_slink freebase/en/device_file_system\" title=\"Device file\" rel=\"wikipedia\" href=\"http://en.wikipedia.org/wiki/Device_file\">/dev</a>/${disk_types[$j]}[a-z])
echo ${disk_array[$j]}
done
}    # ----------  end of function find_disks  ----------

find_partitions ()
{
echo \"In find_partitions\"
l=0
count=${#disk_types}
for i in $(seq 1 $count)
do
((j=i-1))
for k in ${disk_array[$i]}
do
echo $k
<!--loginview start-->disk_partitions[$l]=`fdisk -l $k |<a class=\"zem_slink freebase/en/grep\" title=\"Grep\" rel=\"wikipedia\" href=\"http://en.wikipedia.org/wiki/Grep\">grep</a> \"^/dev\" |grep -v \"Extended$\"|cut -d\" \" -f1`
echo ${disk_partitions[$l]} $l<!--loginview end-->
((l++))
done
done
}    # ----------  end of function find_partitions  ----------

add_fat ()
{
echo \"# Added with script for $label and $k\" >> $file
echo \"$uuid /mnt/$label vfat nosuid,nodev,uhelper=udisks,uid=500,gid=500,shortname=mixed,dmask=0077  0 0\"  >> $file
}    # ----------  end of function add_fat  ----------

add_<a class=\"zem_slink freebase/en/ext3\" title=\"Ext3\" rel=\"wikipedia\" href=\"http://en.wikipedia.org/wiki/Ext3\">ext3</a> ()
{
echo \"# Added with script for $label and $k\" >> $file
echo \"$uuid /mnt/$label ext3     defaults     0 0\" >> $file

}    # ----------  end of function add_ext3  ----------

find_UUID ()
{
echo \"In find_UUID with $l\"
((l--))
for i in $(seq 0 $l)
do
echo ${disk_partitions[$i]}
for k in ${disk_partitions[$i]}
do
echo $k
<!--loginview start-->temp=$(blkid $k)
label=$(echo $temp|grep \"LABEL=\"|sed \'s/.*LABEL=\"//\'|sed \'s/\".*//\')
uuid=$(echo $temp|grep \"UUID=\"|sed \'s/.*UUID=\"//\'|sed \'s/\".*//\')
atype=$(echo $temp|grep \"TYPE=\"|sed \'s/.*TYPE=\"//\'|sed \'s/\".*//\')<!--loginview end-->
if [ $atype = \"vfat\" ]
then
add_fat $label $uuid $k
fi
if [ $atype = \"ext3\" ]
then
add_ext3 $label $uuid $k
fi
echo $label $uuid $atype
done
done
}    # ----------  end of function find_UUID  ----------

find_disks
find_partitions
find_UUID
\"Enhanced