Resize Linux Partition


Reduce the size of a partition containing an volume

  • BE SURE TO MAKE A BACKUP
  • Either resizing or moving the physical partition may cause the raid superblock to be lost

  • Check the filesystem on mdadm raid volume
          e2fsck -f /dev/md0
          
  • Reduce the filesystem on mdadm raid volume (change volume and reduced size)
          resize2fs /dev/md0 120G
          
  • Resize the mdadm raid volume (use a size slightly larger than the filesystem)
  •       mdadm --grow /dev/md0 --size=122G
          
  • Check the filesystem on mdadm raid volume
          e2fsck -f /dev/md0
          
  • Stop the raid device
  •       mdadm /dev/md0 --stop
          
  • Resize the physical partition (use GParted to do that)
  • You may need to boot from a Live CD to do this – to use parted, you may not have to reboot to a live image
    You can also use the parted command line tool as follows:

            # apt install parted
            parted /dev/sda
            (parted) print
    
            # IMPORTANT: The END is NOT the new size - you have to add sizes of partitions before it
            (parted) resizepart
            Partition number? # Select partition number to resize
            End [10G]?        # Enter the new end of partition in bytes (remember to add sizes of partitions before it)
                              # Also, double check in GParted to make sure the size is what you expect it to be, since
                              # the parted size does not correspond to GParted size
    
            # The short sintax is (assuming partition number is 2 and you need it to resize to 125G):
            (parted) resizepart 2 125G
    
            # To continue to the next drive, use select
            (parted) select /dev/sdb
          
  • https://www.tecmint.com/parted-command-to-create-resize-rescue-linux-disk-partitions/
  • Start the raid device
  •         mdadm --examine --scan
            mdadm --assemble --scan
            #mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1
          

    In case of a raid 1 device not starting up, you might mount one of the raid partitions as a standard partition, then
    create a new raid one drive using the second partition. If that works, you can sync from the standard device to the
    new raid device and afterwords add the second partition to the raid, which will cause the raid to recover.

            # Assume /dev/sda3 and /dev/sdb3 was devices of the raid 1 array that is now broken
            mkdir /mnt/sdb3
            mount /dev/sdb3 /mnt/sdb3  # Assuming sdb3 was a raid 1 device and filesystem is still in tact.
            mdadm --create --verbose --force /dev/md1 --level=mirror --raid-devices=1 /dev/sda3
            rsync -avz /mnt/sdb3/* /mnt/md0/
            mdadm --manage /dev/md0 --add /dev/sda3
            cat /proc/mdstat
          

References


Postgres


To list installed server libraries, execute the following SQL: show shared_preload_libraries. To configure
libraries to be preloaded, edit postgres.conf. On an Ubuntu apt installation, it would typically be found in
/etc/postgresql/9.0/main.

To see the default dynamic library search path, execute the following SQL: show dynamic_library_path

$libdir is configured during compile time. On an Ubuntu installation which is done using an Ubuntu package,
$libdir will typically point to /usr/lib/postgresql/9.0/lib. Plug-in library files should typically
be put in /usr/lib/postgresql/9.0/lib/plugins on an Ubuntu system.

To automatically create objects when a new database is created, create the objects in template1. (template0 is
barebone template from which template1 is created)

To install the PL/PGSQL debugger in an Ubuntu postgres server which has been installed using apt, you might want to do
a one-click install from Enterprise DB on a Linux VM
(see Enterprise DB downloads) and do the following:
Copy /opt/PostgreSQL/9.0/lib/postgresql/plugins/plugin_debugger.so to $libdir/plugins on the Ubuntu installation.
Copy /opt/PostgreSQL/9.0/lib/postgresql/pldbgapi.so to $libdir on the Ubuntu installation.
Copy /opt/PostgreSQL/9.0/lib/postgresql/targetinfo.so to $libdir on the Ubuntu installation.
Copy /opt/PostgreSQL/9.0/share/postgresql/contrib/pldbgapi.sql to /usr/share/postgresql/9.0/contrib. on the Ubuntu installation.
Now edit postgres.conf and change the following setting:
shared_preload_libraries = ‘$libdir/plugins/plugin_debugger.so’
Now restart the postgres server and apply
You can also download the latest version of edb-debugger from
PgFoundry
and compile it to get plugin_debugger.so and pldbgapi.sql.


MikroTik WiFi CAP Configuration


MikroTik WiFi CAP Configuration

  • Terminology
    • CAP device is the abbreviation for Controlled Access Point
    • CAPsMAN is the CAP manager and has an enabled CAPsMAN service
    • WinBox is a desktop application for managing Mikrotik devices
    • WinBox can be installed on Linux as a snap package and is probably
      the easiest way to connect to a Mikrotik device, since it uses Layer 2 network
      communication and therefore does not require an IP address in the LAN subnet.

  • MikroTik device
  • When MikroTik device is first powered up, the default IP address is
    192.168.88.1, admin password is empty and the SSID
    is Mikrotik. If LAN subnet is different, the easiest way
    to change configuration is to connect via WiFi to open the web
    configuration at 192.168.88.1.

    • Select Quick Set (top right) and select CAP in combobox just below
    • Configure network address
    • Choose MikroTikCAPsMAN as router identity
    • Select Bridge All LAN Ports as router identity

    Use UP arrow to revert back to default in options to follow when setting up a configuration
    or device settings which refers to some other configuration.

  • CAPsMAN manager device
    • Select WebFig (top right) and select CAPsMAN (left top)
    • Under CAP Interface tab, press Manager and select Enable and choose
      • Select Enabled
      • Choose require same version under Upgrade Policy
      • Press OK
    • Under Channels tab press Add New
      • Set Name to channel1
      • Set Frequency to 2412
      • Set Control Channel Width to 20MHz
      • Set Band to 2ghz-g/n
      • Press OK
      • Add another channel called channel6 with Frequency as 2442
      • (other properties remain the same)

      • Add another channel called channel11 with Frequency as 2472
      • (other properties remain the same)

    • Under Datapaths tab press Add New
      • Set Name to datapath1
      • Set Bridge to bridgeLocal (or whatever the default bridge is)
      • Select Local Forwarding (traffic handled by each CAP and not by CAPsMAN)
      • Select Client To Client Forwarding (allow WiFi clients to see each other)
      • Press OK
    • Under Security Cfg. tab press Add New
      • Set Name to secure
      • Select WPA PSK2 in Authentication Type
      • Select aes ccm in Encryption
      • Set Passphrase to your WiFi password
      • Select Local Forwarding (traffic handled by each CAP and not by CAPsMAN)
      • Select Client To Client Forwarding (allow WiFi clients to see each other)
      • Press OK
    • Under Configuration tab press Add New
      • Select Enabled
      • Set Name to cfg1
      • Choose none as Master Interface
      • Choose ap in Mode
      • Enter SSID
      • Choose Country
      • Choose indoor in Installation
      • Choose datapath1 in Datapath (see Datapath configuration)
      • Select secure in Security (see Security Cfg. configuration)
      • Press OK
    • Under Provisioning tab press Add New
      • Select Enabled
      • Set Action as create dynamic enabled
      • Set Master Configuration (see Configuration definition)
      • Set Name Format as cap
      • Set Name Prefix to some value
      • Press OK
    • Select Wireless menu item on the left and select WiFi Interfaces tab
      • Press CAP button
        • Select Enabled
        • Select wlan1 in Interfaces
        • Select none in Certificate
        • Select ether1 in Discovery interface
        • Select none in Bridge
        • Press OK
      • Set Action as create dynamic enabled
      • Set Master Configuration (see Configuration definition)
      • Set Name Format as cap
      • Set Name Prefix to some value
      • Press OK
    • Select CAPsMAN menu item on the left and select CAP Interfaces tab
      • Press Add New button
      • Set Name to cap1
      • Set Channel to channel1
      • Press OK

  • CAP device (controlled by CAPsMAN)
  • The easiest way to configure a CAP device is by connecting via WinBox and
    linking the device to a CAPsMAN manager.

    • Connect to the device using WinBox
      • Navigate to Quick Set using the menu on the left
      • Set mode (combo box at top) to CAP
      • Set Address Acquisition to Automatic
      • Set Address Source to Ethernet
      • Select Bridge All LAN Ports
      • Set Router Identity to a unique name on the LAN
      • Change password
      • Press OK
      • Navigate to Wireless using the menu on the left
      • Select the WiFi Interfaces tab
      • Press CAP button
      • Select Enabled
      • Set Interface to wlan1
      • Set Certificate to none
      • Set Discovery Interface to ether1 (if devices are linked via ethernet)
      • Set Bridge to bridgeLocal
      • Press OK
  • References:

Linux Lost Password – Recover Linux User


Recover a Linux installation after loosing the administrator user password

  • Download a Linux live CD
  • It can be any linux distro as long as your architecture is the same as the installation.
    Lets go with Ubuntu desktop, because instructions may be slightly different for different
    distros.

    https://ubuntu.com/download/desktop/thank-you?version=20.04.2.0&architecture=amd64

  • Burn the ISO to a CD
  • Boot the machine with lost password from the CD
  • In the case of Ubuntu, you will have the option to “Install Ubuntu” or “Try Ubuntu”.
    Select “Try Ubuntu”, otherwise you risk formatting your disk(s).
    (You might have to select a language somewhere in the process)

  • Start terminal
  • When Ubuntu desktop is ready, click on “Activities” or press the Windows button. When
    activity search appears, type “term” – the “Terminal” app should appear – open it.

  • From the terminal, execute the following:
  • sudo bash
    # You should now be "root" user
    
  • Find disks and partitions
  • Use any combination of the following commands to get information about partitions:

    fdisk -l
    lsblk
    

    Valid entries should look like this:
    /dev/sd*
    /dev/nvme*

  • Create a mount point to work with
  • mkdir -p /mnt/linux
    
  • Figure out on which drive Linux is installed
  • The partion where Linux is installed, should typically have an “ext4”
    filesystem if it is a recent version of Ubuntu, but it may be different if
    other options or distros were installed. Here is an example of how you would
    check if a partition (e.g. /dev/sda1) contains linux:

    mount /dev/sda1 /mnt/linux
    ls /mnt/linux/boot
    

    If anyone of these fails, Linux is not on it. You can umount the partition with the following command
    if this is the wrong partition before moving on to check another partition:

    umount /mnt/linux
    

  • Having found a Linux partion, do the following:
  • chroot /mnt/linux
    

    If this fails, this is not the partition you are looking for. However, if the installation is a x86 installation
    it will not work if you booted an amd64 cd. The error message should be very clear and you should
    then download an older version of Ubuntu or Lubuntu that is x86 – you can use this link:
    https://cdimage.ubuntu.com/lubuntu/releases/18.04.5/release/lubuntu-18.04.5-desktop-i386.iso

  • Add user or change password
  • If the chroot command succeeded, you should now be root user in the installed linux and you
    can manipulate the users and configuration. To create a temp user with admin rights, do the following:

    useradd -d /home/tempadmin -m -s /bin/bash -g users -G sudo tempadmin
    passwd tempadmin
    

    (You can also change existing user passwords using passwd command)

    Now edit ssh configuration to make sure you can log in via ssh: (this tutorial
    assumes openssh-server was installed on the machine.

    nano /etc/ssh/sshd_config
    

    You need to comment out “AllowUsers” or “AllowGroups” lines, since they might block your new user.
    You also need to enable “PasswordAuthentication yes”
    On the server in question, the rest of the settings should be ok. Save the and close the file (Ctrl+X)

  • Unmount the partition
  • unmount /mnt/linux
    

  • You can now and reboot normally
  • Once machine is booted completely, follow these steps:

    • First log in with your newly created username
    • Open a terminal and get the address with one of the following commands:
    •   ip a
        ifconfig
        

    • Check whether routing and DNS is configured correctly:
    •   ping 8.8.8.8
        ping www.google.com
        

    • Test ssh access
    • Now you can test ssh access using the address you got earlier trying to ssh to the machine from a different workstation.

        ssh tempadmin@
        

      If the only other machine you have is a Windows without Linux For Windows installed, you can download Putty from
      https://www.ssh.com/ssh/putty/download

    • Check if the user has administrator access
    • The last thing you need to check is if the user is an administrator:

        sudo bash
        whoami
        

      You would need to enter your password, but then whoami should report
      that you are root.

    Disclamer: Anyone using any of these instructions do so at their own risk. Neither the author or anyone or any company related to this site takes any responsibility for effects performing any of the tasks on any device.


Hypervisor Information


Get information of underlying hypervisor from Linux VM


Execute the following command in the VM

sudo dmidecode | grep -i -e manufacturer -e product -e vendor