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