Iemhof: Difference between revisions

From Geitenpad
Jump to navigation Jump to search
 
m 1 revision imported
(No difference)

Revision as of 14:34, 5 January 2025

Disable integrated devices

In BIOS disable bluetooth, wifi and camera

Setup LVM

Create Large partition 600G while booted Linux Mint from USB Create pv

pvcreate /dev/sda5

Create vg iemhof and add sda5

vgcreate iemhof /dev/sda5

Create lvs

lvcreate --name root --size 35G iemhof
lvcreate --name var --size 100G iemhof
lvcreate --name ja --size 100G iemhof
lvcreate --name a --size 100G iemhof
lvcreate --name vb --size 100G iemhof
lvcreate --name vms --size 150G iemhof

Install base system

Install Debian 10 Buster using lvm

Add some users

root@iemhof:~# adduser janarie
pw: JAvB5282
root@iemhof:~# adduser anneke
pw: AJCdR1959!

Install utilities

root@iemhof:~# apt install vim screen htop aptitude tree curl mlocate unzip ntp openssh-server

Prevent hibernate on lid close

root@iemhof:~# vim /etc/systemd/logind.conf
  • Add line
HandleLidSwitch=ignore

Call pp for ip (uitgezet backup op Stack)

root@paardenpad:/var/www/html/ip# ls -l
total 8
-rw-r--r-- 1 www-data www-data   0 Aug  9 16:13 iemhof_ip
-rw-r--r-- 1 www-data www-data  39 Jul 12 12:38 index.php
-rw-r--r-- 1 www-data www-data 350 Aug  9 16:14 post.php
root@paardenpad:/var/www/html/ip# cat index.php 
<?php echo $_SERVER['REMOTE_ADDR']; ?>
root@paardenpad:/var/www/html/ip# cat post.php 
<?php

if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['ip'])) {

   if(isIemhof($_POST)) {
       writeIemhof($_POST);
   }

}

function isIemhof($POST) {
   return $POST['username'] == 'iemhof' && $POST['password'] == 'qui2Niab';
}

function writeIemhof($POST) {
   file_put_contents(iemhof_ip, $POST['ip']);
}


?>

Set following script into cronjob

root@iemhof:~/scripts# cat phoneHome 
#!/bin/bash
curl https://paardenpad.rijkenmiel.nl/ip/ | xargs -i curl --data "username=iemhof&password=qui2Niab&ip={}" https://paardenpad.rijkenmiel.nl/ip/post.php
root@iemhof:~/scripts#

Add line to /etc/crontab:

0  7  *  *  *   root    /root/scripts/phoneHome

Backup Nextcloud

BackupNCIemhof.sh (/root/scripts/backupNc in cron)

#!/bin/bash

WORK_DIR="/root"
BACKUP_FILE="nc_iemhof.sql"
STACK_SERVER="rijkierijk.stackstorage.com"
STACK_USER="janarie@rijkierijk.stackstorage.com"
export SSHPASS='SJMebb6AQFkDODSm'

echo `date`

cd $WORK_DIR
mysqldump --lock-tables -u nextcloud --password='Md8NqM1MbVY31hHX' -h 127.0.0.1 -P 3310 nextcloud > $WORK_DIR/$BACKUP_FILE


sshpass -e sftp -oBatchMode=no -b - $STACK_USER@$STACK_SERVER << !
   put nc_iemhof.sql
   bye
!

rm -rf $BACKUP_FILE

Add Docker

root@iemhof:~# sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
root@iemhof:~# curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
root@iemhof:~# add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/debian \
    $(lsb_release -cs) \
    stable"
root@iemhof:~# apt update
root@iemhof:~# apt-get install docker-ce docker-ce-cli containerd.io

Install landisplusgyr

root@iemhof:~# usermod -a -G dialout janarie

Copy jar, applications.properties and dockerfile to /home/rijk/landisplusgyr on iemhof

root@iemhof:/home/rijk/landisplusgyr# docker build . -t landisplusgyr

Run container:

root@iemhof:/home/rijk/landisplusgyr# docker run -p 8090:8080 -v /home/janarie/landisplusgyr/:/landisplusgyr/ --device=/dev/ttyUSB0 --restart always landisplusgyr

