1 | <sect1 id="ch07-checkfs">
|
---|
2 | <title>Creating the checkfs script</title>
|
---|
3 |
|
---|
4 | <para>
|
---|
5 | A new file <filename>/etc/init.d/checkfs</filename> is created containing
|
---|
6 | the following:
|
---|
7 | </para>
|
---|
8 |
|
---|
9 | <literallayout>
|
---|
10 |
|
---|
11 | <userinput>cat > checkfs << "EOF"</userinput>
|
---|
12 | #!/bin/sh
|
---|
13 | # Begin /etc/init.d/checkfs
|
---|
14 |
|
---|
15 | #
|
---|
16 | # Include the functions declared in the /etc/init.d/functions file
|
---|
17 | #
|
---|
18 |
|
---|
19 | source /etc/init.d/functions
|
---|
20 |
|
---|
21 | #
|
---|
22 | # Activate all the swap partitions declared in the /etc/fstab file
|
---|
23 | #
|
---|
24 |
|
---|
25 | echo -n "Activating swap..."
|
---|
26 | /sbin/swapon -a
|
---|
27 | evaluate_retval
|
---|
28 |
|
---|
29 | #
|
---|
30 | # If the /fastboot file exists we don't want to run the partition checks
|
---|
31 | #
|
---|
32 |
|
---|
33 | if [ -f /fastboot ]
|
---|
34 | then
|
---|
35 | echo "Fast boot, no file system check"
|
---|
36 | else
|
---|
37 |
|
---|
38 | #
|
---|
39 | # Mount the root partition read-only (just in case the kernel mounts it
|
---|
40 | # read-write and we don't want to run fsck on a read-write mounted
|
---|
41 | # partition).
|
---|
42 | #
|
---|
43 |
|
---|
44 | /bin/mount -n -o remount,ro /
|
---|
45 | if [ $? = 0 ]
|
---|
46 | then
|
---|
47 |
|
---|
48 | #
|
---|
49 | # If the /forcefsck file exists we want to force a partition check even
|
---|
50 | # if the partition was unmounted cleanly the last time
|
---|
51 | #
|
---|
52 |
|
---|
53 | if [ -f /forcefsck ]
|
---|
54 | then
|
---|
55 | echo -n "/forcefsck exists, forcing "
|
---|
56 | echo "file system check"
|
---|
57 | force="-f"
|
---|
58 | else
|
---|
59 | force=""
|
---|
60 | fi
|
---|
61 |
|
---|
62 | #
|
---|
63 | # Check all the file systems mentioned in /etc/fstab that have the
|
---|
64 | # fs_passno value set to 1 or 2 (the 6th field. See man fstab for more
|
---|
65 | # info)
|
---|
66 | #
|
---|
67 |
|
---|
68 | echo "Checking file systems..."
|
---|
69 | /sbin/fsck $force -a -A -C -T
|
---|
70 |
|
---|
71 | #
|
---|
72 | # If something went wrong during the checks of one of the partitions,
|
---|
73 | # fsck will exit with a return value greater than 1. If this is
|
---|
74 | # the case we start sulogin so you can repair the damage manually
|
---|
75 | #
|
---|
76 |
|
---|
77 | if [ $? -gt 1 ]
|
---|
78 | then
|
---|
79 | $FAILURE
|
---|
80 | echo
|
---|
81 | echo -n "fsck failed. Please repair your file "
|
---|
82 | echo "systems manually by running /sbin/fsck"
|
---|
83 | echo "without the -a option"
|
---|
84 | echo
|
---|
85 | echo -n "Please note that the root file system "
|
---|
86 | echo "is currently mounted in read-only mode."
|
---|
87 | echo
|
---|
88 | echo -n "I will start sulogin now. When you "
|
---|
89 | echo "logout I will reboot your system."
|
---|
90 | echo
|
---|
91 | $NORMAL
|
---|
92 | /sbin/sulogin
|
---|
93 | /sbin/reboot -f
|
---|
94 | else
|
---|
95 | print_status success
|
---|
96 | fi
|
---|
97 |
|
---|
98 | else
|
---|
99 |
|
---|
100 | #
|
---|
101 | # If the remount to read-only mode didn't work abort the fsck and print
|
---|
102 | # an error
|
---|
103 | #
|
---|
104 |
|
---|
105 | echo -n "Cannot check root file system because it "
|
---|
106 | echo "could not be mounted in read-only mode."
|
---|
107 | fi
|
---|
108 | fi
|
---|
109 |
|
---|
110 | # End /etc/init.d/checkfs
|
---|
111 | <userinput>EOF</userinput>
|
---|
112 |
|
---|
113 | </literallayout>
|
---|
114 |
|
---|
115 | </sect1>
|
---|
116 |
|
---|