How to create a custom ISO image from RHEL 7 ISO using genisoimage ?

Recently I had to delete few packages in RHEL 7.6 ISO.

I tried few softwares in Windows like 7zip, gburner, anyburn, etc

However, none of them helped me.

So, one of my colleagues suggested me to use mkisofs.

I never used it before. So, I had to spend some time googling on how to use mkisofs.

Below is the list of commands I ran in Ubuntu 16.04 which helped me create a custom ISO from RHEL 7.6 ISO.

My ISO name is RHEL-7.6-Server-x86_64-dvd1.iso

  1. Create few directories
mkdir /home/play_with_iso
mkdir /home/play_with_iso/original
mkdir /home/play_with_iso/mnt
mkdir /home/play_with_iso/copy_iso_files
mkdir /home/play_with_iso/new

     2. Copy the ISO to /home/play_with_iso/original

     3. Mount the ISO

mount -t iso9660 -o loop /home/play_with_iso/original/RHEL-7.6-Server-x86_64-dvd1.iso /home/play_with_iso/mnt

     4. Copy the contents of the mounted ISO

cp -pRf /home/play_with_iso/mnt /home/play_with_iso/copy_iso_files

   5. Unmount the ISO

umount /home/play_with_iso/mnt

   6. Modify the contents of the ISO in the path /home/play_with_iso/copy_iso_files

   7. Create new ISO.

cd /home/play_with_iso/copy_iso_files
genisoimage -U -r -v -T -J -joliet-long -V "RHEL-7.6 Server.x86_64" -volset "RHEL-7.6 Server.x86_64" -A "RHEL-7.6 Server.x86_64" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot -o /home/play_with_iso/new/RHEL-7.6-Server-x86_64-dvd1.iso .

Note:

The value of the parameters V, volset, A should be the value of inst.stage2 in isolinux.cfg .

In the ISO I used, the value is RHEL-7.6\x20Server.x86_64

Look for a line in isolinux.cfg as below

append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.6\x20Server.x86_64 quiet

So, the values of the parameters V, volset, A should be “RHEL-7.6 Server.x86_64”

  8. Implant an MD5 checksum into the image

implantisomd5 /home/play_with_iso/new/RHEL-7.6-Server-x86_64-dvd1.iso

 

Reference Links

  1. RHEL 7 Working with ISO Images
Advertisements

How to set default templates to an OS in Foreman 1.15.6 using REST API ?

I recently started using Foreman for provisioning servers. It is a nice tool, however, the documentation is not so great.


I did not find the REST API documentation for setting default templates to an OS. 

So, I ran the hammer set-default-template command with verbose option and got the REST API I needed.

Below are the simple functions which can help set default templates to an OS

import requests
requests.packages.urllib3.disable_warnings()


FOREMAN_URL = 'https://192.168.10.20/api'
FOREMAN_CREDENTIALS = ('admin', 'foreman')

HEADERS = {'content-type': 'application/json'}


def get_template_by_id(template_id):
    url = '{}/{}/{}'.format(FOREMAN_URL, "config_templates", template_id)
    template = requests.get(url, auth=FOREMAN_CREDENTIALS, verify=False)
    return template.json()

def set_os_default_templates(os_id, template_ids):
    for template_id in template_ids:
        template = get_template_by_id(template_id)
        url = '{}/{}/{}/{}'.format(FOREMAN_URL, "operatingsystems", os_id, "os_default_templates")
        payload = {"os_default_template": {"config_template_id": str(template_id), "template_kind_name":template['template_kind_name']}}
        requests.post(url, headers=HEADERS, auth=FOREMAN_CREDENTIALS, json=payload, verify=False)

# Set templates with ids 10, 20 as default templates to OS with id 1        
os_id = 1
template_ids = (10, 20)
set_os_default_templates(os_id, template_ids)

How to install and configure samba in Ubuntu 18.04 ?

I recently started using samba to create network shares for storing ISO images.

Below are the commands which helped me setup samba in Ubuntu 18.04

  1. Install samba
apt-get install samba

2. Create a user and password for accessing samba share

useradd sambauser --shell /bin/false
smbpasswd -a sambauser

3. Create a directory for storing ISO images and change ownership

mkdir /home/sambauser/iso_images
chown sambauser /home/sambauser/iso_images

4. Edit samba configuration. Add the below content to the end of the file /etc/samba/smb.conf

[iso_images]
path = /home/sambauser/iso_images
valid users = sambauser
read only = no

5. Restart samba

   service smbd restart

6. Verify samba. If the IP of the above samba host is 192.168.10.20, we can verify the share using the below instructions

Windows
Open Run and type \\192.168.10.20\iso_images

Ubuntu
apt-get install cifs-utils
mount -t cifs //192.168.10.20/iso_images /home/iso_images -o rw

Create few files in the samba directory and check if they are available in the shared location

 