Create cleanup job in crontab:

0  0  1  *  *   janarie    mv /home/janarie/landisplusgyr/landisplusgyr_electricity.csv /home/janarie/landisplusgyr/landisplusgyr_electricity_$(date +\%Y\%m\%d).csv

Samba

root@iemhof:~# apt install samba
root@iemhof:/etc/samba# mv smb.conf smb.conf.org
root@iemhof:/etc/samba# vim smb.conf
root@iemhof:/etc/samba# cat smb.conf
[global]
       netbios name = SERVER
       workgroup = IEMHOF
       server string = %v on %L
       encrypt passwords = Yes
       name resolve order = bcast host
       local master = Yes
       os level = 33
       load printers = no
       printing = bsd
       printcap name = /dev/null
       disable spoolss = yes
[janarie]
      path = /home/janarie
      guest ok = No
      comment = Jan Aries documents
      writable = Yes
[anneke]
      path = /home/anneke
      guest ok = No
      comment = Annekes documents
      writable = Yes
[vanberkum]
      path = /home/vanberkum
      guest ok = No
      comment = Shared documents
      writable = yes


root@iemhof:/etc/samba# smbpasswd -a janarie
root@iemhof:/etc/samba# smbpasswd -a anneke 
root@iemhof:/home# mkdir vanberkum
root@iemhof:/home# groupadd vanberkum
root@iemhof:/home# adduser anneke vanberkum
root@iemhof:/home# adduser janarie vanberkum
root@iemhof:/home# chown janarie:vanberkum vanberkum/
root@iemhof:/home# systemctl restart smbd
root@iemhof:/home# systemctl restart nmbd

Give the complete disk to Jan Arie

List current partitions

root@iemhof:~# fdisk -l
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: WDC WD10SPZX-21Z
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x7bb20f4f

Device     Boot      Start        End    Sectors   Size Id Type
/dev/sda1  *          2048 1918363647 1918361600 914.8G  5 Extended
/dev/sda2       1918363648 1953523711   35160064  16.8G 82 Linux swap / Solaris
/dev/sda5             4096 1228804095 1228800000   586G 83 Linux

Create partion

root@iemhof:~# fdisk /dev/sda

Add partition with n

root@iemhof:~# fdisk -l
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: WDC WD10SPZX-21Z
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x7bb20f4f

Device     Boot      Start        End    Sectors   Size Id Type
/dev/sda1  *          2048 1918363647 1918361600 914.8G  5 Extended
/dev/sda2       1918363648 1953523711   35160064  16.8G 82 Linux swap / Solaris
/dev/sda5             4096 1228804095 1228800000   586G 83 Linux
/dev/sda6       1228806144 1918363647  689557504 328.8G 83 Linux

Change partition type to lvm

root@iemhof:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): t
Partition number (1,2,5,6, default 6): 6
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'. 

Command (m for help): w
The partition table has been altered.
Syncing disks.

Reload partion table

partprobe

Create physical volume

root@iemhof:~# pvcreate /dev/sda6
 Physical volume "/dev/sda6" successfully created.

Add /dev/sda6 to volume group

root@iemhof:~# vgextend iemhof /dev/sda6
 Volume group "iemhof" successfully extended

Add space to lv van Jan Arie

root@iemhof:~# lvextend -L+329G /dev/iemhof/ja
 Size of logical volume iemhof/ja changed from 100.00 GiB (25600 extents) to 429.00 GiB (109824 extents).
 Logical volume iemhof/ja successfully resized.

Resize filesystem

root@iemhof:~# resize2fs /dev/iemhof/ja
resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/iemhof/ja is mounted on /home/janarie; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 54
The filesystem on /dev/iemhof/ja is now 112459776 (4k) blocks long.

Remove extra space from Jan Arie

Stop landisplusgyr

root@iemhof:/home/janarie/landisplusgyr# docker container stop 66

Unmount janarie

root@iemhof:~# umount -l /home/janarie/

Remove janarie from fstab

root@iemhof:~# vim /etc/fstab 

Remount everything

root@iemhof:~# mount -a

Disable lv ja

root@iemhof:~# !536
lvchange -an /dev/mapper/iemhof-ja

Remove lv ja

