How to build the smallest docker image?

Let’s write simple C-code to be used as our application which just simply print “Hello World!” message on the screen.


const char msg[] = "Hello World!\n";

void _start(){
  syscall(SYS_write, 1, msg, sizeof(msg) - 1);
  syscall(SYS_exit, 0);

Now compile it using gcc compiler and size optimization.

# gcc -static -Os -nostartfiles -fno-asynchronous-unwind-tables hello-world.c -o hello-world

Our next step will be building docker images with below Dockerfile.

FROM scratch
ADD hello-world /
CMD ["/hello-world"]

So let’s build it!

docker build -t hello-world .

And that’s all! Now we have our smallest Hello World image created. It has just 1.84kB!

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              770ca6b8f31c        5 minutes ago       1.84kB

Let’s try to run it.

$ docker run --rm hello-world 
Hello World!

Get VIO adapters info directly from AIX LPAR

Sometimes You need to find out VIO names and VIO adapter’s which are used by Your AIX LPAR, but do not have access to the VIO servers directly. There is a quick way using kdb to extract those information for You. Just use below scripts.

1) For virtual FC adapters

VFCS_LIST=$(lsdev -Cc adapter | awk '/Available .* Virtual Fibre Channel Client Adapter/ { print $1 }')
for f in ${VFCS_LIST}; do 
		echo vfcs $f | kdb | awk ' 
				/^adapter: / { 
						adapter = $2 
						lpar_id = $4 
						lpar_name = $6 
				/^host_name: / { 
						vios_host_name = $2 
						vios_host_device_name = $4 
				/^num_cmd_elems: / { 
						location_code = $4 
				/^portName: / { 
						wwpn = $2 
				END { 
						printf( "%-10s %-20s %-20s %s\n", 
								wwpn ) 

2) For virtual SCSI adapters

VSCSI_LIST=$(lsdev -Cc adapter | awk '/Available .* Virtual SCSI Client Adapter/ { print $1 }') 
for s in ${VSCSI_LIST}; do 
		echo cvai $s | kdb | awk -v adapter=$s ' 
				/:blank:+host_name: / { 
						vios_host_device_name = $6 
				/host part_number: / { 
						vios_host_id = $3 
						vios_host_name = $8 
				END { 
						printf( "%-10s %-20s %-20s\n", 
								vios_host_device_name ) 

Reading password into script without echoing it

Have You ever wondered how to read password to the variable in the script without echoing it to the screen?
This is quite simple and can be written in just few lines:

oldSTTY=$(stty --save)
stty -echo
read -p "Password: " PASSWD; echo
stty $oldSTTY

1: You save all current settings of the terminal
2: You disable echoing of input characters to the screen
3: You read password into PASSWD variable
4: You restore all your terminal settings as it was before

As I said it is very simple and straightforward, isn’t it?

Firmware update for SUN/Oracle SPARC server

As I had to face this task recently I would like to describe in few steps how to perform firmware update on SUN Sparc servers using T4-1 as an example.

Phase 1. Preparation

1. We do not want any surprises later so before start we should do sanity system reboot, service processor restart and perform all required backups.
From the Solaris level:

# shutdown -i6 -g0 -y

From the ILOM level:

-> reset /SP

2. Download firmware from Oracle website, upload to the server and unzip.
3. Using sysfwdownload utility load new firmware to SP:

# ./sysfwdownload -g
# ./sysfwdownload Sun_System_Firmware-8_9_9-SPARC_T4-1.pkg

4. Next we stop our system:

 # /usr/sbin/shutdown -i0 -g0 -y

Phase 2. Update

1. Open ssh ILOM session and save base configuration:

->show /HOST/bootmode
->show /HOST
->show /SYS

2. Stop our server

->stop /SYS

3. Make sure that option keyswitch_state for /SYS is set to Normal:

-> show /SYS
-> set /SYS keyswitch_state=Normal

4. Check if firmware was uploaded properly and start the update

-> show /SP/firmware/localimage
-> load -source /SP/firmware/localimage

5. We can look on the update process and wait the ILOM restart and we can log in again.

Phase 3. Checks and system start

1. We have to ensure that host bootmode did not change. If You are using LDOM it might be critical for You.

-> show /HOST/bootmode

If needed we can change it:

-> set /HOST/bootmode="our-config-name"

2. Start system:

-> start /SYS

3. Open console and watch system booting:

-> start /HOST/console

4. If everything went fine and Solaris boots up we can finally confirm our new firmware version:

# prtdiag -v