Skip to content

Commit

Permalink
Merge pull request #282 from Integral-Tech/remove-unused-sudo
Browse files Browse the repository at this point in the history
Remove unnecessary sudo
  • Loading branch information
jserv authored Nov 11, 2024
2 parents f3405fe + 6d9d127 commit af8a3e6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lkmpg.tex
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,18 @@ \subsection{What Modules are in my Kernel?}

To discover what modules are already loaded within your current kernel use the command \sh|lsmod|.
\begin{codebash}
sudo lsmod
lsmod
\end{codebash}

Modules are stored within the file \verb|/proc/modules|, so you can also see them with:
\begin{codebash}
sudo cat /proc/modules
cat /proc/modules
\end{codebash}

This can be a long list, and you might prefer to search for something particular.
To search for the \verb|fat| module:
\begin{codebash}
sudo lsmod | grep fat
lsmod | grep fat
\end{codebash}

\subsection{Is there a need to download and compile the kernel?}
Expand Down Expand Up @@ -370,7 +370,7 @@ \subsection{The Simplest Module}
At this point the command:
\begin{codebash}
sudo lsmod | grep hello
lsmod | grep hello
\end{codebash}
should return nothing.
Expand All @@ -381,7 +381,7 @@ \subsection{The Simplest Module}
The dash character will get converted to an underscore, so when you again try:
\begin{codebash}
sudo lsmod | grep hello
lsmod | grep hello
\end{codebash}
You should now see your loaded module. It can be removed again with:
Expand All @@ -392,7 +392,7 @@ \subsection{The Simplest Module}
Notice that the dash was replaced by an underscore.
To see what just happened in the logs:
\begin{codebash}
sudo journalctl --since "1 hour ago" | grep kernel
journalctl --since "1 hour ago" | grep kernel
\end{codebash}
You now know the basics of creating, compiling, installing and removing modules.
Expand Down Expand Up @@ -1088,7 +1088,7 @@ \subsection{Unregistering A Device}
Normally, when you do not want to allow something, you return an error code (a negative number) from the function which is supposed to do it.
With \cpp|cleanup_module| that's impossible because it is a void function.
However, there is a counter which keeps track of how many processes are using your module.
You can see what its value is by looking at the 3rd field with the command \sh|cat /proc/modules| or \sh|sudo lsmod|.
You can see what its value is by looking at the 3rd field with the command \sh|cat /proc/modules| or \sh|lsmod|.
If this number isn't zero, \sh|rmmod| will fail.
Note that you do not have to check the counter within \cpp|cleanup_module| because the check will be performed for you by the system call \cpp|sys_delete_module|, defined in \src{include/linux/syscalls.h}.
You should not use this counter directly, but there are functions defined in \src{include/linux/module.h} which let you increase, decrease and display this counter:
Expand Down Expand Up @@ -1340,20 +1340,20 @@ \section{sysfs: Interacting with your module}
Check that it exists:

\begin{codebash}
sudo lsmod | grep hello_sysfs
lsmod | grep hello_sysfs
\end{codebash}

What is the current value of \cpp|myvariable| ?

\begin{codebash}
sudo cat /sys/kernel/mymodule/myvariable
cat /sys/kernel/mymodule/myvariable
\end{codebash}

Set the value of \cpp|myvariable| and check that it changed.

\begin{codebash}
echo "32" | sudo tee /sys/kernel/mymodule/myvariable
sudo cat /sys/kernel/mymodule/myvariable
cat /sys/kernel/mymodule/myvariable
\end{codebash}

Finally, remove the test module:
Expand Down

0 comments on commit af8a3e6

Please sign in to comment.