root@iemhof:~# lvremove /dev/iemhof/ja
Logical volume "ja" successfully removed

Remove lv vms

root@iemhof:~# lvchange -an /dev/mapper/iemhof-vms 
root@iemhof:~# lvremove /dev/iemhof/
a     root  var   vb    
root@iemhof:~# lvremove /dev/iemhof/
a     root  var   vb    
root@iemhof:~# lvremove /dev/iemhof/vms
 Logical volume "vms" successfully removed

Remove /dev/sda6 from iemhof

root@iemhof:~# vgreduce iemhof /dev/sda6
 Removed "/dev/sda6" from volume group "iemhof"

Recreate lv ja

root@iemhof:~# lvcreate --name ja --size 10G iemhof
 Logical volume "ja" created.

Create filesystem

root@iemhof:~# mkfs.ext4 /dev/iemhof/ja
mke2fs 1.44.5 (15-Dec-2018)
Discarding device blocks: done                            
Creating filesystem with 26214400 4k blocks and 6553600 inodes
Filesystem UUID: 3319f0a9-cc02-44e4-b4f5-583ab2a44777
Superblock backups stored on blocks:
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 
       2654208, 4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done 

Mount ja to /home/janarie

root@iemhof:~# mount /dev/iemhof/ja /home/janarie/
root@iemhof:~# vim /etc/fstab 
root@iemhof:~# mount -a

Copy landisplusgyr files back to /home/janarie/landisplusgyr

Start docker container landisplusgyr

root@iemhof:/home/janarie# docker container start 66

Remove Berend

root@iemhof:/home/janarie/landisplusgyr# deluser berend --remove-home
Looking for files to backup/remove ...
Removing files ...
Removing user `berend' ...
Warning: group `berend' has no more members.
Done.

Remove Anneke completely, lv etc

Remove samba user

root@iemhof:/home/janarie/landisplusgyr# smbpasswd -x anneke
root@iemhof:/home/janarie/landisplusgyr# vim /etc/samba/smb.conf

Unmount anneke

root@iemhof:/home/janarie/landisplusgyr# umount /home/anneke
root@iemhof:/home/janarie/landisplusgyr# vim /etc/fstab

Remove user anneke

root@iemhof:/home/janarie/landisplusgyr# deluser anneke --remove-home

Remove lv a

root@iemhof:/home/janarie/landisplusgyr# lvchange -an /dev/mapper/iemhof-a 
root@iemhof:/home/janarie/landisplusgyr# lvremove /dev/iemhof/a
 Logical volume "a" successfully removed

Remove VanBerkum

root@iemhof:~# umount /home/vanberkum/
root@iemhof:~# lvchange -an /dev/mapper/iemhof-v
iemhof-var  iemhof-vb   
root@iemhof:~# lvchange -an /dev/mapper/iemhof-vb 
root@iemhof:~# lvremove /dev/iemhof/
ja    root  var   
root@iemhof:~# lvremove /dev/mapper/
control      iemhof-ja    iemhof-root  iemhof-var   
root@iemhof:~# lvremove /dev/mapper/iemhof-vb
 Logical volume "vb" successfully removed

== Create lv nc-data and mount on /var/nc-data

root@iemhof:~# lvcreate --name nc-data --size 600G iemhof
 Logical volume "nc-data" created.
root@iemhof:~# mkdir /var/nc-data
root@iemhof:~# mkfs.ext4 /dev/iemhof/nc-data 
mke2fs 1.44.5 (15-Dec-2018)
Discarding device blocks: done                            
Creating filesystem with 157286400 4k blocks and 39321600 inodes
Filesystem UUID: 5fe9826f-62c0-4a1f-a9e6-020b4012a104
Superblock backups stored on blocks:
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
       4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
       102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done     
root@iemhof:~# vim /etc/fstab 
root@iemhof:~# ls /dev/mapper/iemhof-
iemhof-ja        iemhof-nc--data  iemhof-root      iemhof-var       
root@iemhof:~# ls /dev/mapper/iemhof-nc--data
root@iemhof:~# vim /etc/fstab 
root@iemhof:~# ls /var/
backups  cache	lib  local  lock  log  lost+found  mail  nc-data  opt  run  spool  tmp
root@iemhof:~# mount -a