will be replaced with MATCH
bash test if string matches regex:
if ! [[ "2" =~ '^[01]$' ]]; then
echo "not 0 or 1"
else echo "yes 0 or 1"
fi
regex must be on right side
/etc/audit/rules.d/ has auditd files
useful utils
vim gpm elinks2 lynx w3m nano tree tmux wget git ddrescue python2.7
operate line by line
while read line; do echo $line; done < file
add line numbers to anything
nl # ex.: ls | nl
copy stuff from place to place
scp SRC DEST
-r
view free disk space on partitions
df
-h
-T
-hiT
du
-h
-sch
count words in file
wc
-l
view segment of file
head -#
tail -#
is UTIL installed, and where
which UTIL
switch user
su
-
view system resource utilization
top
htop
free
-m
ps aux |grep DAEMON |grep -v grep
dd ISO to flash
remote desktop to windows
xfreerdp -d NETWORK -u USER -g #% --rfx WINBOX
-g
multiline catting to file
cat >> DEST << EOF
content goes here
line 2 of content
more content, etc
EOF
show package to install to get UTIL (rhel-based)
yum whatprovides UTIL
deal with user accounts
adduser USER
useradd -d /home/USER USER
passwd USER
mkdir /home/USER
chown USER:USER USER
cp .bashrc, etc
userdel
-r
change user account settings
passwd
chfn
chsh SHELL
important file locations
/etc/passwd
/var/log
preseed with partman section
designed on debian jessie
partman section has complex instructions for partitioning, lvm, and two kinds of raid
still unknown: which partman commands are necessary to confirm all the shit
preseed file looks like this
d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/choose_interface select eth0
d-i netcfg/disable_autoconfig boolean true
d-i netcfg/dhcp_failed note
d-i netcfg/dhcp_options select Configure network manually
d-i netcfg/get_ipaddress string 10.227.2.22/24
d-i netcfg/get_netmask string 255.255.255.0
d-i netcfg/get_gateway string 10.227.2.1
d-i netcfg/get_nameservers string 10.227.2.5
d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string a227-12
d-i netcfg/get_domain string cis226.a227.cis
d-i netcfg/hostname string a227-12
d-i hw-detect/load_firmware boolean true
d-i mirror/country string manual
d-i mirror/http/hostname string ftp.us.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i mirror/suite string stable
d-i mirror/http/proxy string http://server.cis226.a227.cis:3128
d-i passwd/root-password password class297z
d-i passwd/root-password-again password class297z
d-i passwd/user-fullname string caiser
d-i passwd/username string caiser
d-i passwd/user-password password class297z
d-i passwd/user-password-again password class297z
d-i clock-setup/utc boolean false
d-i time/zone string US/Arizona
d-i clock-setup/ntp boolean true
d-i partman-auto/method string raid
d-i partman-auto/disk string /dev/sda /dev/sdb /dev/sdc
d-i partman-auto-lvm/new_vg_name string vg_sys
d-i partman-auto/expert_recipe string finaltest :: \
1000 1000 1000 raid \
$primary{ } \
$bootable{ } \
$lvmignore{ } \
method{ raid } \
. \
1000 1000 1000 raid \
$primary{ } \
$lvmignore { } \
method{ raid } \
. \
750 750 750 raid \
$primary{ } \
$lvmignore { } \
method{ raid } \
. \
4250 4250 4250 raid \
$lvmignore { } \
method{ raid } \
. \
3500 3500 3500 raid \
$lvmignore { } \
method{ raid } \
. \
10500 10500 10500 raid \
$lvmignore { } \
method{ raid } \
. \
4000 4000 4000 xfs \
$defaultignore{_} \
$lvmok{ } \
lv_name{ home } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ xfs } \
mountpoint{ /home } \
. \
4000 4000 4000 xfs \
$defaultignore{_} \
$lvmok{ } \
lv_name{ squid } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ xfs } \
mountpoint{ /var/spool/squid3 } \
. \
512 4000 1000000000 ext4 \
$defaultignore{_} \
$lvmok{ } \
lv_name{ deleteme } \
method{ lvm } \
.
d-i partman-auto-raid/recipe string \
1 3 0 ext4 / /dev/sda1#/dev/sdb1#/dev/sdc1 . \
1 3 0 ext4 /tmp /dev/sda2#/dev/sdb2#/dev/sdc2 . \
1 3 0 swap - /dev/sda3#/dev/sdb3#/dev/sdc3 . \
5 3 0 ext4 /usr /dev/sda5#/dev/sdb5#/dev/sdc5 . \
5 3 0 ext4 /var /dev/sda6#/dev/sdb6#/dev/sdc6 . \
5 3 0 lvm - /dev/sda7#/dev/sdb7#/dev/sdc7 .
d-i preseed/late_command string lvremove -f vg_sys/deleteme
d-i partman-lvm/confirm boolean true
d-i partman-md/confirm boolean true
d-i partman/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-md/confirm_nooverwrite boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i mdadm/boot_degraded boolean true
d-i partman/mount_style select label
tasksel tasksel/first multiselect standard, ssh-server
popularity-contest popularity-contest/participate boolean false
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/sda
d-i finish-install/reboot_in_progress note
when preseeding over network, the thing uses some default networking setup which is likely not what you want
this also screws up the hostname
to make it stop and redo the network config once it's grabbed the preseed files, put this in yr main preseed file
d-i preseed/run string RUNSCRIPT
d-i preseed/include string NETCONF
where RUNSCRIPT is the name of the file that has this for contents
kill-all-dhcp; netcfg
and NETCONF is the name of a file that looks like part of a preseed file and contains the network config you want
tip: it'll look for those files in the same dir as it got the original preseed file from, unless specified otherwise
hostname can alternatively be fixed thru boot parameter?
auto url=PRESEEDURLHERE hostname=HOSTNAMEHERE
there may only be one instance of preseed/late_command
to use preseed/late_command, chroot to /target or use in-target
d-i preseed/late_command string \
in-target wget -O OUTPUTNAME URL \ # URL may be from same place as preseed files!
in-target bash OUTPUTNAME \
in-target rm OUTPUTNAME
if doing bash scripts in preseed/late_command, prefix most things with "in-target" except for echo commands
if echo commands are sent to append to files, the files need /target/ at the front of the path
echo '*.* @@syslog:514' >> /target/etc/rsyslog.conf
pipes are a thing i have not yet figured out how to get working in late_command
to enable debug mode (this is very helpful if you keep getting asked a question)
still need to figure this out
further reading:
hands.com/d-i
systemctl set-default graphical.target
/etc/dconf/profile/user
+ system-db: mate
after changing things, run dconf update
lauri.vosandi.com
starngely org.mate.background in schema listsings must be org.mate.desktop.background in dconf settings fikles
ansible on localhost
ansible-playbook -i "localhost," -c local playbook.yml
-i "localhost," -c local
NOT NEEDED WHEN
- name: testing playbook locally
hosts: localhost
connection: local
user: root
tasks:
-name: etc...
handlers only run when another task is reported as changed
ansible must be idempotent
when running shell script, check exit code
use register and changed_when, otherwise
molecule --debug test -s ansible-mate
test, verify, converge
--debug is optional
yum whatprovides UTIL
xkcd.com/1296
i.imgur.com/YsbKLlg1.gif
gpm git tree elinks2 wget make
df -h
du -sch # shows subdirs and space
free -m # ram info
ps aux |grep DAEMON |grep -v grep
which COMMAND
/var/log
peltier device
tar OPTIONS NEWFILE TARGET
c # create new tarball
t # test tarball (list / search for files within)
x # extract from tarball/compression
z # call gzip
f # force the command, may overwrite (?)
v # verbose; lists each file as it operates
read the man pages for tar!!
find IN-DIR OPTIONS
-name 'FILENAME
#searches current dir by default
-iname 'FILENAME' ignore case
-not -name 'FILENAME ?
-type
-type l
-type f
-size +-# #bytes
+-#MK
mega, kilobytes
-mtime # # modtime >= # days ago
-mtime -# # less than # days ago
-atime # access time
-user USERNAME # owned by user
-perm ### # files with that permissions
-exec BASHSCRIPT {} \;
takes results of find and runs bashscript on them; good with chmod
locate #quicker, less flexible, must know case of filename
updatedb #for locate
df -hTi # check inodes, needed for file pointers!! if run out, cant use andy remaining space
wc -l # count lines
VI
find/replace
:s/old/new %first occurrence on line
:s/old/new/g # all occurrences on likne
:%s/old/new/g # entire file
execute unix comand
:!COMMAND
save as
:w FILENAME
:#,# w FILENAME # selective wirte
pastefrom file
:r FILENAME
go to line #
[esc]# [shift]+g
:line #view line numbers
:syn on
molecule --debug-test -s ansible-PROJECT
test, converge, verify
find + unmount only bind mounts:
findmnt -Pno source,fsroot,target,maj:min | sort -sVk 4.11 | uniq --all-repeated=prepend -f 3 | sed '/^$/,+1d' | tac | awk -F'"' '{print $6}' | xargs umount -l
findmnt: pull relevant info + logging info that is unneeded here but may be useful in other ways
sort: by device number but KEEP original time-based order otherwise
uniq: find + print all lines w/ duplicated device numbers and add leading newlines to each group
sed: search + find leading newlines, rm them and the lines directly after; this rms the original mounts, which are the sources and were not made w/ bind
tac: reverse order; newest mounts first [important!]
awk: get path to each
xargs: unmount lazy each found bind mount, starting with the ones that are newest and might be layered over others
uname -r
date +%F
hostname
uptime
mount # is different than mount
df -h
lsblk
xfreerdp -u -g
fonts
there are some good free fonts out there
DejaVu Sans is most like Verdana, better looking maybe at larger sizes but Verdana has the edge in smaller sizes
Roboto Slab and Roboto Condensed are great for headings
Liberation Serif is very like Times New Roman and its Sans version is very like Arial
Open Sans looks like Calibri
Input isnt as free as the others but is damn good-looking
and Indento is cool as well
Ubuntu is kind of cool
Alte Haas Grotesk is also cool
archlinux wiki pages are great at everything, download them maybe?
TO LIST PLUGGED IN IFACES BUT NOT LOOPBACK
ip -oneline link | grep "LOWER_UP" | awk '{print $2}' | awk -F ":" '{print $1}' | grep -v lo
TO GET CONNECTION NAME WHEN GIVEN AN IFACE
nmcli con show | tail -n +2 | grep IFACE
GETS NAMES OF ALL CONNECTIONS CURRENTLY PLUGGED IN
while read -u 10 line; do # whole line read into
if $(echo $line | grep -q -w $iface); then
conname=$(echo $line | awk -F "TAB DELIMITER HERE, HOW TO? (and then check it's actually tab)" '{print $1}')
fi
done 10<<< "(nmcli con show | tail -n +2)"
OR TRY
nmcli con show --active
EITHER WAY
need to name the resulting vars based on the content of other vars
AND THEN
names of all plugged-in connections are safely stored in the vars
plug in all connections now
iterate thru nmcli line-by-line and compare connames with the vars
if match, leave alone
if not, takedown and rebuild to specifications for network testing
SMARTCTL
smartctl -H will report OK even if smart tests are not working
SMARTCTL NOTES
view smart info if smart is enabled and device is capable:
smartctl -i /dev/DISK
enable smart:
smartctl --smart=on /dev/DISK
view basic health report:
smartctl -H /dev/DISK
run a test:
smartctl -t short,long,conveyance /dev/DISK
get estimate on how long tests will take:
smartctl -c /dev/DISK
list all test results:
smartctl -l selftest /dev/DISK
please note that smartctl built-n foregrounding/wait-time-tracking with -C causes errors sometimes
instead use
smartctl -a /dev/DISK
to get all information about the smartctl data for that disk
and grep for the number code indicating a running test, in a while loop, to release when true
also apparently smartctl doesn't detect errors until that block has been interacted with, so running a long smartctl after badblocks is good?
badblocks with default number of passes takes about a day per terabyte of disk
bit of handy bash to list all DISKs you have attached to the machine:
lsblk -dno name,type | grep -v sr
use it with a for loop to iterate tests over every disk
also grep out any cd drives or virtual disks that you have messing things up
LVM NOTES
system-storage-manager?
cfdisk with part size
pvcreate /dev/DEV1 /dev/DEV2
pvdisplay
vgcreate VGNAME PV
vgextend VGNAME PV
vgdisplay --size -L
lvcreate #m VGNAME -n LVNAME
lvdisplay
ls /dev/mapper
mkfs -t ext4 /dev/mapper/VGNAME-LVNAME
mount /dev/mapper/VGNAME-LVNAME /MNTPOINT
pvremove /dev/DEV
pvresize --setphysicalvolumesize #m DEV
disk screwed up, don't force this
lvextend lvreduce lvresize lvremove
-r = resize fs along with lv
lvresize -l +100%free VG/LV
reformat with parted, cfdisk hangs on errors
START A SIMPLE PXEBOOT SERVER ON CENTOS 7
SERVER
tftp ROOTDIR specified in tftp config
ROOTDIR can be whatever you want, just pick a good place to store all the files
bootloader pxelinux.0, location specified in dhcp config, usually ROOTDIR/pxelinux/../BOOTLOADER
bootloader menu config autolocated, defaults to ROOTDIR/pxelinux/pxelinux.cfg/default
can make ones named after uuid mac ip of the machine or group of machines you want to pxeboot
kernel vmlinuz0, location specified in bootloader menu config, usually ROOTDIR/pxelinux/../KERNEL
initrd, kickstart, etc locations also specified in bootloader menu config
dnsmasq serves dhcp and tftp
python serves http
install/config dnsmasq
start/enable dnsmasq
restart network
mkdirs and put files in them
stop selinux from fucking things up
may also need to disable firewall
start python http server
If you want to use a separate TFTP server instead of dnsmasq, specify its IP address after the boot-loader path, for example:
dhcp-boot=pxelinux/pxelinux.0,10.0.0.11
script for
yum install dnsmasq
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
cat > /etc/dnsmasq.conf < ROOTDIR/pxelinux/pxelinux.cfg/default < default.bak
virsh net-edit default
+ # make a tftp server on this machine at ROOTDIR, goes just after the line about the ip address
+ # specify location of bootloader, goes just after range, maybe not need stuff about serverIP if the server and this server are the same machine?
virsh net-destroy default
virsh net-start default
not tested with python webserving, because the live image i wanted was transferred entirely over tftp
also did these, but dunno if they had anything to do with it working:
modprobe nf_nat_tftp
setenforce 0
you don't need dnsmasq if you do it in virsh because virsh makes its own tftp server
might be able to mess with this to get vms to pxeboot from other vms, maybe put them on separate networks?
INSTALL XFCE ON CENTOS 7 CORE
sudo yum install -y epel-release # because this stuff isn't in the default repositories
sudo yum groupinstall -y "X Window System"
sudo yum groupinstall -y xfce
sudo systemctl get-default # if multi-user.target, you need this next part
sudo systemctl set-default graphical.target
sudo systemctl isolate graphical.target
FOR EASY COPY-PASTING
sudo yum install -y epel-release && \
sudo yum groupinstall -y "X Window System" && \
sudo yum groupinstall -y xfce && \
sudo systemctl set-default graphical.target && \
sudo systemctl isolate graphical.target
CUSTOMIZE CENTOS ISO
use livecd-tools and livecd-iso-to-pxeboot with a kickstart file
""
Both of those are variables for the LiveCD environment.
$INSTALL_ROOT is for the root of the filesystem of the LiveCD that will eventually be compressed. This is where all of the packages get installed during the build process. Use this if you want the files on the LiveCD OS filesystem.
$LIVE_ROOT is the root of the CD. Use this if you want the files available without having to boot to the LiveCD or uncompressing the filesystem on the CD. For example, you would copy files to $LIVE_ROOT if you wanted to be able to put the CD in a running system and see them. As in your post above, /EFI, /isolinux, /LiveOS.
There is no variable for the root of the installed (host) system. You retain access to it by using the %post --nochroot
To start simply, you could attempt something like:
Code:
...
%post --nochroot
touch $INSTALL_ROOT/this-is-install-root
touch $LIVE_ROOT/this-is-live-root
...
""
SIMPLE CENTOS KICKSTART CONFIGURATION WITHOUT GUI FOR PXE
install
cmdline
lang en_US
keyboard us
timezone America/Phoenix
reboot
rootpw --plaintext caiser
user --name=caiser --plaintext --password=caiser
part / --size 4096 --fstype ext4
selinux --disabled
firewall --disabled
services --enabled=NetworkManager,sshd
network --bootproto=dhcp --device=link --activate
repo --name=base --baseurl=http://mirror.cogentco.com/pub/linux/centos/7/os/x86_64/
skipx
%packages --nobase --ignoremissing
@core
tree
wget
%end
try without?: url --url="http://mirror.cogentco.com/pub/linux/centos/7/os/x86_64/"
makes a real pretty error if you try to give the pxeboot environment an iso instead of a kernel or initrd
SIMPLE CENTOS KICKSTART CONFIGURATION WITH GUI
eula --agreed
firstboot --disabled
KICKSTART MAKE PASSWORD ENCCRYPTED HOWTO
###########
# MAKE A RHEL7 PXEBOOT SERVER!
# ADAPTED FROM http://www.tecmint.com/install-pxe-network-boot-server-in-centos-7/
# SERVER MUST FIRST BE CONF'D WITH A STATIC IP ADDRESS IN SAME NETSEGMENT AS PXE CLIENTS
yum install -y dnsmasq
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
wget -O /etc/dnsmasq.conf caiser.net/classes/ap/serv_dnsmasq.txt
yum install -y syslinux
yum install -y tftp-server
cp -r /usr/share/syslinux/* /var/lib/tftpboot
mkdir /var/lib/tftpboot/pxelinux.cfg
touch /var/lib/tftpboot/pxelinux.cfg/default
wget -O /var/lib/tftpboot/pxelinux.cfg/default caiser.net/classes/ap/serv_tftpdef.txt
scp student@172.16.49.1:/home/student/Desktop/ISOs/CentOS-7-x86_64-DVD-1511.iso centos7.iso
mount -o loop /root/centos7.iso /mnt
# to check mount: ls /mnt
mkdir /var/lib/tftpboot/centos7
cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7
cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/centos7
yum install -y vsftpd
cp -r /mnt/* /var/ftp/pub
chmod -R 755 /var/ftp/pub
systemctl start dnsmasq
systemctl status dnsmasq
systemctl start vsftpd
systemctl status vsftpd
systemctl enable dnsmasq
systemctl enable vsftpd
netstat -tulpn
firewall-cmd --add-service=ftp --permanent # port 21
firewall-cmd --add-service=dns --permanent # port 53
firewall-cmd --add-service=dhcp --permanent # port 67
firewall-cmd --add-port=69/udp --permanent # port for TFTP
firewall-cmd --add-port=4011/udp --permanent # port for ProxyDHCP
firewall-cmd --reload # apply rules
# check ftp server on different pc: ftp://172.16.49.201/pub