operating_systems:raspbian:raspbian
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| operating_systems:raspbian:raspbian [2019/04/30 08:41] – maferreira | operating_systems:raspbian:raspbian [2019/07/22 09:50] (current) – removed maferreira | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Raspbian ====== | ||
| - | ===== Clone only a directory ===== | ||
| - | git clone <git path> | ||
| - | cd <git directory> | ||
| - | git config core.sparsecheckout true | ||
| - | echo "< | ||
| - | git checkout -- | ||
| - | | ||
| - | ===== Reduce time that is used to raise network interfaces ===== | ||
| - | As root, create the " | ||
| - | mkdir / | ||
| - | vi reduce-timeout.conf | ||
| - | | ||
| - | Then add this to your " | ||
| - | [Service] | ||
| - | TimeoutStartSec=XX | ||
| - | | ||
| - | < | ||
| - | ===== Disable swap ===== | ||
| - | As root, turn off the process that automatically creates a swap file | ||
| - | / | ||
| - | |||
| - | Also as root, add " | ||
| - | vi / | ||
| - | |||
| - | ### BEGIN INIT INFO | ||
| - | # Provides: | ||
| - | # Required-Start: | ||
| - | # Required-Stop: | ||
| - | # Should-Start: | ||
| - | # Should-Stop: | ||
| - | # Default-Start: | ||
| - | # Default-Stop: | ||
| - | # Short-Description: | ||
| - | # Description: | ||
| - | # swap partition. Instead install without swap partition and then run | ||
| - | # this, with file size (re-)computed automatically to fit the current | ||
| - | # RAM size. | ||
| - | ### END INIT INFO | ||
| - | | ||
| - | exit 0 | ||
| - | | ||
| - | . / | ||
| - | | ||
| - | # get ready to work | ||
| - | PATH=/ | ||
| - | export PATH | ||
| - | | ||
| - | ... | ||
| - | | ||
| - | |||
| - | ===== Stop process using files in / ===== | ||
| - | First we need to know which processes are using files in the directory we want to make read-only. To do so, you can use the fuser command. | ||
| - | sudo fuser -v -m / | ||
| - | You should have something like this | ||
| - | USER PID ACCESS COMMAND | ||
| - | /: | ||
| - | Some other process | ||
| - | | ||
| - | root 423 Frce. rsyslogd | ||
| - | root 657 Frce. dhclient | ||
| - | | ||
| - | Some other process | ||
| - | |||
| - | < | ||
| - | |||
| - | Now, if you check rsyslog status it might be stopped because it uses / | ||
| - | vim / | ||
| - | |||
| - | [Unit] | ||
| - | Description=Generate rsyslog structure | ||
| - | Before=rsyslog.service | ||
| - | | ||
| - | [Service] | ||
| - | ExecStart=/ | ||
| - | Type=oneshot | ||
| - | | ||
| - | [Install] | ||
| - | WantedBy=default.target | ||
| - | |||
| - | |||
| - | And then create " | ||
| - | #!/bin/bash | ||
| - | | ||
| - | if [ -r / | ||
| - | WorkDirectory=$(grep " | ||
| - | else | ||
| - | echo " | ||
| - | exit 1 | ||
| - | fi | ||
| - | | ||
| - | [ -d " | ||
| - | | ||
| - | exit 0 | ||
| - | Restart rsyslog and it should work! | ||
| - | |||
| - | From the 2 processes I showed you earlier, only dhclient remains. | ||
| - | |||
| - | dhclient is launched by dhcpcd which uses a file as database for each network interface (/ | ||
| - | |||
| - | After reading the dhcpcd documentation, | ||
| - | |||
| - | So I took a look to the dhcpcd.conf manual page but I didn't found a " | ||
| - | |||
| - | I started thinking if I couldn' | ||
| - | |||
| - | If you have done the BLFS project before, you might remember installing dhcpcd package. | ||
| - | Here is what they used to compile it: | ||
| - | |||
| - | ./configure --libexecdir=/ | ||
| - | --dbdir=/ | ||
| - | make | ||
| - | sudo make install | ||
| - | As you can see, dbdir is a compilation variable that contains the path where dhcpcd can find the lease files for each network interface. | ||
| - | |||
| - | Here is the precedure I used to try to find if there is a config file other than dhcpcd.conf or if there is an option to change the default lease files path. | ||
| - | - Find out where dbdir is defined/ | ||
| - | - Search for some kind of read_config function and see where it is used | ||
| - | Unfortunately, | ||
| - | I searched in the dhcpcd.conf manual page for an option that isn't used very often in order to make the " | ||
| - | |||
| - | I choose the **xidhwaddr** option. I executed **grep -r -i " | ||
| - | ./ | ||
| - | ./ | ||
| - | ./ | ||
| - | | ||
| - | After this, I took a look to the if-options.c file to know where this C struct option where used. The first line of code I found contained a **parse_config_line function** which had a **char *line** parameter. | ||
| - | |||
| - | The next step was to find out where this function was called. I found out that it was called by a read_config function which didn't have a char *line parameter. | ||
| - | |||
| - | It was obvious that the line variable was initialised and declared inside read_config. After a research in that function, I realised that the line variable contained data from either dhcpcd.conf or / | ||
| - | |||
| - | After some time of lecture, I found out that there wasn't a config file with a lease-file option. | ||
| - | |||
| - | |||
| - | |||
| - | ===== Create a clean raspbian image ===== | ||
| - | sudo dd if=/ | ||
| - | | ||
| - | <note important> | ||
| - | |||
| - | Before modifying **cmdline.txt** and **config.txt**, | ||
| - | cp -p cmdline.txt cmdline.txt.original | ||
| - | cp -p config.txt config.txt.original | ||
| - | Once you have finished, change the output console device and remove the script that autoexpands / partition size at first startup. | ||
| - | vi cmdline.txt | ||
| - | console=serial0, | ||
| - | delete init=/ | ||
| - | |||
| - | Don't forget to enable this option, otherwise you won't be able to communicate to your raspberry pi throught raspberry debug port (TTL-232R-RPi). | ||
| - | vi config.txt | ||
| - | add this : enable_uart=1 | ||
| - | |||
| - | / | ||
| - | devtmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | / | ||
| - | tmpfs 93M | ||
| - | | ||
| - | Now, resize the / partition and create a new one. As root, type : | ||
| - | fdisk / | ||
| - | Your partition table should look like this : | ||
| - | Device | ||
| - | / | ||
| - | / | ||
| - | Delete the / partition, and create a new one (primary) which starts at **THE SAME POSITION** as the one you have just deleted, in my case 98304.\\ | ||
| - | In the **fstab**, replace **PARTUUID** by / | ||
| - | resize2fs / | ||
| - | After creating the partition that will be mounted at / | ||
| - | mkfs.ext4 / | ||
| - | |||
| - | Now, it's time to test what you have done. | ||
| - | mount -a | ||
| - | df -h | ||
| - | | ||
| - | Filesystem | ||
| - | / | ||
| - | devtmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | tmpfs | ||
| - | / | ||
| - | tmpfs 93M | ||
| - | / | ||
| - | | ||
| - | |||
| - | sudo apt update | ||
| - | sudo apt upgrade | ||
| - | |||
| - | touch /boot/ssh | ||
| - | sudo systemctl enable ssh | ||
| - | sudo systemctl start ssh | ||
| - | Reference : https:// | ||
| - | |||
| - | vi fstab | ||
| - | tmpfs / | ||
| - | tmpfs / | ||
| - | | ||
| - | reboot | ||
| - | Check if there are any errors | ||
| - | |||
| - | vi / | ||
| - | | ||
| - | [Unit] | ||
| - | Description=Generate Rsyslog structure | ||
| - | Before=syslog.service | ||
| - | | ||
| - | [Service] | ||
| - | ExecStart=/ | ||
| - | Type=oneshot | ||
| - | | ||
| - | [Install] | ||
| - | WantedBy=default.target | ||
| - | |||
| - | vi / | ||
| - | #!/bin/bash | ||
| - | | ||
| - | if [ -r / | ||
| - | WorkDirectory=$(grep " | ||
| - | else | ||
| - | echo " | ||
| - | exit 1 | ||
| - | fi | ||
| - | | ||
| - | if [ ! -d " | ||
| - | mkdir $WorkDirectory | ||
| - | fi | ||
| - | | ||
| - | exit 0 | ||
| - | |||
| - | sudo chmod 664 generateRsyslogStructure.service | ||
| - | chmod a+x generateRsyslogStructure.sh | ||
| - | | ||
| - | sudo systemctl enable enerateRsyslogStructure.service | ||
| - | vi /etc/fstab | ||
| - | tmpfs / | ||
| - | | ||
| - | reboot | ||
| - | |||
| - | vi /etc/fstab | ||
| - | tmpfs / | ||
| - | | ||
| - | reboot | ||
| - | Systemd-hostnamed doest not start | ||
| - | vi /etc/fstab | ||
| - | tmpfs / | ||
| - | | ||
| - | reboot | ||
| - | |||
| - | vi /etc/fstab | ||
| - | PARTUUID=c1dc39e5-02 | ||
| - | | ||
| - | reboot | ||
| - | |||
| - | vi /etc/fstab | ||
| - | PARTUUID=c1dc39e5-01 | ||
| - | |||
| - | sudo systemctl stop dphys-swapfile.service | ||
| - | sudo systemctl disable dphys-swapfile.service | ||
| - | reboot | ||
| - | Systemd manual: https:// | ||
| - | |||
| - | Create a partition with the unused partition size.\\ | ||
| - | --Rw mode--\\ | ||
| - | Create / | ||
| - | Mount /media/data (/ | ||
| - | reboot\\ | ||
| - | --Ro mode--\\ | ||
| - | reboot\\ | ||
| - | vi / | ||
| - | | ||
| - | #! /bin/bash | ||
| - | | ||
| - | history -c | ||
| - | set +o history | ||
| - | | ||
| - | export HISTFILESIZE=0 | ||
| - | export HISTSIZE=0 | ||
| - | unset HISTFILE | ||
| - | | ||
| - | chmod a+x / | ||
| - | | ||
| - | reboot | ||
| - | ===== Rename username ===== | ||
| - | As root account is disabled by default on raspberrian, | ||
| - | sudo mount -o remount,rw / | ||
| - | sudo su passwd root | ||
| - | And then enter the new password you want. | ||
| - | |||
| - | usermod -l acdsn pi | ||
| - | usermod -m -d /home/acdsn acdsn | ||
| - | Set a password to the user | ||
| - | passwd acdsn | ||
| - | |||
| - | ===== Rename group ===== | ||
| - | groupmod --new-name acdsn pi | ||
| - | |||
| - | ===== Rename hostname ===== | ||
| - | vi / | ||
| - | Replace the existing hostname by the new one. | ||
| - | ===== Generate ssh keys ===== | ||
| - | ssh-keygen -t rsa -b 2048 | ||
operating_systems/raspbian/raspbian.1556613705.txt.gz · Last modified: 2019/04/30 08:41 by maferreira