带有内置应用程序的 FreeBSD 内核映像

带有内置应用程序的 FreeBSD 内核映像

我曾经创建过 FreeBSD 内核映像,但是有没有办法将应用程序(例如 SQlite 数据库)包含在映像中?我想要实现的是将映像构建中的应用程序打包为一个。

答案1

有没有办法在图像中包含一个应用程序,例如 SQlite 数据库?

是的。可以。安装您的自定义映像或其中一个公开可用的映像图片并使用安装软件包。使用选项-r。引用:

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

笔记:


例子

  • 创建记忆盘/dev/md0从图片中
shell> mdconfig -a -t vnode -u 0 -f FreeBSD-13.1-RELEASE-amd64.raw
  • 显示分区
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)
  • 将分区挂载到/mnt并列出目录
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/
  • 安装包sqlite3在指定的根目录中/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%
  • 查看已安装的文件
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
  • 卸载镜像并销毁 vnode
shell> umount /mnt
shell> mdconfig -l
md0 
shell> mdconfig -d -u 0
shell> mdconfig -l

相关内容