ubuntu boot from particular kernel version

If kernel version to boot from Linux 4.15.0-32-generic
Get menuentries

root@Ubuntu9-141:~# grep -A100 submenu  /boot/grub/grub.cfg |grep menuentry
submenu 'Advanced options for Ubuntu GNU/Linux' $menuentry_id_option 'gnulinux-advanced-b56fcaaa00cf79aa' {
menuentry 'Ubuntu GNU/Linux, with Linux 4.15.0-54-generic' --class Ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-54-generic-advanced-b56fcaaa00cf79aa' {
menuentry 'Ubuntu GNU/Linux, with Linux 4.15.0-54-generic (recovery mode)' --class Ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-54-generic-recovery-b56fcaaa00cf79aa' {
menuentry 'Ubuntu GNU/Linux, with Linux 4.15.0-50-generic' --class Ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-50-generic-advanced-b56fcaaa00cf79aa' {
menuentry 'Ubuntu GNU/Linux, with Linux 4.15.0-50-generic (recovery mode)' --class Ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-50-generic-recovery-b56fcaaa00cf79aa' {
menuentry 'Ubuntu GNU/Linux, with Linux 4.15.0-32-generic' --class Ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-32-generic-advanced-b56fcaaa00cf79aa' {
menuentry 'Ubuntu GNU/Linux, with Linux 4.15.0-32-generic (recovery mode)' --class Ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-32-generic-recovery-b56fcaaa00cf79aa' {



Edit /etc/default/grub

GRUB_DEFAULT='gnulinux-advanced-b56fcaaa00cf79aa>gnulinux-4.15.0-32-generic-advanced-b56fcaaa00cf79aa'


Update grub

root@Ubuntu9-141:~# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-59-generic
Found initrd image: /boot/initrd.img-4.4.0-59-generic
Found linux image: /boot/vmlinuz-3.19.0-73-generic
Found initrd image: /boot/initrd.img-3.19.0-73-generic
Found linux image: /boot/vmlinuz-3.19.0-43-generic
Found initrd image: /boot/initrd.img-3.19.0-43-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
...........

reboot to verify





Time Synchronization with NTP and systemd

I recently ran into problems with generating TOTP 2-factor codes on my laptop. The fact that some of the codes would work and some wouldn't suggested a problem with time keeping on my laptop.
This was surprising since I've been running NTP for a many years and have therefore never had to think about time synchronization. After realizing that ntpd had stopped working on my machine for some reason, I found that systemd provides an easier way to keep time synchronized.

The new systemd time synchronization daemon

On a machine running systemd, there is no need to run the full-fledged ntpd daemon anymore. The built-in systemd-timesyncd can do the basic time synchronization job just fine.
However, I noticed that the daemon wasn't actually running:
$ systemctl status systemd-timesyncd.service 
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
           └─disable-with-time-daemon.conf
   Active: inactive (dead)
Condition: start condition failed at Thu 2017-08-03 21:48:13 PDT; 1 day 20h ago
     Docs: man:systemd-timesyncd.service(8)
referring instead to a mysterious "failed condition". Attempting to restart the service did provide more details though:
$ systemctl restart systemd-timesyncd.service 
$ systemctl status systemd-timesyncd.service 
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
           └─disable-with-time-daemon.conf
   Active: inactive (dead)
Condition: start condition failed at Sat 2017-08-05 18:19:12 PDT; 1s ago
           └─ ConditionFileIsExecutable=!/usr/sbin/ntpd was not met
     Docs: man:systemd-timesyncd.service(8)
The above check for the presence of /usr/sbin/ntpd points to a conflict between ntpd and systemd-timesyncd. The solution of course is to remove the former before enabling the latter:
apt purge ntp

Enabling time synchronization with NTP

Once the ntp package has been removed, it is time to enable NTP support in timesyncd.
Start by choosing the NTP server pool nearest you and put it in /etc/systemd/timesyncd.conf. For example, mine reads like this:
[Time]
NTP=time.cloudflare.com
before restarting the daemon:
systemctl restart systemd-timesyncd.service 
That may not be enough on your machine though. To check whether or not the time has been synchronized with NTP servers, run the following:
$ timedatectl status
...
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no
If NTP is not enabled, then you can enable it by running this command:
timedatectl set-ntp true
Once that's done, everything should be in place and time should be kept correctly:
$ timedatectl status
...
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

move /boot on zfs on root to ext4

# modprobe zfs
# zpool import -a -N -R /mnt
Mount the root pool into /mnt

# zfs mount LP_Pool/ROOT/lp_root
mount -t proc /proc /mnt/proc
mount --rbind /dev /mnt/dev
mount --rbind /sys /mnt/sys

chroot /mnt /bin/bash --login
export ZPOOL_VDEV_NAME_PATH=YES
grub-probe /

sgdisk -p /dev/sdx
#creating
sgdisk -n 1:2048:4095 -c 1:"BIOS Boot Partition" -t 1:ef02 /dev/sdx

#below command will create new partition number "2" of size 3219MB 
sgdisk -n 2:4096:6291456 -c 2:"Linux /boot" -t 2:8300 /dev/sdx

# For  1605 MB
#sgdisk -n 2:4096:3291456 -c 2:"Linux /boot" -t 2:8300 /dev/sdx

mkfs.ext4 /dev/sdx2 and mount it on /newboot

mount -t ext4 /boot/ /newboot/
copy /boot/* to /newboot
rename /newboot to /boot

get UUID of /dev/sdx2 and append to fstab as below:-

UUID=1b1d424c-9fd1-4fd2-aba7-80252f1a8d64 /boot           ext4    defaults        0       2

grub-install /dev/sdx
update-grub2
grub-mkdevicemap
update-initramfs -u -k all

exit from chroot
# zfs unmount -a
# zfs set mountpoint=/ LP_Pool/ROOT/lp_root
# reboot

https://www.rodsbooks.com/gdisk/sgdisk-walkthrough.html

https://pve.proxmox.com/wiki/ZFS:_Tips_and_Tricks

Boot fails and goes into busybox

If booting fails with something like
No pool imported. Manually import the root pool
at the command prompt and then exit.
Hint: try: zpool import -R /rpool -N rpool
is because zfs is invoked too soon (it has happen sometime when connecting a SSD for future ZIL configuration). To prevent it there have been some suggestions in the forum. Try to boot following the suggestions of busybox or searching the forum, and try ONE of the following:
a) edit /etc/default/grub and add "rootdelay=10" at GRUB_CMDLINE_LINUX_DEFAULT (i.e. GRUB_CMDLINE_LINUX_DEFAULT="rootdelay=10 quiet") and then issue a # update-grub
b) edit /etc/default/zfs, set ZFS_INITRD_PRE_MOUNTROOT_SLEEP='4', and then issue a "update-initramfs -k 4.2.6-1-pve -u"


nxlog iis

Panic Soft
### Start off with Definitions ###
define ROOT C:\Program Files (x86)\nxlog
define CERTDIR %ROOT%\cert
define CONFDIR %ROOT%\conf
define LOGDIR %ROOT%\data
define LOGFILE %LOGDIR%\nxlog.log
LOGFILE %LOGDIR%\nxlog.log

Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
LogLevel INFO
#PersistLogqueue TRUE
#SyncLogqueue TRUE
#CacheFlushInterval always
#CacheSync TRUE

<Extension _syslog>
Module xm_syslog
</Extension>

<Extension xml>
Module xm_xml
</Extension>

<Extension _exec>
Module xm_exec
</Extension>

<Extension _json>
Module xm_json
</Extension>

<Extension w3c>
Module xm_csv
Fields $date, $time, $s-ip, $cs-method, $cs-uri-stem, $cs-uri-query, $s-port, $cs-username, $c-ip, $cs(User-Agent), $sc-status, $sc-substatus, $sc-win32-status, $time-taken
FieldTypes string, string, string, string, string, string, integer, string, string, string, integer, integer, integer,integer
Delimiter ' '
QuoteChar '"'
EscapeControl FALSE
UndefValue -
</Extension>

<Extension _fileop>
Module xm_fileop

# Check the size of our log file every hour and rotate if it is larger than 5Mb
<Schedule>
Every 1 hour
Exec if (file_exists('%LOGFILE%') and (file_size('%LOGFILE%') >= 5M)) file_cycle('%LOGFILE%', 8);
</Schedule>
</Extension>



### Get IIS Exchange logs ###

<Input IIS_log>
Module im_file
File "D:\\Inetlogs\\W3SVC1\\\\u_ex*.log"
InputType LineBased
SavePos TRUE
#Drop info legend lines
Exec if $raw_event =~ /^\#/ drop();\
else\
{\
w3c->parse_csv();\
$EventTime = parsedate($date + " " +$time);\
$date = strftime($EventTime, "%Y-%m-%d");\
}
Exec $Message = $raw_event;\
#Exec $date = strftime($EventTime, "'%Y-%m-%d"); $time = strftime($EventTime, "%H:%M:%S");
</Input>


### Define the output that goes to SIEM for analysis ###

<Output logcontents1>
Module om_tcp
Host SIEM_IP
Port 514
Exec $Hostname = hostname_fqdn();
Exec to_json();
</Output>

### Tie together inputs to outputs ###

<Route r_lp2>
Path IIS_log => logcontents1
</Route>

------------------------------------------------
To pull windows event log All you need to do is add the log name into the query list.

Query <QueryList>\
<Query Id="0">\
<Select Path="Application">*</Select>\
<Select Path="System">*</Select>\
<Select Path="Security">*</Select>\
<Select Path="DNS Server">*</Select>\
<Select Path="Directory Service">*</Select>\
<Select Path="DFS Replication">*</Select>\
<Select Path="Active Directory Web Services">*</Select>\
</Query>\
</QueryList>
To find the name of the log you want to add the easiest way is to

open event viewer

select custom view

select the event logs you want from the dropdown

switch to the XML tab

It will have a very similar look but you have to make it look exactly like my code above. Note the backslash at the end.



rsync through jumphost handy command

rsync -azvP -e 'ssh -A -J user1@10.99.1.50:22'  user1@192.168.20.163:/opt/backup/configuration/zipped/configuration_2020-03-19-07-47-44.backup  /path/local/

macos spotlight indexing problem

Intermittent stopping of spotlight on macos mojave 2020/03/26

urgens-MacBook-Pro:~ urgensherpa$ sudo mdutil -a -i off
/:
2020-03-26 12:40:18.654 mdutil[750:14995] mdutil disabling Spotlight: / -> kMDConfigSearchLevelFSSearchOnly
Indexing disabled.

urgens-MacBook-Pro:~ urgensherpa$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
/System/Library/LaunchDaemons/com.apple.metadata.mds.plist: Operation not permitted while System Integrity Protection is engaged

urgens-MacBook-Pro:~ urgensherpa$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

/System/Library/LaunchDaemons/com.apple.metadata.mds.plist: service already loaded

urgens-MacBook-Pro:~ urgensherpa$ sudo mdutil -a -i on
/:
Indexing enabled. 

ZFS: Performance Tuning for Scrubs and Resilvers

Jason Matthews


My environment is write heavy. I have hundreds of millions of phones sending me events continously. They are like billions and billions of star like bubbles invading my spinning rust.
Consequently, when a disk fails or takes on excessive CRC errors a resilver job is kicked off. Similarly, I scrub the storage pools monthly and occasionally turn up a bad disk that is silently corrupting. The problem is the resilver or scrub job reports that it needs two or three months to complete, with the default settings. That doesn’t work for me. If you are reading this, you might have a similar problem.
I would prefer to throttle the inbound data and repair the system to optimal data redundancy. Around here, data integrity is everything. To complete the scrubs and resilvers quickly, I have had to tweak ZFS in an Evil way. First, we’ll talk about what to put into /etc/system, then I will show you how to make these changes take effect immediately.
The /etc/system changes are straight forward:

* Prioritize resilvering by setting the delay to zero
set zfs:zfs_resilver_delay = 0
* Prioritize scrubs by setting the delay to zero
set zfs:zfs_scrub_delay = 0
* set maximum number of inflight IOs to a reasonable value - this number will vary for your environment
set zfs:zfs_top_maxinflight = 128
* resilver for five seconds per TXG
set zfs:zfs_resilver_min_time_ms = 5000

The default value here is three seconds. By giving resilver five seconds per transaction group we can rebuild the mirror more quickly.
Now, to make these changes take effect immediately so you dont have to reboot, you can execute the following:

echo zfs_resilver_delay/w0 | mdb -kw
echo zfs_scrub_delay/w0 |mdb -kw
echo zfs_top_maxinflight/w7f |mdb -kw
echo zfs_resilver_min_time_ms/w1388 |mdb -kw
These variables and more can be found in dsl_scan.c
These modifications speed up my scrub/resilver operations from taking a approximately two months, to approximately two to three hours depending on the individual system.

zfs move boot to ext4

move boot to ext4
  1. Create your ext partition
  2. Mount it somewhere temporarily
  3. rsync -avPX /boot/. /<tempboot>/.
  4. unmount /<tempboot>
  5. Move /boot to another location on zfs (eg. /bootbackup)
  6. Recreate /boot mountpoint and mount your new partition there
  7. Add the new boot ext4 partition to /etc/fstab
UUID=1b1d424c-9fd1-4fd2-aba7-80252f1a8d64 /boot           ext2    defaults        0       2
  1. Re-run update-grub (maybe even update-initramfs for good measure)
  2. reboot
 The /bootbackup allows you to a location to periodically rsync your /boot ext4 into the pool for recovery purposes.

after reboot you might have to manually select the second partition as boot device
#############
# zpool import -a -N -R /mnt
Mount the root pool into /mnt
# zfs mount LP_Pool/ROOT/lp_root
mount -t proc /proc /mnt/proc
mount --rbind /dev /mnt/dev
mount --rbind /sys /mnt/sys
chroot /mnt /bin/bash --login

sgdisk -p /dev/sdx
#creating 
sgdisk -n 1:2048:4095 -c 1:"BIOS Boot Partition" -t 1:ef02 /dev/sdx
#below command will create new partition number "2" of size 3219MB 
sgdisk -n 2:4096:6291456 -c 2:"Linux /boot" -t 2:8300 /dev/sdx 

mkfs.ext4 /dev/sdx2 and mount it on /newboot
copy /boot/* to /newboot
rename /newboot to /boot

get UUID of /dev/sdx2 and change fstab as below:-

UUID=1b1d424c-9fd1-4fd2-aba7-80252f1a8d64 /boot           ext4    defaults        0       2

grub-install /dev/sdx
update-grub2
grub-mkdevicemap
update-initramfs -u -k all

exit from chroot

# zfs unmount -a
# zfs set mountpoint=/ LP_Pool/ROOT/lp_root
# reboot












############

UPDATE (2020-01-27): The SuperMicro X10SRH-CLN4F motherboard boots just fine from a root-on-ZFS disk in UEFI mode from the built-in SAS HBA. The only required change is the last step in the description below; to add a delay before attempting to mount ZFS volumes at boot-time.
There is a potential drawback to installing Proxmox in root-on-ZFS mode in a UEFI system: The drive gets partitioned, so ZFS doesn’t get uninhibited access to the entire block storage. This may or may not make a difference for performance, but in terms of speed on an SSD solution, I haven’t really seen any cause for concern for my real-world use case. An alternative would be to install the underlying operating system to a separate physical drive.
Also note that the workaround below works on a single vFAT volume. Since FAT doesn’t support symlinks, kernel or initramfs updates in Proxmox/Debian will require some manual work, which most sane people would likely wish to avoid.
I’m leaving the rest of my article intact for posterity:

My workaround was to place /boot – not the system – on a USB stick connected directly to the motherboard.

Process

After installation, reboot with the Proxmox installation medium, but select Install Proxmox VE (Debug mode).
When the first shell appears, Ctrl+D to have the system load the necessary drivers.
Check the name of the USB drive.
lsblk
Partition it.
cfdisk /dev/sdb
Clear the disk, create an EFI System partition and write the changes. Then apply a FAT to the new partition
mkfs.vfat /dev/sdb1
Prepare to chroot into the installed Proxmox instance
mkdir /media/rescue
zpool import -fR /media/rescue rpool
mount -o bind /dev /media/rescue/dev
mount -o bind /sys /media/rescue/sys
mount -o bind /dev /media/rescue/dev
chroot /media/rescue
Make room for the new /boot
mv /boot /boot.bak
Edit /etc/fstab and add the following:
/dev/sdb1 /boot vfat defaults 0 0
Make the stick bootable
mount -a
grub-install --efi-directory=/boot/efi /dev/sdb
update-grub
grub-mkconfig -o /boot/grub/grub.cfg
Exit the chroot, unmount the ZFS file system (zfs export rpool)and reboot
In my specific case I had a problem where I got stuck in a shell with the ZFS pool not mountable.
/sbin/zpool import -Nf rpool
Exit to continue the boot process. Then edit /etc/default/zfs and edit a delay before attempting to boot the file system.
ZFS_INITRD_PRE_MOUNTROOT_SLEEP=15
Then apply the new configuration:
update-initramfs -u

snmp customization

1. Bash Scripts

Preparing to extend snmp – prepare the scripts you would like to run, move it to desired folder and make sure they are executable by “root” user. I think it is hygienical to create a new folder called “scripts” in “/etc/snmp” and put these scripts there. If you disagree, you can put it anywhere else on the system too, as long as “root” user will be able to access them.

2. Edit snmpd.conf

To extend snmp we need to edit “/etc/snmp/snmpd.conf” configuration file and add the extend configuration parameters that point to bash scripts. For this example purpose i will extend SNMP by two bash scripts, you can add more or less of course.
# Extend SNMP
extend script1 /etc/snmp/scripts/script1.sh
extend script2 /etc/snmp/scripts/script2.sh

3. Restart SNMPD Service

To apply configuration changes we need to restart “snmpd” service by running the following command:
[mitch@node01 ~]$ sudo service snmpd restart
 Stopping snmpd: [ OK ]
 Starting snmpd: [ OK ]

4. Test it out

After we’ve restarted SNMPD service we can proceed to run tests by manually triggering the scripts via “snmpget” command, where:
  • “v2c” tells it to use Simple Network Management Protocol Version 2
  • “geekpeek” is the configured community name (default is “public”) you can see in snmpd.conf file
  • “localhost” is the host we are connecting to
  • “script1” is the human readable name of the extended SNMP
  • “STRING: X” tells us the output of the bash script which is X
[mitch@node01 ~]$ snmpget -v2c -c geekpeek localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."script1".1'
NET-SNMP-EXTEND-MIB::nsExtendOutLine."script1".1 = STRING: 1
[mitch@node01 ~]$ snmpget -v2c -c geekpeek localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."script2".1'
NET-SNMP-EXTEND-MIB::nsExtendOutLine."script2".1 = STRING: 2
As we can see the “script1” output is “1” and the “script2” output is “2”, which in my case is ok and i confirmed normal operation of SNMP.

5. Get the OID

There’s one more thing missing, to make this useful. To wrap things up we need to get the OID of these extended scripts and we can use this OID to make monitoring checks. To get the OIDs we need to run the “snmptranslate” command as you see below:
[mitch@node01 ~]$ snmptranslate -On 'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."script1".1'
.1.3.6.1.4.1.8072.1.3.2.3.1.1.11.109.111.110.95.115.101.110.100.101.114.115
[mitch@node01 ~]$ snmptranslate -On 'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."script2".1'
.1.3.6.1.4.1.8072.1.3.2.3.1.1.14.100.99.115.95.112.111.115.110.95.100.101.108.97.121
Voila and we got the OIDs we can call via SNMP. What we get is the output of the scripts configured in snmpd.conf file. Told you it’s really easy to extend snmp.

snmp disk monitor

Disk Statistics
Regarding disk statistics one of method is to modify snmpd.conf file (append below contents). Please note that there are some limitations on certain oid/objects like dskTotal, diskAvail (more info here).

#includeAllDisks 10%
disk / 10%
disk /opt 10%
disk /opt/makalu/storage 10%
# where 10% is threshold,it is set when 10% threshold is reached and reachable with UCD-SNMP-MIB::dskErrorFlag.<number>. it defaults to 100kB

List out mountpoints/path
# snmpwalk -v2c -c public localhost UCD-SNMP-MIB::dskPath
UCD-SNMP-MIB::dskPath.1 = STRING: /
UCD-SNMP-MIB::dskPath.2 = STRING: /opt
UCD-SNMP-MIB::dskPath.3 = STRING: /opt/makalu/storage

~# snmpwalk -v2c -c public localhost UCD-SNMP-MIB::dskPercent.3
UCD-SNMP-MIB::dskPercent.3 = INTEGER: 4

~# snmpwalk -v2c -c public localhost UCD-SNMP-MIB::dskDevice.3
UCD-SNMP-MIB::dskDevice.3 = STRING: MainPool/storage

root@myserver:~# df -hT
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.5G 0 1.5G 0% /dev
MainPool/ROOT/root zfs 47G 3.6G 43G 8% /
...
MainPool/application zfs 47G 3.4G 44G 8% /opt
...
MainPool/storage zfs 28G 1.1G 27G 4% /opt/data/storage
...

Note:- The percentage value usage is rounded off to ceiling value