-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
+++ | ||
title = 'Debian Preseed late_command' | ||
date = 2024-07-01T16:05:02Z | ||
draft = false | ||
+++ | ||
|
||
In Debian installation process, the `preseed.cfg` file allows for automated installations by pre-configuring various installation parameters. In this article I will focus on the `d-i preseed/late_command string` parameter, which is used to run custom commands at the end of the installation process. | ||
|
||
Here is an example that I recently used in my [packer-vbox-debian-latest](https://github.com/Schwitzd/packer-vbox-debian-latest) project: | ||
|
||
``` | ||
d-i preseed/late_command string \ | ||
mkdir --mode=700 /target/home/testuser/.ssh; \ | ||
wget -q http://10.0.2.2:8081/key.pub -O /target/home/testuser/.ssh/authorized_keys; \ | ||
in-target chown testuser:testuser /home/testuser/.ssh; \ | ||
in-target chown testuser:testuser /home/testuser/.ssh/authorized_keys; \ | ||
in-target chmod 0600 /home/testuser/.ssh/authorized_keys | ||
``` | ||
|
||
As you can see, sometimes `/target` is used, other times `in-target`, I must admit I struggled a bit to understand the difference and when to use one instead of the other. | ||
|
||
## The `/target` directory | ||
|
||
When you are installing Debian, the installer needs a place to set up the new system, and this place is called `/target`. During the installation process, `/target` acts as a temporary workspace where the new system's root filesystem is prepared. Essentially, the installer mounts the new system's root partition to `/target`, allowing it to configure and manipulate the filesystem and its contents as if it were the actual running system. | ||
|
||
## The `in-target` command | ||
|
||
The `in-target` command is used within the preseed file to execute commands in the context of the newly installed system, rather than within the installer’s environment. When you use `in-target`, it effectively chroots into `/target` and runs the specified command as if you were executing it on the new system. | ||
|
||
## Conclusion | ||
|
||
- Use `/target` when you need to create or manipulate files and directories directly on the new system’s filesystem during the installation process. | ||
- Use `in-target` when you need to execute commands within the context of the new system, as it effectively chroots into `/target` and runs commands as if you were operating within the new system itself. |