Creating "golden images" of an operating system (OS) is a popular and recommended practice for deploying new systems to any environment, from the data center to the public cloud. They enable rapid deployments that are more maintainable and can better conform to your unique Standard Operating Environment (SOE) requirements. Red Hat Enterprise Linux (RHEL) provides two options to help you build customized RHEL OS images: RHEL image builder and Red Hat Insights image builder. An overview and list of latest articles about these can be found here: https://redhat.com/image-builder.
Insights image builder has recently added the first boot script configuration feature to embed scripts in the image that are run when an instance first starts up. This enables you to run your scripts to do any variety of custom tasks. This new pre-release feature is currently available by enabling Preview mode and will later transition to full production support status.
This article will focus on Insights image builder and demonstrate how to execute a simple shell script at first boot, as well as explain how it works. In later articles, we will demonstrate more advanced functionality, such as implementing RHEL system roles, registering to Red Hat Satellite and initiating callbacks to Red Hat Ansible Automation Platform.
Creating the image with Insights image builder
Insights image builder can be accessed under Inventory->Images in Insights for RHEL of the Hybrid Cloud Console. You can try the first boot script configuration by enabling Preview mode at the top of the screen. When this feature transitions out of preview status, this step will no longer be necessary.I’ll start by creating a new blueprint, and selecting the version of RHEL and target environments that I would like to use for the image.

On the registration step of image builder, it is recommended that the system be registered with Red Hat. This will make sure that any script commands to install or update software will be able to download RHEL content, assuming network access to Red Hat is available.

Including a shell script for first boot automation
Insights image builder provides a text box, complete with syntax highlighting, for you to drag and drop, upload, or write your scripts from scratch. It will auto-detect both bash shell and python scripts.
Note that this feature supports regular shell (bash) and Python scripts that can run in a normal RHEL environment. This makes it easier to test script functionality in a normal environment. This is different from traditional RHEL installer kickstart, post-install scripting which are executed in a “chroot” environment and can be very challenging to test and debug.

In this example, I used the following bash script. Note that it provides multiple examples of how to capture debugging output for later review.
#!/bin/bash
## Enable debugging for this bash script
set -x
## Test writing a file with a starting time stamp
date > /var/tmp/ib-test.txt
echo "Hello, world!" >> /var/tmp/ib-test.txt
## Set our hostname
hostnamectl set-hostname "ib-test"
## Testing a log message to the journal
## View later with `journalctl -t bootup_script`
logger -t bootup_script "Howdy! This is a test message from the bootup script."
## Test that the system registered correctly
## 2>&1 captures of stout and sterr
rhc status >> /var/tmp/ib-test.txt 2>&1
## View the systemd service status
systemctl status custom-first-boot >> /var/tmp/ib-test.txt 2>&1
## Final time stamp
date >> /var/tmp/ib-test.txt
How does it work?
The first boot script execution works by defining a systemd unit service with the oneshot
option. This means the script will only run a single time. The shell script is renamed as /usr/local/sbin/custom-first-boot
.done to ensure it is not run again while remaining available for future reference. The systemd unit file looks like this:
[root@ib-test ~# cat /etc/systemd/system/custom-first-boot.service
[Unit]
Description=Run first boot script
ConditionPathExists=/usr/local/sbin/custom-first-boot
Wants=network-online.target
After=network-online.target
After=osbuild-first-boot.service
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/custom-first-boot
ExecStartPost=mv /usr/local/sbin/custom-first-boot /usr/local/sbin/custom-first-boot.done
[Install]
WantedBy=multi-user.target
Validation and debugging
The steps to provision a system from the image vary depending on the target platform. For more information, refer to the Insights image builder documentation.
Once a system is provisioned from the image, I logged in to the system to verify that the first boot script had properly run and to review the logging output.
Note that by using the set -x option at the beginning of the shell script, it captures all of the commands executed. This is good for debugging but may not be a recommended practice or conform to your organization’s security requirements as it could leak sensitive information.
First, I queried systemd about the service with the journalctl -u custom-first-boot.service command.

Next, I reviewed the output file that my script was writing to with the cat /var/tmp/ib-test.txt command.

Lastly, I reviewed the system’s primary messaging log to see where the service was run during startup using the less /var/log/messages command, and then searching for the custom-first-boot text.

Wrap up
The Insights image builder first boot script configuration functionality opens up many exciting possibilities that enable you to further customize your RHEL golden images. Check out the overview and list of latest articles here, then go over to Insights image builder to create your own custom blueprints and RHEL images.
저자 소개
Terry Bowling has been designing and working with customers on UNIX and GNU/Linux environments since 1999. He brings this experience to the RHEL Product Management team to provide the best experience to assembling and deploying RHEL for customers. This includes the RHEL installer, image builder and related build services for RHEL being developed at Console.RedHat.com.
유사한 검색 결과
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.