Gentoo – James Batchelor https://james-batchelor.com Useful I.T & VoIP Ramblings Wed, 18 Oct 2023 10:31:51 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.5 https://james-batchelor.com/wp-content/uploads/2025/05/cropped-cropped-logo-jb-202505-32x32.png Gentoo – James Batchelor https://james-batchelor.com 32 32 Manually install net-snmpd on Gentoo https://james-batchelor.com/index.php/2023/10/18/manually-install-net-snmpd-on-gentoo/ Wed, 18 Oct 2023 18:25:00 +0000 https://james-batchelor.com/?p=895 Continue reading "Manually install net-snmpd on Gentoo"]]> Recently we’ve moved from an aged Opsview instance to Zabbix for our system health monitoring, which in turn facilitated moving data collector agents from Nagios to snmp.

Many of our PBX’s were deployed from the vendors ISO and so run atop of Gentoo, and it has a couple of issues:

  1. We’ve been told not to “emerge” anything by the vendor, as the base OS on the image is not maintained.
  2. Portage (Gentoo’s package manager) has fallen out of date, meaning even if emerge is attempted, it’ll fail as all repository links are broke.

If faced with the same issue, this is how to install net-snmpd from source, add it a startup service and be able to monitor via snmp…

Installation

On the Gentoo box, move to your home directory

cd ~

Download the source .tar.gz file

wget https://sourceforge.net/projects/net-snmp/files/net-snmp/5.9.4/net-snmp-5.9.4.tar.gz

Visit http://www.net-snmp.org/download.html for the latest version. When I was downloading SourceForge’s SSL cert had expired, if this happens add –no-check-certificate after wget in the command above.

Untar the file to your home directory, and change into it

tar -xzvf net-snmp-5.9.4.tar.gz
cd net-snmp-5.9.4

Run the configuration script

./configure

This allows you to set snmp version, file installation locations and snmp details, with exception of snmp version these can be left as default (Hit enter at the prompt). snmp details will look like this if left default…

Compile and install snmpd

make
make install

The make process is quite CPU intensive, may want to do this during a quiet period for the server.

Some libraries are not where they need to be, namely:
libnetsnmpagent.so.40
libnetsnmpmibs.so.40
libnetsnmp.so.40

Find where they were installed

find / -name libnetsnmpagent.so.40

Pick the result that is not in your current working folder (the install setup) and link it to /usr/lib

ln -s /usr/local/lib64/libnetsnmpagent.so.40 /usr/lib/

Repeat this process with the other two files

ln -s /usr/local/lib64/libnetsnmpmibs.so.40 /usr/lib/
ln -s /usr/local/lib64/libnetsnmp.so.40 /usr/lib/

Now can test to see if snmpd can run

snmpd -v

Configuration

Create a configuration file, the “snmpconf” command can be used but I found it easier to create from scratch

nano /usr/local/share/snmp/snmpd.conf

For my needs, only this line is needed

rocommunity {community} {ip address}

Save and exit the editor.

Testing

If you’d like to test your configuration, run snmpd

snmpd

Test on the snmp target machine, for quick results snmpwalk can be run

snmpwalk -c {community} -v 2c {ip address}

When run, snmpd automatically switches to a background process. To stop the process ID needs to be found and killed

ps aux | grep snmpd

Here the process ID (PID) is 5716, use this with the kill command

kill -9 {PID}

Add Service

Create the new service file

nano /etc/init.d/snmpd

Paste the following

#!/sbin/openrc-run
 
depend() {
    after modules
}
 
start() {
    ebegin "Starting snmpd"
    start-stop-daemon --background --start --exec /usr/local/sbin/snmpd --pidfile /var/run/snmpd.pid \
    -- -p /var/run/snmpd.pid -c /usr/local/share/snmp/snmpd.conf
    eend $?
}
 
