Part 1. Getting Started
Chapter 2. Installing FreeBSD
-
FreeBSD的鏡像分為多種,如:CD的、DVD的、memstick。用于U盤的,是memstick.img的。
Using dd to write the image:
# dd if=FreeBSD-12.1-RELEASE-amd64-memstick.img of=/dev/sdb bs=1M conv=sync
。
If this command fails, verify that the USB stick is not mounted and that the device name is for the disk, not a partition. Some operating systems might require this command to be run with sudo. The dd syntax varies slightly across different platforms; for example, Mac OS requires a lower-case bs=1m. Systems like Linux might buffer writes. To force all writes to complete, use sync.
Win下的工具可用Win32DiskImager、rufus等等。
- FreeBSD Boot Loader Menu,按數字鍵6可進入Boot Options,Toggle “Verbose” On,可以在啟動過程中顯示出詳細資訊。
- When laying out file systems, remember that hard drives transfer data faster from the outer tracks to the inner. Thus, smaller and heavier-accessed file systems should be closer to the outside of the drive, while larger partitions like /usr should be placed toward the inner parts of the disk. It is a good idea to create partitions in an order similar to: /, swap, /var, and /usr.
- As a rule of thumb, the swap partition should be about double the size of physical memory (RAM).
- On larger systems with multiple SCSI disks or multiple IDE disks operating on different controllers, it is recommended that swap be configured on each drive, up to four drives. The swap partitions should be approximately the same size. The kernel can handle arbitrary sizes but internal data structures scale to 4 times the largest swap partition. Keeping the swap partitions near the same size will allow the kernel to optimally stripe swap space across disks. Large swap sizes are fine, even if swap is not used much. It might be easier to recover from a runaway program before being forced to reboot.
- A standard FreeBSD GPT installation uses at least three partitions: freebsd-boot - Holds the FreeBSD boot code; freebsd-ufs - A FreeBSD UFS file system; freebsd-swap - FreeBSD swap space. Another partition type worth noting is freebsd-zfs, used for partitions that will contain a FreeBSD ZFS file system.
- Proper sector alignment provides the best performance, and making partition sizes even multiples of 4K bytes helps to ensure alignment on drives with either 512-byte or 4K-byte sectors. Generally, using partition sizes that are even multiples of 1M or 1G is the easiest way to make sure every partition starts at an even multiple of 4K. There is one exception: the freebsd-boot partition should be no larger than 512K due to current boot code limitations.
- system clock / machine’s CMOS clock :set to UTC.
- Username: A common convention is to use the first letter of the first name combined with the last name, as long as each username is unique for the system. The username is case sensitive and should not contain any spaces.
- Arch的useradd的"-c, --comment COMMENT",就可以用來設定user’s full name,可為任意字元串,可包含空格。Arch的useradd不加-m選項就不會為新使用者建立login directory家目錄,具體描述參考Arch的
、/etc/defaults/useradd、/etc/login.defs。$ man useradd
- 若user needs administrative access,則user需被加入wheel組。
Chapter 3. FreeBSD Basics
- FreeBSD将ttyv0當作"system console",“system messages are configured by default to display on the system console.”(例如,在text-based界面下,先在ttyv0登入,然後Alt+F3,切換到ttyv2并用root登入,則ttyv0 也就是system console 中就會輸出一條root在ttyv2登入了的消息),ttyv1~ttyv7為"virtual console"。switching between virtual consoles,用Alt+F1;When using Xorg as a graphical console, the combination becomes Ctrl+Alt+F1 to return to a text-based virtual console。
- Note that the last virtual console (ttyv8) is used to access the graphical environment if Xorg has been installed and configured as described in “Chapter 5, The X Window System” (配置xdm時).
-
/etc/ttys,如果将某個ttyv的“status”中的“secure”去掉,則root不能在此ttyv登入。如果将console這行的secure改為insecure,則進入單使用者模式需要root密碼。
Note: If the root password is forgotten, booting into single user mode is still possible, but may be difficult for someone who is not familiar with the FreeBSD booting process.
(那麼忘了root密碼,如何進single user mode?可能在handbook Part Ⅲ有講?)
- vidcontrol - system console control and configuration utility。可以調很多console設定,但是我是在虛拟機,隻換了換foreground和background,video mode調不了,顯示不出可用的mode……調了的設定要想每次在開機時啟用,可寫到/etc/rc.conf。
- FreeBSD允許多使用者在同一時間使用電腦,While only one user can sit in front of the screen and use the keyboard at any one time, any number of users can log in to the system through the network。
- FreeBSD System Accounts:daemon、operator、bind、news、ww等等,The reason for this is security; if all services ran as the superuser, they could act without restriction。The superuser account,usually called root。
- Login class:Login classes are an extension to the group mechanism that provide additional flexibility when tailoring the system to different users.
- "Always double and triple-check any commands issued as the superuser, since an extra space or missing character can mean irreparable ([ɪˈrepərəbl]) data loss."
- FreeBSD中root使用者的primary group是wheel,而在Linux中是root。
- 要想使用su指令轉到root,使用者必須是wheel的一員 (“In particular, by default only users in the ‘wheel’ group can switch to UID 0 (‘root’)”)。而上一篇記錄Arch的筆記中曾提到,Arch Wiki說su、sudo的實作均不需要使用者處于wheel組。可看FreeBSD和Arch的/etc/pam.d/su,内容是有差别的,有需要的話,可以進行修改。
-
使用su從目前普通使用者轉換到另一個普通使用者,$USER、$HOME、$SHELL會改變,其他環境變量不改變。例如,現在是vanellope使用者,環境中有個變量是QWE,那麼su liberty後:$PWD、$QWE保持不變,$USER變為liberty;但若執行的是su - liberty,那麼$USER仍會變為liberty,但是$QWE就沒有了,$PWD會變為liberty的家目錄。
而當從普通使用者su到root時:例如,現在是vanellope,執行su root後:$PWD不變,$USER不變;若執行的是su - root:$PWD變為root家目錄,$USER變為root。(對比一下,su到普通使用者時,$USER會變,而su到root時,隻有加’-’,$USER才會變。)
在man su中,“By default, the environment is unmodified with the exception of USER, HOME and SHELL. HOME and SHELL are set to the target login’s default values.USER is set to the target login, unless the target login has a user ID of 0, in which case it is unmodified.”,
和$ su -
一樣(在Linux中是$ su -l
==$ su --login
==$ su -l
$ su -
),“Simulate a full login. The environment is discarded except for HOME, SHELL, PATH, TERM, and USER.”,在Arch中是這樣描述的:“Start the shell as a login shell with an environment similar to a real login: clears all the environment variables except TERM and variables specified by --whitelist-environment;initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH;changes to the target user’s home directory;sets argv[0] of the shell to ‘-’ in order to make the shell a login shell”。“It is recommended to always use the --login option (instead of its shortcut - ) to avoid side effects caused by mixing environments.”(這個不知道為什麼,是因為’–login’比’-'的意思更清晰?二者的結果是一樣的呀)
FreeBSD和Arch的有些options不一樣。推薦一個由ArchWiki管理團隊建立并維護的Arch manual pages
- 在Handbook中,“If - is specified when running this command, the user will also inherit the root user’s environment”,這個inherit,就是上條說的 discarded自己的環境,然後用root使用者的環境。(有錯誤了解請幫忙指正)
- sudo:An alternative is to install the security/sudo package or port. This software provides activity logging and allows the administrator to configure which users can run which commands as the superuser.
- FreeBSD的adduser和rmuser都是interactive mode;Arch的是useradd -m username、userdel -r username。被删除使用者的除了家目錄、郵箱之外的檔案,需要手動删除。
- chpass:可以修改使用者資訊。當執行者是regular user時,隻能修改shell、全名、工作地點電話等等;當執行者是superuser時,還可以改home、uid、gid、密碼和帳戶時效等等。
- pw可以建立、删除、修改、顯示使用者群組的資訊,pw useradd、pw usermod、pw groupadd、pw groupmod等等,pw groupmod groupname -M memberlist:将groupname的成員替換為memberlist,如果不想替換,隻想加就是-m,隻減就是-d。還有很多很多command和option,用時再看吧。Arch有usermod - modify a user account,可以用來修改一些使用者資訊。給使用者添加supplementary groups可以用
,删除組就用-G group1,group2,group3… username,想保留哪些組,就寫上哪些組,不寫的組就會被删除,但是 不寫primary group,也不會把使用者從primary group中删除。用usermod -g可以修改使用者的primary group。usermod -aG group1,group2... username
- 對一個目錄有rx,則可以正常cd進去并ls檢視目錄下的東西;若隻有r,則隻可以ls看到目錄下的檔案名和類型;若隻有x,則可以cd進目錄,但是不能ls看到目錄下有哪些東西。
-
上一篇筆記摘抄過Linux的man chmod。這次看到FreeBSD的man chmod,覺得還有必要再摘抄一下:(感覺FreeBSD這兒沒說全,可以将linux和FreeBSD的man chmod結合起來看)
chmod -R, change the modes of the file hierarchies rooted in the files, instead of just the files themselves. Beware of unintentionally matching the ‘. .’ hard link to the parent directory when using wildcards like ‘.*’ ———— 比如說,想對pp目錄下的目錄名符合‘.*’的目錄進行-R式修改權限,這時就會把‘. .’,也就是把pp的parent dir也進行了修改 (如果對pp的parent dir有足夠權限的話)。是以要小心!
Modes may be absolute or symbolic. An absolute mode is an octal number constructed from the sum of one or more of the following values:
4000:(the setuid bit). Executable files with this bit set will run with effective uid set to the uid of the file owner. Directories with this bit set will force all files and subdirectories created in them to be owned by the directory owner and not by the uid of the creating process, …
2000:(the setgid bit). Executable files with this bit set will run with effective gid set to the gid of the file owner.
1000:(the sticky bit). A directory whose ‘sticky bit’ is set becomes an append-only directory, or, more accurately, a directory in which the deletion of files is restricted. A file in a sticky directory may only be removed or renamed by a user if the user has write permission for the directory and the user is the owner of the file, the owner of the directory, or the super-user. This feature is usefully applied to directories such as /tmp which must be publicly writable but should deny users the license to arbitrarily delete or rename each others’ files.
s: The set-user-ID-on-execution and set-group-ID-on-execution bits.
X: The execute/search bits if the file is a directory or any of the execute/search bits are set in the original (unmodified) mode. Operations with the perm symbol ‘X’ are only meaningful in conjunction with the op symbol ‘+’, and are ignored in all other cases.
上次看到過的real user ID和effective user ID:The real user ID is the UID who owns or starts the process. The effective UID is the user ID the process runs as. As an example, passwd runs with the real userID when a user changes their password. However, in order to update the password database, the command runs as the effective ID of the root user. This allows users to change their passwords without seeing a Permission Denied error.
(突然想起的:
1)chmod、chown這些更改權限的指令,使用者隻能更改屬于自己的檔案、目錄的權限。當某個使用者是一個目錄所屬組的成員,且目錄所屬組對目錄是rwx,那麼這個使用者可以在這個目錄下建立、删除東西,但是不能更改此目錄下不屬于自己的東西的權限。就是使用者對不屬于自己的檔案目錄的權限可以被擴充:r、w、x,但使用者隻能控制屬于自己的檔案目錄的權限。
2) 在使用chmod這類指令對’.‘開頭的檔案目錄進行權限更改時,比如現在想改hh目錄下的’.'開頭的檔案的權限,
$ chmod g+w hh/.*
,因為hh目錄下包含.和. .目錄,如果使用者擁有hh目錄,那麼hh的權限也會被更改,不隻是更改了hh下“.”開頭的檔案的權限;如果使用者還擁有目錄“. .”,那麼hh的父目錄的權限也會被更改。是以使用時要注意".*"的用法,如果使用者隻是擁有目錄下“.”開頭的普通檔案和目錄,那麼目前目錄和目前目錄的父目錄的權限則不會受到影響。(shell的“*”不會比對檔案目錄名開頭的“.”,“.*”才能比對到開頭是“.”的檔案/目錄名,但這也會包括“.”和“. .”。
)
- chflags: In addition to file permissions, FreeBSD supports the use of “file flags”. These flags add an additional level of security and control over files, but not directories. With file flags, even root can be prevented from removing or altering files.
- “Note: In these examples, even though the shell script in question is an executable file, it will not run with a different EUID or effective user ID. This is because shell scripts may not access the setuid(2) system calls.”
- A mount point is a directory where additional file systems can be grafted onto a parent file system (usually the root file system). Standard mount points include /usr/, /var/, /tmp/, /mnt/, and /cdrom/.
-
:A complete description of the file system hierarchy is available in hier(7). 有時間的話應該好好看看man hier。(也看看linux的man hier)# man hier
- 為什麼會有 /usr/home/ 這個檔案夾? 看了一下,在FreeBSD中,/home/是link到/usr/home/的,而Arch中 /home/不是link;在FreeBSD中,/bin/ (user utilities fundamental to both single-user and multi-user environments)、/sbin/ (system programs and administration utilities fundamental to both single-user and multi-user environments)、/lib/ (critical system libraries needed for binaries in /bin and /sbin) 就是正常dir;而在Arch中,/bin/和/sbin/都是link到/usr/bin/的,/lib/和/lib64/是link到/usr/lib/的。
- motd :快速清空檔案
(%是FreeBSD普通使用者的指令提示符)% : > filename
- motd :“You can press Ctrl-L while in the shell to clear the screen”,或者執行clear也能清屏。
- 假定現在有三個檔案系統,是A、B、C,每個檔案系統都有一個root目錄,每個root下又有兩個目錄,分别為A1和A2、B1和B2、C1和C2。然後把檔案系統B挂載到A1,此時檔案系統B的根目錄就會取代A1,B1、B2中的東西就可以通過路徑/A1/B1、/A1/B2擷取,而/A1下原有的内容則會暫時隐藏,待B從A unmount後,會重新顯現。
-
安裝FreeBSD時可以隻使用一個很大的分區(根分區/),而不劃分其他分區(如/boot、/home、/usr、/var),但是不推薦這樣做,因為有些缺點(列舉了3個缺點、1個優點),具體看Handbook 3.6節。
那“1個優點”應該是指:安裝FreeBSD時隻用一個根分區/的話,若後續使用中發現分區容量需要擴充時,隻需要對這一個根分區擴充就行。(但是必須經過如下步驟:備份資料、以新容量擴充分區并建立檔案系統、恢複資料)(然鵝,FreeBSD搞了一個指令:growfs - expand an existing UFS file system,which makes it possible to increase the size of file system on the fly, removing this limitation. 也就是可以線上擴充UFS檔案系統,無需備份資料等那些操作,是以即使有多個分區,那隻要對相應的分區進行線上擴充就好了,意味着那“1個優點”也算不上什麼優點了。)
- FreeBSD中的區(partitions)的用詞:假如現在有一塊MBR的disk,根據MBR,這個disk上最多有4個primary。然後現在在此disk上劃出3個primary區,這叫作slices,然後每個slice裡又可以有partitions (比如slice1裡可以裝Windows,slice1裡劃分幾個partitions作為CDEF盤,slice2、slice3可以裝FreeBSD,每個slice可以劃分出partitions,裝FreeBSD需要的檔案系統),partitions标号從a到h,然後每個partition隻能包含一個file system或者swap。i.e. “ada1s3e” is the fifth partition in the third slice of the second SATA disk drive.",ada一般表示硬碟為SATA型,1表示第二塊硬碟,s3表示第三個slice,e表示第五個partition。
- 接上條,體會FreeBSD(UNIX)的partition和dos的partition。Handbook中舉了個栗子Example 3.13 Conceptual Model of a disk:假定現在電腦上挂着的disks的第一塊是250G的SATA disk,上面有兩個slice,第一個slice是170GB (MS-DOS partitions),裝着Windows NTFS file system , C:,第二個slice是裝着FreeBSD,有四個data partitions and a swap partition。見圖,圖更直覺: Partition letter c refers to the entire slice, and so is not used for ordinary partitions. Partition letter a一般指root file system所在分區,b 是 swap,d 以前有特殊含義 現在沒了,和efgh正常使用。
FreeBSD 12.1 Handbook Notes Part 1 Getting StartedPart 1. Getting Started -
Daemons: Some programs are not designed to be run with continuous user input and disconnect from the terminal at the first opportunity. For example, a web server responds to web requests, rather than user input. Mail servers are another example of this type of application.
(These types of programs are known as daemons. The term daemon comes from Greek mythology and represents an entity that is neither good nor evil, and which invisibly performs useful tasks. This is why the BSD mascot is the cheerful-looking daemon with sneakers and a pitchfork.)
There is a convention to name programs that normally run as daemons with a trailing “d”.比如httpd、sshd等。This is only a naming convention.
-
ps指令:To display a static list of … : PIDs are assigned starting at 1, go up to 99999, then wrap around back to beginning. The TT column show the tty the program is running on and STAT shows the program’s state. TIME is the amount of time the program has been running on the CPU. This is usually not the elapsed time since the program was started, as most programs spend a lot of time waiting for things to happen before they need to spend time on the CPU. Finally, COMMAND is the command that was used to start the program.
最常用的選項set之一就是 auxww, where ‘a’ displays information about all the running processes of all users, ‘u’ displays the username and memory usage of the process’ owner, ‘x’ displays information about daemon processes, and ‘ww’ causes ps to display the full command line for each process, rather than truncating it once it gets too long to fit on the screen.
-
top指令:To display all the running processes and update the display every few seconds in order to interactively see what the computer is doing. 其輸出分為兩部分:第一部分是最開始的五六行,The header shows the PID of the last process to run (因為是動态顯示,是以可看到系統中最後一個運作的程式的PID,每當一個新的程序運作,其PID就可作為last pid,可看到last pid的顯示會更新), the system load averages (which are a measure of how busy the system is), …, and how much time the system is spending in different CPU states. If the ZFS file system module has been loaded, an ARC line indicates how much data was read from the memory cache instead of from disk.
By default, top also displays the amount of memory space taken by the process. This is split into two columns: one for total size and one for resident size. Total size is how much memory the application has needed and the resident size is how much it is actually using now.
top automatically updates the display every two seconds. A different interval can be specified with -s.
-
Killing Processes: Two signals can be used to stop a process: SIGTERM and SIGKILL.
SIGTERM is the polite way to kill a process as the process can read the signal, close any log files it may have open, and attempt to finish what it is doing before shutting down. In some cases, a process may ignore SIGTERM if it is in the middle of some task that cannot be interrupted.
SIGKILL cannot be ignored by a process. Sending a SIGKILL to a process will usually stop that process there and then. (确實有些任務暫時不能中斷,隻有當任務變成可以中斷了,程序才能被killed。栗子看FreeBSD 12.1 Handbook P78 頁面最下方的注釋。)
- Procedure 3.1. Sending a Signal to a Process 舉了一個栗子,它用kill給程序發送信号,但用的是/bin/kill。“Why use /bin/kill ? Many shells provide kill as a built in command, meaning that the shell will send the signal directly, rather than running /bin/kill . Be aware that different shells have a different syntax for specifying the name of the signal to send. Rather than try to learn all of them, it can be simpler to specify /bin/kill .”
- Arch中,ls和grep要顯示顔色的話,是用"–color=auto",而FreeBSD裡grep還是"–color=auto",而ls要用"-G",或者設定變量CLICOLOR或COLORTERM;指令source是csh、bash的shell built-in command,sh沒有它。
- 在FreeBSD裡,發現delete鍵不能用,一按就是輸出’~’,這就需要設定一下,在csh配置檔案裡寫入
,然後source一下使設定生效。指令bindkey、bindkey -l可以看到更多可用的設定。(有時間的話看看man csh)(bash是bind)bindkey "^[[3~" delete-char
- 設定環境變量:在sh、bash中設定環境變量 與 在tcsh、csh中設定的差別:前者是
,後者是export EDITOR="/usr/local/bin/emacs"
。setenv EDITOR /usr/local/bin/emacs
- 在linux的tty下,螢幕翻頁是shift+page up/page down;在FreeBSD的ttyv下是,先按下Scroll lock鍵,然後就可以方向鍵↑/↓滾動檢視螢幕,看完以後想要繼續敲指令,再按下Scroll lock鍵。
- When using ZFS as the file system the “df” command is reporting the pool size and not file system sizes. It also does not know about descendent ZFS datasets, snapshots, quotas, and reservations with their individual space usage. Use the built-in “zfs list” command to get a better overview of space usage:
.# zfs list -o space
Chapter 4. Installing Applications: Packages and Ports
- 更新已安裝軟體:
;列出所有已安裝軟體:# pkg upgrade
,檢視某個已安裝軟體的資訊:# pkg info
;删除軟體:# pkg info pkgname
;檢測已安裝的軟體的vulnerabilities:# pkg delete pkgname
。# pkg audit -F
可删除/var/cache/pkg目錄下過時的二進制包,保留下載下傳的最新版本的二進制包,在這條指令後添加-a選項,則是直接清空/var/cache/pkg目錄。# pkg clean
- 自動删除無用的包:
;the packages that were explicity installed not as a dependency to another package, can be listed using:# pkg autoremove
,所列出的包的源可用# pkg prime-list
檢視;Marking an installed package as automatic can be done using:# pkg prime-origins
, Once a package is a leaf package and is marked as automatic, it gets selected by# pkg set -A 1 devel/cmake
; Marking an installed package as not automatic can be done using:pkg autoremove
。# pkg set -A 0 devel/cmake
- The Ports Collection is a set of Makefiles, patches, and description files. Each set of these files is used to compile and install an individual application on FreeBSD, and is called a port.
-
如果安裝FreeBSD的過程中沒有安裝The Ports Collection,那麼FreeBSD安裝完成後,有兩種方法安裝The Ports Collection:
1)Portsnap Method:首先下載下傳壓縮的The Ports Collection的snapshot到/var/db/portsnap :
,然後extract the snapshot into /usr/ports :# portsnap fetch
,這兩步可以合起來:# portsnap extract
。這便完成了portsnap的第一次使用,等以後需要更新/usr/ports的時候,執行# portsnap fetch extract
# portsnap fetch update
,也可以分開寫成兩條指令。
2)Subversion Method : If more control over the ports tree is needed or if local changes need to be maintained, Subversion can be used to obtain the Ports Collection. Subversion的安裝也有兩種方法,如果系統已經有了/usr/ports (比如FreeBSD安裝時安裝了Ports),則
、# cd /usr/ports/devel/subversion
;若沒有安裝ports,則用pkg,# make install clean
。Subversion安裝完成後,check out a copy of the ports tree:# pkg install subversion
,等之後使用時需要更新/usr/ports :# svn checkout https://svn.FreeBSD.org/ports/head /usr/ports
。# svn update /usr/ports
-
/usr/ports/下是軟體類别,每個類别目錄下才是相應的軟體,i.e. /usr/ports/games/xonotic/,就是遊戲類别下有個遊戲xonotic(第一人稱射擊,可以單機玩,挺好)。然後每個軟體的目錄内又包含一些檔案,稱為"ports skeleton",每個port skeleton一般包含以下檔案和目錄:
Makefile: contains statements that specify how the application should be compiled and where its components should be installed.
distinfo: contains the names and checksums of the files that must be downloaded to build the port.
files/: this directory contains any patches needed for the program to compile and install on FreeBSD. This directory may also contain other files used to build the port.
pkg-descr: provides a more detailed description of the program.
pkg-plist: a list of all the files that will be installed by the port. It also tells the ports system which files to remove upon deinstallation.
The port does not include the actual source code, also known as a distfile. The extract portion of building a port will automatically save the downloaded source to /usr/ports/distfiles.
- (4.5.1. Installing Ports)用ports安裝軟體:(Using the Ports Collection assumes a working Internet connection. It also requires superuser privilege.)To compile and install the port, change to the directory of the port to be installed, then type make install at the prompt:
,# cd /usr/ports/sysutils/lsof
# make install clean
。
因為一些shell會有指令緩存,是以新安裝port以後,在tcsh中可以執行
,這樣新裝的指令在執行時就不必輸入full path。(sh shell用% rehash
)% hash -r
- (4.5.1.1. Customizing Ports Installation) 一些ports會提供編譯選項,然後可能它依賴的ports也會提供編譯選項,這樣在安裝時就會中途暫停好幾次以讓使用者選擇編譯選項,但是可以在the port skeleton (要安裝的軟體的ports目錄 /usr/ports/xxx/xxx/)中執行
,to do all of the configuration in one batch, 然後再# make config-recursive
# make install clean
。
make config、make showconfig、make rmconfig 可以用來增加、删除或者改變已安裝軟體的build options。
ports安裝時使用fetch來下載下傳源檔案,它支援各自環境變量。對于那些不能一直聯網的使用者,
can be run within /usr/ports, to fetch all distfiles, or within a category, or within the specific port skeleton. (應該就是 因為聯網時間可能不長,然後使用者可以根據需要用fetch下載下傳所需distfiles————要麼是全部ports的distfiles,要麼是某個類别的distfiles,要麼是某個軟體的distfiles,然後進行安裝) 但是當在category和ports skeleton中執行fetch時,如果要安裝的軟體有依賴在其他categories,則feth不會從其他categories下載下傳所需distfiles,這可以用# make fetch
make fetch-recursive
來解決。
如果fetch時有指定的local distfiles repository,可以用變量進行指定:
(在/usr/ports/下、在category下、在ports skeleton下應該都可以指定);還可以通過變量改變 ports安裝時進行編譯等工作的目錄 和 ports被安裝的目錄:# make MASTER_SITE_OVERRIDE=xxxxxxxxx fetch
will compile the port in /usr/home/example/ports and install everything under /usr/local,# make WRKDIRPREFIX=/usr/home/example/ports install
will compile the port in /usr/ports and install it in /usr/home/example/local. And:# make PREFIX=/usr/home/example/local install
# make WRKDIRPREFIX=../ports PREFIX=../local install
will combine the two. 如果這些變量經常用,可以設定為shell環境變量,不用每次寫。
是以,一般用ports裝軟體時,可以醬紫:
、# make config-recursive
。# make install clean
- 删除已安裝的ports,可以用pkg delete; alternately, make deinstall can be run in the port’s directory:
、# cd /usr/ports/sysutils/lsof
。最好在port被解除安裝時看一看輸出的資訊,因為如果有其他已安裝軟體依賴于被解除安裝軟體,那麼輸出中會顯示資訊,但是解除安裝過程仍将繼續,是以這時還得重新安裝已解除安裝的軟體,不然就會break dependencies。make deinstall
-
更新ports:首先要更新ports tree,上面的第4條講了兩種安裝the Ports Collection的方法:portsnap和svn,這倆也可以用來更新ports tree。
如果安裝FreeBSD時沒有安裝The Ports Collection,然後FreeBSD安裝完成後用portsnap或者svn安裝了The Ports Collection,那麼要更新ports tree的話:portsnap 先fetch然後update;svn 先checkout然後update。
如果安裝FreeBSD時已經安裝了The Ports Collection,且現在是第一次更新ports tree,那麼用portsnap的話,得先fetch,然後extract,再update。因為如果ports tree是用portsnap維護的,那麼/usr/ports下會有一個.portsnap.INDEX檔案,而安裝FreeBSD時安裝的/usr/ports下沒有這個portsnap的索引檔案,是以不能直接fetch後update,要extract後才能update。等以後再次用portsnap更新ports tree時,就可以portsnap fetch後update了,此時執行update後,如果有新變化需要加入本地ports tree,update就會将新目錄和檔案extract到相應位置。
如果安裝FreeBSD時已經安裝了The Ports Collection,且現在是第一次更新ports tree,那麼用svn的話(得先安裝上svn),就是先chekout,然後update。用svn更新過的/usr/ports下會有一個.svn目錄。
綜上,更新ports tree時,svn随便用,而用portsnap,則要求ports tree目錄下有portsnap的INDEX檔案。(如果之前不是用portsnap,然後現在想用,必須得執行extract,但是extract會清空目前ports tree上使用者做的本地修改,但是extract可以與選項path一起用,即隻extract部分ports tree。如果自己對ports tree做了本地修改,那麼請認真看portsnap和svn的指令)
用svn checkout時可能出現錯誤:svn: E120106: ra_serf: The server sent a truncated HTTP response body. 據說這是因為檔案太大,然後下載下傳得太慢,解決辦法為:每出現一次這個錯誤,就先在工作目錄下執行svn cleanup、svn update,然後再接着checkout。如此循環,直至checkout完成。(也可以修改httpd.conf,把Timeout得值設得大一些,比如Timeout=6000或者=12000。但是我沒在我的系統上find到這個檔案…)
下圖依次顯示了安裝FreeBSD時安裝的/usr/ports、Portsnap的ports tree和SVN的ports tree的對比,因為svn時下載下傳的檔案太大且網速太慢,是以沒checkout完,我就停止了。
FreeBSD 12.1 Handbook Notes Part 1 Getting StartedPart 1. Getting Started - 接着上條,更新完ports tree後,就可以更新ports了。可以用
# pkg version -l "<"
看哪些installed ports are out of date。注意:更新ports前,先看看/usr/ports/UPDATING,如果有涉及到待會兒更新的ports,看看可能會有什麼問題、變化,該怎麼做。更新工具大部分使用Portmaster、Portupgrade,Synth是一個新的更新工具。
Using Portmaster: ports-mgmt/portmaster is designed to use the tools installed with the FreeBSD base system without depending on other ports or databases. 沒有安裝portmaster的話可先用port安裝。Portmaster定義了四種類型的ports: Root port: 它不依賴其他ports,任何其他ports也不會依賴于它;Trunk port: 它不依賴其他ports,但其他ports可能會依賴于它;Branch port: 它可能會依賴别的ports,且其他的ports可能依賴于它;Leaf port: 它可能依賴于其他ports,但是沒有ports會依賴于它. (果然我翻譯一下反而不好懂了,還是看英文原話比較清晰) To list these categories and search for updates:
, to upgrade all outdated ports:# portmaster -L
. Portmaster會在更新時自動對舊的ports進行備份,如果更新成功,才會删除備份,可用-b選項使其不自動删除備份,使用-i選項可使Portmaster進入interactive mode,每更新一個port都會請求确認。如果更新過程中出現錯誤,加-f可重新更新并建立ports:# portmaster -a
。Portmaster也可以用來安裝new ports,它可以自動更新new ports安裝時需要的所有依賴,舉個栗子:# portmaster -af
# portmaster shells/bash
。更多用法可看Portmaster的ports目錄下的pkg-descr檔案。
Portmaster更新(有新版本的)每個port時,會建立一個package形式的備份,如果這個port成功更新了,那麼調用pkg-delete删除package備份,如果更新port失敗了,則會顯示提示資訊,告訴使用者如何找到package備份。(預設情況,這些package備份會存放到變量$PACKAGES指定的目錄(usually /usr/ports/packages)下的名為"portmaster-backup"的目錄下,比如/usr/ports/packages/portmaster-backup/icu-65.1,1.txz就是icu的pkg形式的備份) -B選項可以用來讓portmaster不建立package備份,-b選項可使package備份在成功更新port後不被自動删除。在更新過程中,添加-D選項,可以"no cleaning of distfiles",-d可以"always clean distfiles",避免有時需要一個一個确認是否删除某個port的stale distfiles。
是以在man portmaster的栗子中,給出了更新并删除stale distfiles的指令用法:
,即先更新ports,這時不删,等全部更新完了,再删除stale distfiles。(distfiles就是make fetch下來的源碼包,儲存在/usr/ports/distfiles)# portmaster -aD; portmaster --clean-distfiles
portmaster --clean-distfiles
,可以添加-t選項,這樣就是 如果有任意port依賴于某個stale file,即使這個port還未安裝,那也不删除這個stale file;不加-t就是隻看已安裝的ports裡有沒有依賴某個stale file的,沒有的話 就删除這個stale file;-y和-n可以用來避免一個個确認是否删除這個stale file,要麼全yes要麼全no。
Using Portupgrade: 想用的話可先用ports安裝,然後看文檔
-
pkg install和pkg upgrade時 會自動進行 執行pkg update時做的事情(“Updating FreeBSD repository catalogue”),是以除非是換了新的pkg源,那麼不用單獨執行pkg update。(了解錯了請指正)
pkg info 會列出installed packages,portmaster -L會列出installed ports及可更新的版本,但是這倆指令列出的是一樣的東西:用pkg和ports安裝的所有包,不是:pkg列出用pkg install的包,portmaster列出用make install clean, portmaster列出的可更新的包。如果一個軟體(比如vim)是用pkg安裝的(或作為依賴安裝的),那不能用
這樣直接隻更新某個包,但可以# portmaster vim-8.1.2372
,這樣更新vim,相當于在ports下make install,比用pkg upgrade慢。# portmaster editors/vim
- 用ports安裝軟體确實有點麻煩……我用portsnap更新ports tree,然後ports源用的USTC的,但是這倆更新不能時刻同步,所有就會有ports tree更新了新版本的一個依賴包,但是USTC的freebsd-ports源的distfiles還沒有同步新版本的那個源碼包,這樣ports系統fetch不到需要的包,就會轉向GitHub找,雖然能找到連結,但是下載下傳是從AmazonAWS下載下傳的,是以還是不行……除非翻外網,否則隻能等ustc同步了以後,再make install。
- ports-mgmt/pkg_cutleaves automates the task of removing installed ports that are no longer needed. (用pkg autoremove應該也行,之前用ports安裝emacs,編譯沒成功,就準備删了安裝的東西 重來,然後用了一下pkg autoremove,能把編譯emacs時編譯安裝的其他依賴軟體删掉)
-
更換pkg源:建立/usr/local/etc/pkg/repos/FreeBSD.conf,寫入:
FreeBSD: {
url: “pkg+http://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/quarterly”,
}
更換ports源:建立檔案/etc/make.conf,寫入:MASTER_SITE_OVERRIDE?=http://mirrors.ustc.edu.cn/freebsd-ports/distfiles/${DIST_SUBDIR}/ ,等用ports安裝軟體時,就能看到輸出顯示從這個源fetch distfiles。
- 這節 4.6. Building Packages with Poudriere,關于Poudriere的介紹和用法,可以安裝ports-mgmt/poudriere後看man,或者看GitHub https://github.com/freebsd/poudriere/wiki 。
-
Post-Installation Considerations:
1)大多數app都會安裝至少一個配置檔案,并将其放入/usr/local/etc目錄下,如果有多個配置檔案,則會建立子目錄來存放。通常模闆配置檔案以.sample字尾結尾,To edit a sample file, first copy it without the .sample extension.
2)第三方app的文檔會存放在/usr/local/share/doc目錄下,也會安裝manual pages。
3)有些app會運作服務(開機自啟服務),其相關配置需要寫入/etc/rc.conf,然後再開啟服務。These applications usually install a startup script in /usr/local/etc/rc.d 。
4)Users of csh should run rehash to rebuild the known binary list in the shells PATH.
5)Use pkg info to determine which files, man pages, and binaries were installed with the application.
-
用ports安裝Emacs時,裝完 archivers/lzo2 這個依賴并将其注冊為automatic時,輸出了錯誤資訊:“pkg-static: Cannot get an exclusive lock on a database, it is locked by another process”,我沒有重新在emacs的port skeleton下make install,因為它輸出了還有哪些沒有成功安裝,是以我cd到剩餘的每個port skeleton,執行make install clean,然後pkg set -A 1 xxx/xxx,就是指定這個依賴所在目錄及軟體名,将其注冊為automatic,但是像cmake這樣的依賴,就不将其注冊為automatic了。
在man pkg-static中:pkg-static is a statically linked variant of pkg typically only used for the initial installation of pkg. There are some differences in functionality. See pkg.conf(5) for details.
Chapter 5. The X Window System
- bsdinstall安裝時不會自動安裝使用者界面,想要在安裝時就安裝上使用者界面的使用者可以去 http://www.trueos.org/ ,“TrueOS | FreeBSD Based Operating System with ZFS”。(國内目前打不開此網站…什麼時候能解封此類網站,FreeNAS的官網也打不開…)
- 安裝Xorg:用pkg安裝,或者用ports安裝。也可以安裝x11/xorg-minimal,但是有些未安裝的xorg元件可能是其他app需要的。
- 配置Xorg:将需要運作xorg的使用者加入video或wheel組,以啟用3D acceleration:
。執行# pw groupmod video -m jru || pw groupmod wheel -m jru
% startx
即可啟動xorg,預設的window manager是TWM (可以自己換成i3wm,這個用了很久,感覺用着挺習慣了)。
在/boot/loader.conf中添加一行 “kern.vty=vt” 以啟用vt。這步應該不是必須的,因為如果不寫那行,新版(9.0、10.0之後的版本)的FreeBSD會預設使用vt。在vt出現之前是sc,但是好像會發生這樣的問題:從X界面退出到virtual console後,會黑屏。
配置檔案:一般無需手動建立配置檔案,除非xorg自動配置時發生錯誤。xorg的配置檔案推薦存儲在/usr/local/etc/X11/下,使app檔案和os檔案分離;但是非要放在傳統的位置/etc/X11/下也可以。推薦使用多個檔案配置xorg,并将其存儲在/usr/local/etc/X11/xorg.conf.d/下;但是就想用傳統的一個檔案xorg.conf進行配置也可。
配置顯示卡驅動:看Handbook吧,這裡不記了。和Linux差不多,找到顯示卡資訊,下載下傳對應驅動,寫配置檔案,和Linux裡的配置一樣,都是section、device、identifier等等。配置檔案放在/usr/local/etc/X11/xorg.conf.d/下。
配置顯示器:大多數顯示器支援EDID(the Extended Display Identification Data standard),Xorg能通過EDID确定顯示器适合哪個分辨率和重新整理頻率。如果沒有自動選擇最好的分辨率或者想自己改分辨率,可以使用xrandr進行修改。想要每次使用自定義的分辨率、重新整理頻率、筆記本外接顯示器的位置等設定,可以寫xorg配置檔案進行配置,或者在.xinitrc檔案裡用xrandr設定。顯示器的相關配置也和Linux差不多,可以參考Arch Wiki裡有關顯示器配置的相關文檔。
可以設定關閉X界面的快捷鍵,參見Handbook 5.4.7.1. Keyboards。5.4.7.2. Mice and Pointing Devices講了一點滑鼠鍵的設定,比如可以設定滑鼠上的鍵的個數為7:Section “InputDevice”、Option “Buttons” “7”。
有時Xorg的自動配置可能對某些硬體不起作用,那這時可以自己配:先執行
,這會基于已檢測到的硬體生成一個傳統的single配置檔案/root/xorg.conf.new,然後在這個檔案中寫入或修改自己想要的配置,然後測試:# Xorg -configure
。等調到自己想要的狀态後,可以把xorg.conf.new拆成小配置檔案(就是之前說的,一個小配置檔案對一個硬體進行配置),放入/usr/local/etc/X11/xorg.conf.d/。# Xorg -config /root/xorg.conf.new
- 字型配置:在字型配置檔案中添加新字型的目錄、然後
、是否需要添加xorg啟動時load的子產品。字型配置盡量都寫在/usr/local/etc/fonts/local.conf檔案中,以XML格式。需要Xorg去load的子產品,看能不能寫到/usr/local/etc/X11/xorg.conf.d/xxxxxx.conf檔案中,檔案名不知道能不能自己随便起,内容包括Section “Module” Load “xxx”。配置檔案的寫法參照man fonts-conf、man xorg.conf、/usr/local/etc/fonts/、/etc/X11/xorg.conf 等。(在虛拟機用時,有些地方的字型我沒配好,比如fluxbox的window title不能顯示中文,但是我安裝了Google Noto的中文字型)# fc-cache -f
- 在虛拟機(我用的是VirtualBox)中使用FreeBSD時,安裝了xorg,然後startx,會報錯"freebsd xorg cannot run in framebuffer mode …",然後我看了看虛拟機裡的Ubuntu,安裝了一個vmware display driver,是以在FreeBSD虛拟機裡也裝一下
,然後就能startx進入界面了。(之前的虛拟機一般都裝arch,不需要界面,是以從來不知道虛拟機裡的linux/unix得有xf86-video-vmware驅動才能開界面)# pkg install xf86-video-vmware
- 桌面:之前用Arch時,是i3wm作為視窗管理器,然後有個wallpaper.sh (加入.xinitrc 使sh在啟動x界面時開始執行),這個sh的内容大緻就是在指定目錄抽一張圖檔,作為桌面,每15分鐘換一次。設定桌面是用feh --bg-scale實作,現在是新看到了一個選項:use --no-xinerama to treat the whole X display as one screen when setting wallpapers。這個還沒有用過,因為以前都是筆記本外接顯示器,i3wm會自動配置設定workspace,然後兩個螢幕桌面都是一樣的。不知道兩個螢幕不一樣大時(一個螢幕是筆記本屏,一個是大顯示器),用上–no-xinerama會是什麼樣,一張圖檔 左半部分在筆記本屏 右半部分在外接屏 尺寸還不同,感覺不好看吧……等以後配了桌上型電腦,弄兩個一樣的大屏,這樣應該會好看。
- 在Gentoo Wiki中看到的關于URxvt的一些以前不知道的東西:urxvt可以作為daemon,這樣能減少資源消耗、加速新終端的啟動。推薦在啟動X時啟動daemon ( It is a good idea to start the daemon at the beginning of the X session.)。在相應檔案中(比如.xinitrc)寫入:
,After this, new clients can be opened on the single daemon process, rather than spawning new processes for each terminal,之後想要打開新終端時用指令urxvtc代替urxvt。如果daemon被意外終止了,那麼所有在daemon上打開的urxvtc調用和執行個體都會被關閉。在檔案 ~/.urxvt/urxvtd-hostname 中還可以通過變量RXVT_SOCKET指定不同的listening socket。urxvtd --quiet --opendisplay --fork
- URxvt的color theme可以參照Gentoo Wiki的格式,然後自己設想要的顔色。有關urxvt的更多資料建議參考Arch Wiki、Gentoo Wiki、man pages。
-
GNU Screen。以前用Linux時,圖形界面一直用的i3wm,在字元界面也隻是進行一些簡單任務,是以一直不明白screen有什麼用…然後最近試用FreeBSD,一直在字元界面操作,有時需要多個終端,就手動ttyv0、ttyv1、ttyv2等來回切換着用,這時也沒想到screen,然後偶然看Gentoo Wiki的時候又看到了GNU Screen,才突然了解了screen的用處。
簡單了解,當在圖形界面需要多個終端時可以開多個圖形終端,而在字元界面時,一個tty隻有一個終端,那麼可以用screen來達到在一個tty裡顯示多個終端的目的。
當在tty指令行輸入
$ screen -S xxx
後,即開啟了一個名為xxx的screen session,這個session會開啟一個全屏的新的字元界面,稱為window,這個window中預設開啟的應用是shell (好像可以更改預設開啟的應用),但是這時還是隻有一個終端。
接下來可以通過按鍵對目前region進行劃分(可以認為screen -S xxx後開啟了一個大的region,然後這個region裡有一個運作着shell的window):先按Ctrl+a再按S,Split current region horizontally into two regions,也就是将目前region劃分為上下兩個regions;先Ctrl+a再|,Split current region vertically into two regions,即将目前region劃分為左右兩個region。新劃出的小region是空白的,什麼程式都沒有運作着,可以通過Ctrl+a tab将focus切換到新region,然後Ctrl+a c,在新region上打開一個預設運作着shell的window。
這樣一個tty裡就有了兩個終端了,可以将每個region不斷進行水準、垂直劃分,獲得多個region,每個region上可以開啟一個window,以獲得多個終端。當有兩個及以上window時,每個window都會有window title,比如第一個region 有一個window 運作着bash,那麼第一個window的title就是"0 bash",第二個region和第一個情況一樣的話,title就編号往下走,為"1 bash"。
常用指令:
,to create a named session$ screen -S session_name
,to print a list of “pid.tty.host” strings identifying your screen sessions$ screen -list
或$ screen -x session_name
$ screen -r session_name
,to attach to a named screen session
Ctrl+a ?,Displays commands and their defaults
Ctrl+a S,Split current region horizontally into two regions
Ctrl+a |,Split current region vertically into two regions
Ctrl+a tab,Switch the input focus to the next region
Ctrl+a c,Create a new window (with shell)
Ctrl+a ",Window list,可以用方向鍵的上下進行選擇,然後enter确認,将所選的那個window顯示在目前region上
Ctrl+a 0,opens window 0, Ctrl+a 1就是打開window 1,切換到某個region,然後Ctrl+a 再按某個數字鍵x,即可将window x顯示在目前region上
Ctrl+a a,Sends Ctrl+a to the current window,Arch Wiki中的栗子 “A common scenario”:使用者在終端開啟了一個screen session,然後在這個screen session裡開啟了ssh session,然後在ssh session裡又開了一個screen session。這時如果按鍵Ctrl+a a,那麼Ctrl+a首先被第一個開啟的screen session (the outer screen session) 處理,然後按鍵序列的第二個a被第二個screen session (the inner screen session) 處理,第二個screen session接收Ctrl+a。 For example: Ctrl+a a d Detaches the inner screen session. Ctrl+a a K Kills the inner screen session.
Ctrl+a Ctrl+a,Toggle between current and previous region,在目前region和上一個region之間切換。如果現在整個tty隻有左右兩個region,然後左邊是0 bash,右邊是空白,這時先将focus放在0 bash上,然後Ctrl+a tab将focus移到右邊的region,然後Ctrl+a Ctrl+a,則右邊region也顯示0 bash,那麼現在左右region就是同步顯示的,會顯示相同的動作及結果。可以用這個在tty裡弄"田"字分布的四個0 bash,然後screenfetch或者neofetch,截個屏/拍個照。
Ctrl+a Esc,Enter Copy Mode (use enter to select a range of text)
Ctrl+a ],Paste text
Ctrl+a [,不知道在哪看的說是檢視曆史。其實和Ctrl+a Esc一樣,是進入Copy Mode,然後可以上下移動光标,是以可以達到檢視螢幕buffer的目的。(進入Copy Mode後,按下space或enter可以選擇文本,移動光标選擇完成後,再按space或enter可以确認将選中的内容Copied into buffer,按其他鍵 比如q、Esc 可以終止Copy Mode。)
Ctrl+a Q,Close all regions but the current one
Ctrl+a X,Close the current region
Ctrl+a d,Detach from the current screen session, and leave it running.
Ctrl+a :quit,Closes all windows and closes screen session
Ctrl+a \,和上條一樣,但是會問你 Really???
Turn off visual bell: 在檔案~/.screenrc裡添加一行:
vbell off
,with this setting, Screen will not make an ugly screen flash instead of a bell sound.
上述指令差不多滿足目前的日常使用了,更多用法請參考Arch Wiki的簡單介紹和GNU Screen的手冊。
FreeBSD 12.1 Handbook 的剩餘Parts 的Notes以後再寫。