How to send vm-support logs in ESXi via kickstart file ?

I recently started using ESXi and I need to install ESXi via kickstart files.

The basic kickstart file available in different websites works fine.

However, I needed a way to send vm-support logs to a FTP server.

Assuming FTP server IP is 192.168.10.20 and the directory “esxi_vmsupport_logs” exists in FTP root directory, below is the post section of the kickstart file

 

%post --interpreter=busybox --ignorefailure=true

#disable firewall to send logs to FTP server
localcli network firewall set --enabled=false

vm-support -s > /tmp/vm-support-logs.tgz

cat >/tmp/send_vmsupport_logs.py << EOF
from ftplib import FTP
import subprocess
import sys


def send_logs_to_ftp(ftp_ip, ftp_dir, ftp_user='ftp'):
    ftp = FTP(ftp_ip)
    ftp.login(ftp_user)
    ftp.cwd(ftp_dir)
    service_tag = subprocess.check_output("localcli hardware platform get | sed -n '/^\s*Serial/p' | cut -d: -f 2 | cut -d' ' -f 2", shell=True).strip()
    with open('/tmp/vm-support-logs.tgz', 'rb') as f:
        dest_log = service_tag.decode("utf-8") + '.tgz'
        ftp.storbinary('STOR %s' % dest_log, f)
    ftp.quit()


if __name__ == '__main__':
    ftp_ip = sys.argv[1]
    ftp_dir = sys.argv[2]
    send_logs_to_ftp(ftp_ip, ftp_dir)
EOF
python /tmp/send_vmsupport_logs.py 192.168.10.20 /esxi_vmsupport_logs

reboot

 

How to setup anonymous FTP and transfer files using Python ftplib ?

I recently started using vsftpd and Python ftplib in one of my projects to save log files in FTP.

I would like to list down the instructions, configuration and sample code which helped me setup anonymous FTP and upload files using Python ftplib

Note: My host OS is Ubuntu 18.04

Install vsftpd

apt-get update && apt-get install vsftpd

Create directory for FTP logs

mkdir /home/ftp_logs

Make the directory world writable

chmod a+rwx /home/ftp_logs

Set ownership for the directory

chown -R nobody:nogroup /home/ftp_logs

Configure vsftpd (/etc/vsftpd.conf)

listen=YES
local_enable=NO
anonymous_enable=YES
write_enable=YES
anon_root=/home/ftp_logs
allow_writeable_chroot=YES
virtual_use_local_privs=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
no_anon_password=YES

Start vsftpd

/etc/init.d/vsftpd start

Python code to transfer a file using ftplib

from ftplib import FTP

FTP_IP = '192.168.10.20'
ftp = FTP(FTP_IP)
ftp.login('ftp')

with open('/home/install_status_src.log', 'rb') as f:
    ftp.storbinary('STOR %s' % 'install_status_dest.log', f)
ftp.quit()

Run this code to upload a file to FTP server.

 

How to use Docker in a proxy environment in Ubuntu 18.04 ?

I recently started using cntlm and had to make few simple changes for Docker to work fine with proxy

Let’s say your machine IP is 192.168.10.20 and cntlm is listening on port 3128

A. Edit /lib/systemd/system/docker.service

Add the below line in [Service] section and restart docker
Environment=”HTTP_PROXY=192.168.10.20:3128″

B. Add the environment variables in Dockerfile

ENV http_proxy http://192.168.10.20:3128
ENV https_proxy http://192.168.10.20:3128

 

What can be the user stories of few of the most successful products ?

I recently joined Dell and I had an opportunity to listen to The Guru of Product Management David Fradin.

One of the key takeaways from David’s session is “Story Telling”

Organizations create a product and go to customers expecting them to buy.

Few organizations listen to customers, empathize with their problems and create products to solve those problems.

Very few organizations create products by envisioning user’s problems in the future or create products for a completely new market segment.

Customers always start with something like “I want to …..” which translate to the features of the products to solve customer’s problems.

In this post, I will try to write the possible user stories of few of the widely used products

Ola 

As a user, I want to book a cab from A to B
As a user, I want to pay for my ride using cash or card
As a user, I want to know how much time does it take the driver to reach my pick up point
As a user, I want to know how much time it takes for my ride to complete
As a user, I want to contact the driver
As a user, I want to cancel my ride

Amazon (E-commerce)

As a user, I want to buy a product using computer or mobile
As a user, I want to pay for a product using cash or card
As a user, I want to browse all the products
As a user, I want to know the details of a product
As a user, I want to browse products by category
As a user, I want to cancel my order

Watsapp

As a user, I want to send instant messages to any of my contacts over internet
As a user, I want to add contacts
As a user, I want to share any media files with my contacts
As a user, I want to create groups
As a user, I want to call any contact

All the most widely used products solve a problem and they make user’s lives easy.

So, what’s your product’s user stories ?