stop() {
    ebegin "Stopping snmpd"
    start-stop-daemon --stop --exec /usr/local/sbin/snmpd \
    --pidfile /var/run/snmpd.pid
    eend $?
}
restart() {
    ebegin "Restarting snmpd"
    start-stop-daemon --stop --exec /usr/local/sbin/snmpd
    start-stop-daemon --background --start --exec /usr/local/sbin/snmpd --pidfile /var/run/snmpd.pid \
    -- -p /var/run/snmpd.pid -c /usr/local/share/snmp/snmpd.conf
    eend $?
}

Save and exit the text editor, then make the file executable

chmod +x /etc/init.d/snmpd

Start the service, and check its running

/etc/init.d/snmpd start

/etc/init.d/snmpd status

Finally, to make snmpd start with the system, run

rc-update add snmpd default

References

Help Creating init.d file

https://big-elephants.com/2013-01/writing-your-own-init-scripts/
https://tecadmin.net/startup-shutdown-script-on-gentoo/

Experienced issue where the process-id in the PID file was not matching the PID of process. With help of below found flag for snmpd to specify PID file, and match that to init.d

https://forums.gentoo.org/viewtopic-t-886230-start-0.html

]]>
Increase disk size on Gentoo VM Instance https://james-batchelor.com/index.php/2022/01/18/increase-disk-size-on-gentoo-vm-instance/ Tue, 18 Jan 2022 14:44:56 +0000 https://james-batchelor.com/?p=774 Continue reading "Increase disk size on Gentoo VM Instance"]]> There are occasions when the storage capacity of a virtual drive needs to be increased. In production environments a backup and re-install of an OS to a higher capacity provision may not be practical.

Many of our systems deployed from OVA’s use Gentoo as it’s base OS for inexplicable reasons, here’s how to increase the drive capacity of a VM instance running Gentoo and make the extra space usable…

Prework

SSH into the machine and identify the volume to benefit from the increase by entering

df -h

In this scenario the /home mount point requires the extra space, this is served by the /dev/sda4 Filesystem.

Now discover which disk this is on and where it sits in the layout of the disk (partition):

fdisk -l

The virtual disk is detailed towards the end of the output, and is identified with sda, multiple disks will be lableled sdb, sdc etc.

Along with the partition table at the end:

/dev/sda4 is located towards the end of the disk as denoted by the start and end sectors, so will be able to increase the disk by adding extra storage onto what is effectively the end of the drive.

Increase Drive Capacity.

Shut down the VM.

At the hypervisor, edit the configuration of the VM and enter a new capacity.

IM

Note: In VMware, Snapshots or Replications need to be removed in order to change the drive capacity.

Start up the VM, restore any Replications (and wait for initial sync to complete)

Highly recommended to take a snapshot at this point.

Reconfigure Partitions

SSH back into the machine, fdisk -l can be used again to sanity check that the drive now has increased capacity:

Now to assign this extra capacity to the volume, edit the disk partitions by entering:

fdisk /dev/sda

To refresh yourself on the current partition layout, enter p command to view, it also helps to have this on screen for the next steps…

As mentioned, here the goal is to increase /dev/sda4. To achieve this we need to remove this partition then re-add it to overlay the current structure but including the extra space. Sounds scary, but these changes aren’t in place until we commit the changes later. Nevertheless a good time to check the recent snapshot has completed.

Delete the current partition using command “d”, then entering partition number:

Again, can you the “p command to check its gone.

Now create the new partition with the “n” command.

Prompted for the first sector, enter the same value recorded on the original partition

The last sector, enter the default value shown, this should be greater than the original partition as there’s more storage available.

Output will advise that partition is made, then ask if you want to remove the signature. Enter NO to keep it, as we want to keep the original partition intact.

Finally, enter “w” command to write and commit the changes.

Reboot the VM.

Assign new space.

On restart, using fdisk -l will confirm the partition is bigger:

However, df -h will not have increased:

To use the extra space, we need to tell Gentoo that its available to use by entering:

resize2fs /dev/sda4

Output should look like this:

Now df -h will reflect the extra space and is ready to use:

]]>