summaryrefslogtreecommitdiff
path: root/3 Resources/Linux
diff options
context:
space:
mode:
Diffstat (limited to '3 Resources/Linux')
-rw-r--r--3 Resources/Linux/APT.md5
-rw-r--r--3 Resources/Linux/Definitions.md6
-rw-r--r--3 Resources/Linux/Device drivers.md22
-rw-r--r--3 Resources/Linux/Device mapper.md28
-rw-r--r--3 Resources/Linux/LSOF.md69
-rw-r--r--3 Resources/Linux/PXE.md19
-rw-r--r--3 Resources/Linux/Users.md22
-rw-r--r--3 Resources/Linux/Watch.md4
-rw-r--r--3 Resources/Linux/filesystems/Tmpfs.md16
9 files changed, 191 insertions, 0 deletions
diff --git a/3 Resources/Linux/APT.md b/3 Resources/Linux/APT.md
new file mode 100644
index 0000000..9231d40
--- /dev/null
+++ b/3 Resources/Linux/APT.md
@@ -0,0 +1,5 @@
+#linux #packages #how-to
+
+---
+reinstall packages:
+`apt reinstall <pkg>` \ No newline at end of file
diff --git a/3 Resources/Linux/Definitions.md b/3 Resources/Linux/Definitions.md
new file mode 100644
index 0000000..c0ca4dd
--- /dev/null
+++ b/3 Resources/Linux/Definitions.md
@@ -0,0 +1,6 @@
+#linux #definitions
+
+---
+NBP = Network Bootstrap Program
+PXE = Preboot Execution Environment
+NIC = Network Interface Card \ No newline at end of file
diff --git a/3 Resources/Linux/Device drivers.md b/3 Resources/Linux/Device drivers.md
new file mode 100644
index 0000000..95f1a75
--- /dev/null
+++ b/3 Resources/Linux/Device drivers.md
@@ -0,0 +1,22 @@
+#linux #devices
+
+---
+major, minor numbers
+major = driver (used by kernel when opening device to dispatch to correct driver)
+minor = used by driver to differentiate device(s)
+
+after disk the major, minor numbers are shown:
+```
+[jasras@n04.compute.vps2-lej1 ~]$ ls -l /dev/dm-*
+brw-rw---- 1 root disk 253, 0 Oct 25 10:10 /dev/dm-0
+brw-rw---- 1 root disk 253, 1 Oct 25 10:11 /dev/dm-1
+brw-rw---- 1 root root 253, 11 Oct 28 19:58 /dev/dm-11
+brw-rw---- 1 root root 253, 12 Oct 28 19:58 /dev/dm-12
+```
+
+available devices: `cat /proc/devices`
+
+character devices vs block devices; what is the difference?
+
+---
+[oreilly-device-drivers](https://www.oreilly.com/library/view/linux-device-drivers/0596000081/ch03s02.html) \ No newline at end of file
diff --git a/3 Resources/Linux/Device mapper.md b/3 Resources/Linux/Device mapper.md
new file mode 100644
index 0000000..059a0d1
--- /dev/null
+++ b/3 Resources/Linux/Device mapper.md
@@ -0,0 +1,28 @@
+#linux #device-mapper
+
+---
+Device mapper is a kernel driver to map physical block devices to virtual ones; this means that for example we can have many physical devices be represented by a single virtual one (linear mapping).
+
+How does it work?
+[[1 projects/Inwerken Mohammed/TODO]]
+What is its function in relation to multipath?
+
+Logical devices using device-mapper can be managed using `man 8 dmsetup`
+```
+[jasras@n04.compute.vps2-lej1 ~]$ sudo dmsetup info 3600a098038314d736724566a67346538
+Name: 3600a098038314d736724566a67346538
+State: ACTIVE
+Read Ahead: 256
+Tables present: LIVE
+Open count: 1
+Event number: 3
+Major, minor: 253, 12
+Number of targets: 1
+UUID: mpath-3600a098038314d736724566a67346538
+```
+
+If dmsetup cannot remove a device because a process still has it open, but lsof does not show any processes that open it, use `-f` which replaces the device with a fake that rejects all I/O.
+
+---
+[device-mapper](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/device_mapper#device_mapper)
+[dmsetup](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/dmsetup#dmsetup) \ No newline at end of file
diff --git a/3 Resources/Linux/LSOF.md b/3 Resources/Linux/LSOF.md
new file mode 100644
index 0000000..5a3aa95
--- /dev/null
+++ b/3 Resources/Linux/LSOF.md
@@ -0,0 +1,69 @@
+#linux #how-to
+
+---
+
+```
+lsof -p 1111 # show open files for this PID
+lsof /path/to/file # show which process has this open
+```
+
+A usage in the wild; using lsof to find the qemu process for a specific base image and using that to get instance name and disk path:
+```
+lsof -F p {{ item['path'] }} | cut -b 2- | head -1 | xargs ps | grep -oP '(instance\\-[a-z0-9]+)|(\\/var\\/lib\\/nova\\/instances\\/[a-z0-9\\-]+\\/disk)' | uniq
+```
+
+(man lsof: search "OUTPUT FOR OTHER PROGRAMS")
+output for other programs
+```
+specify -F
+These are the fields that lsof will produce. The single character listed first is the field identifier.
+ a file access mode
+ c process command name (all characters from proc or
+ user structure)
+ C file structure share count
+ d file's device character code
+ D file's major/minor device number (0x<hexadecimal>)
+ f file descriptor (always selected)
+ F file structure address (0x<hexadecimal>)
+ G file flaGs (0x<hexadecimal>; names if +fg follows)
+ g process group ID
+ i file's inode number
+ K tasK ID
+ k link count
+ l file's lock status
+ L process login name
+ m marker between repeated output
+ M the task comMand name
+ n file name, comment, Internet address
+ N node identifier (ox<hexadecimal>
+ o file's offset (decimal)
+ p process ID (always selected)
+ P protocol name
+ r raw device number (0x<hexadecimal>)
+ R parent process ID
+ s file's size (decimal)
+ S file's stream identification
+ t file's type
+ T TCP/TPI information, identified by prefixes (the
+ `=' is part of the prefix):
+ QR=<read queue size>
+ QS=<send queue size>
+ SO=<socket options and values> (not all dialects)
+ SS=<socket states> (not all dialects)
+ ST=<connection state>
+ TF=<TCP flags and values> (not all dialects)
+ WR=<window read size> (not all dialects)
+ WW=<window write size> (not all dialects)
+ (TCP/TPI information isn't reported for all supported
+ UNIX dialects. The -h or -? help output for the
+ -T option will show what TCP/TPI reporting can be
+ requested.)
+ u process user ID
+ z Solaris 10 and higher zone name
+ Z SELinux security context (inhibited when SELinux is disabled)
+ 0 use NUL field terminator character in place of NL
+ 1-9 dialect-specific field identifiers (The output
+ of -F? identifies the information to be found
+ in dialect-specific fields.)
+
+``` \ No newline at end of file
diff --git a/3 Resources/Linux/PXE.md b/3 Resources/Linux/PXE.md
new file mode 100644
index 0000000..dcd59e7
--- /dev/null
+++ b/3 Resources/Linux/PXE.md
@@ -0,0 +1,19 @@
+---
+tags:
+ - linux
+---
+The NBP is a bootloader that is obtained via the network typically via [[TFTP]]. It handles setting up an environment in which an OS can run or install. For example, it displays a boot menu and downloads the kernel images. It sets up hardware, for example the [[NIC]]s.
+
+PXE boot process:
+1. Modified [[DHCP]] request: request to include boot information (PXE boot request).
+2. Process DHCP response which includes an IP address of [[TFTP]] server and filename of [[NBP]].
+3. Download NBP over TFTP.
+4. NBP executes
+ 1. Loads additional stuff over network, like kernel images.
+ 2. Handles the boot menu
+5. Kernel takes over boot process and potentially downloads additional files required to complete booting.
+
+Popular NBP's:
+- PXELINUX
+- iPXE
+- GRUB2
diff --git a/3 Resources/Linux/Users.md b/3 Resources/Linux/Users.md
new file mode 100644
index 0000000..885a7cc
--- /dev/null
+++ b/3 Resources/Linux/Users.md
@@ -0,0 +1,22 @@
+#linux #user-management
+
+Change uid/gid of user
+`usermod -u newnumber user`
+`groupmod -g newnumber user`
+
+File permissions in homedir will be automatically updated; file perms outside home dir will not be automatically updated.
+
+Finding files of a specific user, and printing their uid/gid;
+`sudo find / -user 4109 -printf '%p %u(%U) %g(%G)\n'`
+
+To change only the group: `chgrp`.
+
+Or using find to chmod/chgrp:
+`sudo find / -user 4109 -group 4109 -exec chmod 998:998 {} \;`
+`sudo find / -group 4109 -exec chgrp 998 {} \;`
+
+Dirty way to find "system users" (uid < 999) - note that this is not fool-proof, it also lists groups
+`getent passwd | grep -oP '\b[0-9]{3}\b' | uniq | sort`
+
+---
+https://www.cyberciti.biz/faq/linux-change-user-group-uid-gid-for-all-owned-files/
diff --git a/3 Resources/Linux/Watch.md b/3 Resources/Linux/Watch.md
new file mode 100644
index 0000000..0c167b7
--- /dev/null
+++ b/3 Resources/Linux/Watch.md
@@ -0,0 +1,4 @@
+#linux #how-to
+
+---
+`watch (1)` periodically executes the executable on argv. It can be used to reload the output of a command, like `sudo watch ovs-dpctl dump-flows` .
diff --git a/3 Resources/Linux/filesystems/Tmpfs.md b/3 Resources/Linux/filesystems/Tmpfs.md
new file mode 100644
index 0000000..b8fe839
--- /dev/null
+++ b/3 Resources/Linux/filesystems/Tmpfs.md
@@ -0,0 +1,16 @@
+#linux #filesystem
+
+---
+Is a [[virtual filesystem]] that is stored in memory; it uses both RAM and swap space.
+> Kernel option: CONFIG_TMPFS
+
+`mount -t tmpfs source target`
+
+A tmpfs can only grow to 50% of RAM avail. unless overridden with size=nbytes mount option.
+Only consumes RAM for actual usage.
+Data is ephemeral/volatile.
+
+Mount stacking: mount over existing /tmp, to improve speed of apps using alot of tmp files, then unmount to delete data.
+
+Kernel uses tmpfs for [[system v shared memory]] and [[shared anonymous memory mappings]].
+`/dev/shm` or `/run/shm`: [[glibc]] of [[POSIX]] shared memory and [[POSIX]] semaphores. \ No newline at end of file