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