0

I have experienced creating a FreeBSD kernel image but is there a way to include an application, for example an SQlite database in the image? What I want to achieve is to package the application in the image build as one.

1
  • Sounds like you want something like Linux’ initramfs.
    – Daniel B
    Commented Aug 29, 2022 at 12:26

1 Answer 1

1

Is there a way to include an application, for example, an SQlite database in the image?

Yes. It is. Mount your custom image or one of the publicly available images and use pkg to install packages. Use the option -r. Quoting:

-r  <root directory>, --rootdir <root directory>
         pkg will install all packages within the specified <root
         directory>.

Notes:


Example

  • Create memory disk /dev/md0 from the image
shell> mdconfig -a -t vnode -u 0 -f FreeBSD-13.1-RELEASE-amd64.raw
  • Show the partitions
shell> gpart show /dev/md0
=>       3  10552467  md0  GPT  (5.0G)
         3       123    1  freebsd-boot  (62K)
       126     66584    2  efi  (33M)
     66710   2097152    3  freebsd-swap  (1.0G)
   2163862   8388608    4  freebsd-ufs  (4.0G)
  • Mount the partition to /mnt and list the directory
shell> mount -t ufs /dev/md0p4 /mnt
shell> ll /mnt
total 176
drwxr-xr-x  18 root  wheel   512 May 12 11:58 ./
drwxr-xr-x  24 root  wheel  1024 Aug 21 16:05 ../
-rw-r--r--   2 root  wheel  1023 May 12 11:45 .cshrc
-rw-r--r--   2 root  wheel   507 May 12 11:45 .profile
-r--r--r--   1 root  wheel  6109 May 12 11:58 COPYRIGHT
drwxr-xr-x   2 root  wheel  1024 May 12 11:55 bin/
drwxr-xr-x  14 root  wheel  1536 May 12 11:58 boot/
dr-xr-xr-x   2 root  wheel   512 May 12 11:39 dev/
drwxr-xr-x  28 root  wheel  2048 May 12 11:59 etc/
-rw-r--r--   1 root  wheel     0 May 12 11:59 firstboot
drwxr-xr-x   5 root  wheel  2048 May 12 11:55 lib/
drwxr-xr-x   3 root  wheel   512 May 12 11:55 libexec/
drwxr-xr-x   2 root  wheel   512 May 12 11:39 media/
drwxr-xr-x   2 root  wheel   512 May 12 11:39 mnt/
drwxr-xr-x   2 root  wheel   512 May 12 11:39 net/
dr-xr-xr-x   2 root  wheel   512 May 12 11:39 proc/
drwxr-xr-x   2 root  wheel  2560 May 12 11:55 rescue/
drwxr-x---   2 root  wheel   512 May 12 11:58 root/
drwxr-xr-x   2 root  wheel  3072 May 12 11:56 sbin/
drwxrwxrwt   2 root  wheel   512 May 12 11:39 tmp/
drwxr-xr-x  14 root  wheel   512 May 12 11:39 usr/
drwxr-xr-x  24 root  wheel   512 May 12 11:39 var/
  • Install the package sqlite3 within the specified root directory /mnt
shell> pkg -r /mnt install sqlite3
Updating FreeBSD repository catalogue...
Fetching meta.conf: 100%    163 B   0.2kB/s    00:01    
Fetching packagesite.pkg: 100%    6 MiB   1.7MB/s    00:04    
Processing entries: 100%
FreeBSD repository update completed. 31759 packages processed.
All repositories are up to date.
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    libedit: 3.1.20210910,1
    sqlite3: 3.39.0,1

Number of packages to be installed: 2

The process will require 6 MiB more space.
1 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/2] Fetching sqlite3-3.39.0,1.pkg: 100%    1 MiB   1.4MB/s    00:01    
[2/2] Fetching libedit-3.1.20210910,1.pkg: 100%  136 KiB 138.9kB/s    00:01    
Checking integrity... done (0 conflicting)
[1/2] Installing libedit-3.1.20210910,1...
[1/2] Extracting libedit-3.1.20210910,1: 100%
[2/2] Installing sqlite3-3.39.0,1...
[2/2] Extracting sqlite3-3.39.0,1: 100%
  • Take a look at the installed files
shell> for file in `pkg -r /mnt info -l sqlite3 | grep /usr/local`; do ll /mnt/$file; done
-r-xr-xr-x  1 root  wheel  1727552 Aug 11 03:12 /mnt//usr/local/bin/sqldiff*
-rwxr-xr-x  1 root  wheel  1960488 Aug 11 03:12 /mnt//usr/local/bin/sqlite3*
-rw-r--r--  1 root  wheel  613415 Aug 11 03:12 /mnt//usr/local/include/sqlite3.h
-rw-r--r--  1 root  wheel  37310 Aug 11 03:12 /mnt//usr/local/include/sqlite3ext.h
lrwxr-xr-x  1 root  wheel  19 Aug 11 03:12 /mnt//usr/local/lib/libsqlite3.so@ -> libsqlite3.so.0.8.6
lrwxr-xr-x  1 root  wheel  19 Aug 11 03:12 /mnt//usr/local/lib/libsqlite3.so.0@ -> libsqlite3.so.0.8.6
-rwxr-xr-x  1 root  wheel  1750208 Aug 11 03:12 /mnt//usr/local/lib/libsqlite3.so.0.8.6*
-rw-r--r--  1 root  wheel  297 Aug 11 03:12 /mnt//usr/local/libdata/pkgconfig/sqlite3.pc
-r--r--r--  1 root  wheel  3596 Aug 11 03:12 /mnt//usr/local/man/man1/sqlite3.1.gz
-rw-r--r--  1 root  wheel  55 Aug 11 03:12 /mnt//usr/local/share/licenses/sqlite3-3.39.0,1/LICENSE
-rw-r--r--  1 root  wheel  71 Aug 11 03:12 /mnt//usr/local/share/licenses/sqlite3-3.39.0,1/PD
-rw-r--r--  1 root  wheel  180 Aug 11 03:12 /mnt//usr/local/share/licenses/sqlite3-3.39.0,1/catalog.mk
  • Umount the image and destroy the vnode
shell> umount /mnt
shell> mdconfig -l
md0 
shell> mdconfig -d -u 0
shell> mdconfig -l
2
  • Hm, I’m not quite sure this answers the entirety of the question. The way I’m reading it, OP wants a single file that contains both the kernel and the image you propose to create.
    – Daniel B
    Commented Aug 30, 2022 at 6:57
  • Your answer make sense to me, I will try. Thanks for the details @Vladimir Botka! Commented Aug 31, 2022 at 0:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .