D.3. Cài đặt Debian GNU/Linux từ hệ thống UNIX/Linux

Phần này diễn tả phương pháp cài đặt Debian GNU/Linux từ một hệ thống UNIX hay Linux đã có, không cần dùng trình cài đặt dựa vào trình đơn như được diễn tả trong phần sổ tay còn lại. Tài liệu cài đặt chéo Thế Nào này đã được yêu cầu bởi người dùng chuyển đổi sang Debian GNU/Linux từ hệ thống Red Hat, Mandriva, và SUSE. Trong phần này giả sử là bạn quen với cách nhập lệnh *nix và cách duyệt qua hệ thống tập tin. Trong phần này, dấu đồng $ đại diện lệnh cần nhập vào hệ thống hiện thời của người dùng, còn dấu băm # đại diện lệnh được nhập vào chroot của Debian.

Một khi cấu hình hệ thống Debian mới một cách thích hợp, bạn có thể nâng cấp lên nó dữ liệu người dùng tồn tại nào, sau đó tiếp tục làm việc như bình thường. Vì vậy, tiến trình cài đặt Debian GNU/Linux này không có thời gian chết. Nó cũng là một phương pháp thông minh để quản lý phần cứng thường không hợp tác với vật chứa khác nhau kiểu khởi động hay cài đặt.

[Ghi chú] Ghi chú

Vì đây phần lớn là một thủ tục làm bằng tay, ghi nhớ rằng bạn sẽ cần phải tự làm nhiều cấu hình cơ bản, mà yêu cầu bạn quen nhiều với Debian và Linux hơn khi cài đặt bình thường. Thủ tục này sẽ không làm kết quả là hệ thống trùng với kết quả của tiến trình cài đặt bình thường. Thủ tục này chỉ diễn tả những bước cơ bản khi thiết lập hệ thống. Có thể là cần thiết thêm bước cài đặt hay/và cấu hình.

D.3.1. Bắt đầu

With your current *nix partitioning tools, repartition the hard drive as needed, creating at least one filesystem plus swap. You need around 1012MB of space available for a console only install, or about 2539MB if you plan to install X (more if you intend to install desktop environments like GNOME or KDE Plasma).

Sau đó, hãy tạo hệ thống tập tin trên những phân vùng. Chẳng hạn, để tạo một hệ thống tập tin kiểu ext3 trên phân vùng /dev/sda6 (phân vùng gốc mẫu):

# mke2fs -j /dev/sda6

Còn để tạo hệ thống tập tin kiểu ext2, chỉ cần bỏ đoạn -j đi.

Sơ khởi và kích hoạt vùng trao đổi (thay thế số thứ tự phân vùng của phân vùng trao đổi Debian dự định):

# mkswap /dev/sda5
# sync
# swapon /dev/sda5

Lắp một phân vùng như là /mnt/debinst (điểm cài đặt, để làm hệ thống tập tin gốc (/) trên hệ thống mới). Tên của điểm lắp là tùy ý chặt chẽ: nó được tham chiếu về sau bên dưới.

# mkdir /mnt/debinst
# mount /dev/sda6 /mnt/debinst

[Ghi chú] Ghi chú

Nếu bạn muốn đặt phần nào của hệ thống tập tin (v.d. /usr) được gắn kết vào phân vùng riêng, bạn cần phải tự tạo và gắn kết những thư mục này trước khi tiếp tục tới giao đoạn kế tiếp.

D.3.2. Cài đặt debootstrap

Tiện ích được dùng bởi trình cài đặt Debian, cũng được thấy là phương pháp chính thức để cài đặt hệ thống cơ bản Debian, là debootstrap. Nó dùng hai chương trình wgetar, nhưng về mặt khác thì phụ thuộc chỉ vào /bin/sh và các công cụ UNIX/Linux cơ bản[21]. Chưa có thì cài đặt hai gói wgetar, sau đó tải về và cài đặt gói debootstrap.

Hoặc bạn có thể tự cài đặt nó bằng thủ tục theo đây. Tạo một thư mục work vào đó cần giải nén .deb:

# mkdir work
# cd work

Tập tin nhị phân debootstrap nằm trong kho Debian (hãy chắc là bạn chọn tập tin thích hợp với kiến trúc của mình). Tải tập tin dạng .deb debootstrap xuống vùng gộp, sao chép gói đó vào thư mục work, sau đó giải nén các tập tin nhị phân ra nó. Bạn cần phải có quyền người chủ để cài đặt các tập tin nhị phân này.

# ar -x debootstrap_0.X.X_all.deb
# cd /
# zcat /đường_dẫn_đầy_đủ_đến_work/work/data.tar.gz | tar xv

D.3.3. Chạy debootstrap

Chạy chương trình debootstrap thì có thể tải các tập tin cần thiết một cách trực tiếp xuống kho lưu. Có thể thay thế chuỗi http.us.debian.org/debian (trong mẫu bên dưới) bằng bất cứ máy nhân bản kho lưu Debian nào, tốt hơn là một máy nhân bản ở gần chỗ bạn trên mạng. Các máy nhân bản được liệt kê ở địa chỉ http://www.debian.org/mirror/list.

If you have a bookworm Debian GNU/Linux installation image mounted at /cdrom, you could substitute a file URL instead of the http URL: file:/cdrom/debian/

Substitute one of the following for ARCH in the debootstrap command: amd64, arm64, armel, armhf, i386, mips64el, mipsel, ppc64el, s390x.

# /usr/sbin/debootstrap --arch ARCH bookworm \
     /mnt/debinst http://ftp.us.debian.org/debian

If the target architecture is different than the host, you should add the --foreign option.

D.3.4. Cấu hình hệ thống cơ bản

Now you've got a real Debian system, though rather lean, on disk. chroot into it:

# LANG=C.UTF-8 chroot /mnt/debinst /bin/bash

If the target architecture is different from the host, you will need to first copy qemu-user-static to the new host:

# cp /usr/bin/qemu-ARCH-static /mnt/debinst/usr/bin
# LANG=C.UTF-8 chroot /mnt/debinst qemu-ARCH-static /bin/bash

After chrooting you may need to set the terminal definition to be compatible with the Debian base system, for example:

# export TERM=xterm-color

Depending on the value of TERM, you may have to install the ncurses-term package to get support for it.

If the target architecture is different from the host, you need to finish the multi-stage boot strap:

/debootstrap/debootstrap --second-stage

D.3.4.1. Tạo tập tin thiết bị

Ở điểm thời này, thư mục /dev/ chỉ chứa các tập tin thiết bị rất cơ bản. Đối với những bước tiếp theo của tiến trình cài đặt, có thể cần thiết thêm tập tin thiết bị. Có một số phương pháp khác nhau : phương pháp thích hợp với trường hợp của bạn thì phụ thuộc vào hệ thống hỗ trợ tiến trình cài đặt, vào kiểu hát nhân (kiểu mô-đun hay không) và vào bạn định dùng tập tin thiết bị kiểu động (v.d. dùng udev) hay tĩnh.

Vài tùy chọn sẵn sàng:

  • cài đặt gói makedev, và tạo một tập hợp tập tin thiết bị tĩnh mặc định bằng cách dùng (sau khi đã đổi root)

    # apt install makedev
    # mount none /proc -t proc
    # cd /dev
    # MAKEDEV generic
    

  • tạo bằng tay chỉ một số tập tin thiết bị dứt khoát dùng MAKEDEV

  • bind mount /dev từ hệ thống hỗ trợ ở trên /dev trong hệ thống đích; ghi chú rằng những văn lệnh sau khi cài đặt của một số gói có thể thử tạo tập tin thiết bị, vì vậy bạn nên dùng tùy chọn này chỉ một cách cẩn thận.

D.3.4.2. Gắn kết phân vùng

You need to create /etc/fstab.

# editor /etc/fstab

Here is a sample you can modify to suit:

# /etc/fstab: static file system information.
#
# file system    mount point   type    options                  dump pass
/dev/XXX         /             ext3    defaults                 0    1
/dev/XXX         /boot         ext3    ro,nosuid,nodev          0    2

/dev/XXX         none          swap    sw                       0    0
proc             /proc         proc    defaults                 0    0

/dev/cdrom       /media/cdrom  iso9660 noauto,ro,user,exec      0    0

/dev/XXX         /tmp          ext3    rw,nosuid,nodev          0    2
/dev/XXX         /var          ext3    rw,nosuid,nodev          0    2
/dev/XXX         /usr          ext3    rw,nodev                 0    2
/dev/XXX         /home         ext3    rw,nosuid,nodev          0    2

Use mount -a to mount all the file systems you have specified in your /etc/fstab, or, to mount file systems individually, use:

# mount /path   # e.g.: mount /usr

Current Debian systems have mountpoints for removable media under /media, but keep compatibility symlinks in /. Create these as as needed, for example:

# cd /media
# mkdir cdrom0
# ln -s cdrom0 cdrom
# cd /
# ln -s media/cdrom

You can mount the proc file system multiple times and to arbitrary locations, though /proc is customary. If you didn't use mount -a, be sure to mount proc before continuing:

# mount -t proc proc /proc

Sau đó, lệnh liệt kê ls /proc nên hiển thị thư mục khác rỗng. Nếu nó bị lỗi, có lẽ bạn có khả năng gắn kết proc từ bên ngoài chroot đó.

# mount -t proc proc /mnt/debinst/proc

D.3.4.3. Đặt múi giờ

Setting the third line of the file /etc/adjtime to UTC or LOCAL determines whether the system will interpret the hardware clock as being set to UTC respective local time. The following command allows you to set that.

# editor /etc/adjtime

Here is a sample:

0.0 0 0.0
0
UTC

The following command allows you to choose your timezone.

# dpkg-reconfigure tzdata

D.3.4.4. Cấu hình khả năng chạy mạng

To configure networking, edit /etc/network/interfaces, /etc/resolv.conf, /etc/hostname and /etc/hosts.

# editor /etc/network/interfaces

Here are some simple examples from /usr/share/doc/ifupdown/examples:

######################################################################
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# See the interfaces(5) manpage for information on what options are
# available.
######################################################################

# The loopback interface isn't really required any longer, but can be used
# if needed.
#
# auto lo
# iface lo inet loopback

# To use dhcp:
#
# auto eth0
# iface eth0 inet dhcp

# An example static IP setup: (network, broadcast and gateway are optional)
#
# auto eth0
# iface eth0 inet static
#     address 192.168.0.42
#     network 192.168.0.0
#     netmask 255.255.255.0
#     broadcast 192.168.0.255
#     gateway 192.168.0.1

Enter your nameserver(s) and search directives in /etc/resolv.conf:

# editor /etc/resolv.conf

A simple example /etc/resolv.conf:

search example.com
nameserver 10.1.1.36
nameserver 192.168.9.100

Enter your system's host name (2 to 63 characters):

# echo DebianHostName > /etc/hostname

And a basic /etc/hosts with IPv6 support:

127.0.0.1 localhost
127.0.1.1 DebianHostName

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

If you have multiple network cards, you should arrange the names of driver modules in the /etc/modules file into the desired order. Then during boot, each card will be associated with the interface name (eth0, eth1, etc.) that you expect.

D.3.4.5. Cấu hình Apt

Debootstrap will have created a very basic /etc/apt/sources.list that will allow installing additional packages. However, you may want to add some additional sources, for example for source packages and security updates:

deb-src http://ftp.us.debian.org/debian bookworm main

deb http://security.debian.org/ bookworm-security main
deb-src http://security.debian.org/ bookworm-security main

Make sure to run apt update after you have made changes to the sources list.

D.3.4.6. Cấu hình miền địa phương và bàn phím

To configure your locale settings to use a language other than English, install the locales support package and configure it. Currently the use of UTF-8 locales is recommended.

# apt install locales
# dpkg-reconfigure locales

To configure your keyboard (if needed):

# apt install console-setup
# dpkg-reconfigure keyboard-configuration 

Ghi chú rằng bàn phím không thể được đặt trong khi nằm trong chroot, nhưng sẽ được cấu hình cho lần khởi động lại kế tiếp.

D.3.5. Cài đặt hạt nhân

Nếu bạn dự định khởi động hệ thống này, bạn rất có thể muốn có một hạt nhân (kernel) Linux và một bộ nạp khởi động (boot loader). Có thể nhận diện các hạt nhân đóng gói sẵn bằng lệnh:

# apt search linux-image

Sau đó cài đặt gói hạt nhân đã chọn, dùng tên gói của nó.

# apt install linux-image-arch-etc

D.3.6. Thiết lập bộ nạp khởi động

To make your Debian GNU/Linux system bootable, set up your boot loader to load the installed kernel with your new root partition. Note that debootstrap does not install a boot loader, but you can use apt inside your Debian chroot to do so.

Ghi chú rằng ở đây giả sử tập tin thiết bị /dev/sda đã được tạo. Có những phương pháp khác để cài đặt grub2, nhưng chúng không nằm trong phạm vi của phụ lục này.

D.3.7. Remote access: Installing SSH and setting up access

In case you can login to the system via console, you can skip this section. If the system should be accessible via the network later on, you need to install SSH and set up access.

# apt install ssh

Root login with password is disabled by default, so setting up access can be done by setting a password and re-enable root login with password:

# passwd
# editor /etc/ssh/sshd_config

This is the option to be enabled:

PermitRootLogin yes

Access can also be set up by adding an ssh key to the root account:

# mkdir /root/.ssh
# cat << EOF > /root/.ssh/authorized_keys
ssh-rsa ....
EOF

Lastly, access can be set up by adding a non-root user and setting a password:

# adduser joe
# passwd joe

D.3.8. Đòn kết liễu

As mentioned earlier, the installed system will be very basic. If you would like to make the system a bit more mature, there is an easy method to install all packages with standard priority:

# tasksel install standard

Of course, you can also just use apt to install packages individually.

Sau khi cài đặt xong, có rất nhiều gói đã tải về nằm trong thư mục kho lưu /var/cache/apt/archives/. Vậy bạn có dịp giải phóng thêm chỗ trống trên đĩa bằng cách chạy lệnh « làm sạch »:

# apt clean



[21] Những công cụ này gồm có các tiện ích lõi của GNU và lệnh như sed, grep, targzip.