arch Linux

Posted d0ct0rx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arch Linux相关的知识,希望对你有一定的参考价值。

  1. 制作启动盘

  2. 将U盘插入待装主机,设置U盘启动,重启进入系统安装界面

  3. 设置root密码

    [email protected]~ # passwd
  4. 启动允许远程连接

    [email protected]~ # systemctl start sshd
  5. 链接无线网络

    [email protected]~ # wifi-menu
  6. 查看待装主机的IP地址

    [email protected]~ # ip a
  7. 拿出MacBook我们使用远程安装

    macOS:~ hhbsh$ ssh [email protected]
  8. 更新在线安装源

    在下列文件开头

    [email protected] ~ # vim /etc/pacman.d/mirrorlist

    添加

    Server = http://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch
    Server = http://mirrors.zju.edu.cn/archlinux/$repo/os/$arch
  9. 更新

    [email protected] ~ # sudo pacman -Syy
  10. 分区,使用如下命令查看磁盘分区情况

    [email protected] ~ # fdisk -l
  11. 找到待装磁盘符。我这里是 /dev/sda

    Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors
    Disk model: Lenovo SSD SL700
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: gpt
    Disk identifier: 6109DCF3-362D-468B-970C-81967DD0D852
    
    Device        Start       End   Sectors  Size Type
    /dev/sda1      2048      6143      4096    2M Bios boot
    /dev/sda2      6144    415743    409600  200M Linux filesystem
    /dev/sda3    415744  17192959  16777216    8G Linux filesystem
    /dev/sda4  17192960 250069646 232876687  111G Linux filesystem
  12. 抹除 /dev/sda 磁盘的所有数据

    [email protected] ~ # fdisk /dev/sda
    
    Welcome to fdisk (util-linux 2.33.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): p
    Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors
    Disk model: Lenovo SSD SL700
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: gpt
    Disk identifier: 6109DCF3-362D-468B-970C-81967DD0D852
    
    Device        Start       End   Sectors  Size Type
    /dev/sda1      2048      6143      4096    2M BIOS boot
    /dev/sda2      6144    415743    409600  200M Linux filesystem
    /dev/sda3    415744  17192959  16777216    8G Linux filesystem
    /dev/sda4  17192960 250069646 232876687  111G Linux filesystem
    
    Command (m for help): d
    Partition number (1-4, default 4):
    
    Partition 4 has been deleted.
    
    Command (m for help): d
    Partition number (1-3, default 3):
    
    Partition 3 has been deleted.
    
    Command (m for help): d
    Partition number (1,2, default 2):
    
    Partition 2 has been deleted.
    
    Command (m for help): d
    Selected partition 1
    Partition 1 has been deleted.
    
    Command (m for help): d
    No partition is defined yet!
    
    Command (m for help):
    
    
    Command (m for help): w
    
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
  13. 使用下面命令刷新信息

    [email protected] ~ # partprobe
  14. 重启机器

    [email protected] ~ # reboot

    注:当然还是选择U盘启动。选第一个即可。

  15. 在待安装主机重复 3~6 步骤

  16. 然后我们就到MacBook使用远程安装,执行步骤 7。出现下列问题

    macOS:~ hhbsh$ ssh [email protected]
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
    Someone could be eavesdropping on you right now (man-in-the-middle attack)!
    It is also possible that a host key has just been changed.
    The fingerprint for the ECDSA key sent by the remote host is
    SHA256:kGzwhZIhRjRwXG7UNenF1zhXruVLaOz6MyGCtnAu5Wg.
    Please contact your system administrator.
    Add correct host key in /Users/hhbsh/.ssh/known_hosts to get rid of this message.
    Offending ECDSA key in /Users/hhbsh/.ssh/known_hosts:8
    ECDSA host key for 192.168.3.8 has changed and you have requested strict checking.
    Host key verification failed.
  17. 原因是我们之前链接的ssh协商的 192.168.3.8 该 IP 地址的主机密钥失效。我们在MacBook的 /Users/hhbsh/.ssh/known_hosts 文件内删除 192.168.3.8 相关信息, :wq 保存退出,重新生成密钥即可。

    macOS:~ hhbsh$ vim /Users/hhbsh/.ssh/known_hosts
    macOS:~ hhbsh$ ssh [email protected]
    The authenticity of host '192.168.3.8 (192.168.3.8)' can't be established.
    ECDSA key fingerprint is SHA256:IhRjRwXG7fsfgUNenF1zhXruVLaOz6MdfgdfGCtnAu5Wg.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '192.168.3.8' (ECDSA) to the list of known hosts.
    [email protected]'s password:
    Last login: Mon Feb  4 05:08:29 2019
    [email protected] ~ #
  18. 我们再来查看 /dev/sda 分区信息。发现与 11 步的信息完全不同了,我们已经擦除了该磁盘数据。

    [email protected] ~ # fdisk -l
    Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors
    Disk model: Lenovo SSD SL700
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: gpt
    Disk identifier: 6109DCF3-362D-468B-970C-81967DD0D852
  19. 创建分区

    1. 首先我们创建一个 2MB 大小的分区 sda1,留着后边我们设定它的标志为 bios_grub
    2. 再创建一个 200MB 的分区 sda2
    3. 再创建一个 8G 的分区 sda3
    4. 余下的空间创建分区 sda4
    [email protected] ~ # fdisk /dev/sda
    
    Welcome to fdisk (util-linux 2.33.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): n
    Partition number (1-128, default 1):
    First sector (34-250069646, default 2048):
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-250069646, default 250069646): +2M
    
    Created a new partition 1 of type 'Linux filesystem' and of size 2 MiB.
    
    Command (m for help): n
    Partition number (2-128, default 2):
    First sector (6144-250069646, default 6144):
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (6144-250069646, default 250069646): +200M
    
    Created a new partition 2 of type 'Linux filesystem' and of size 200 MiB.
    Partition #2 contains a ext2 signature.
    
    Do you want to remove the signature? [Y]es/[N]o: y
    
    The signature will be removed by a write command.
    
    Command (m for help): n
    Partition number (3-128, default 3):
    First sector (415744-250069646, default 415744):
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (415744-250069646, default 250069646): +8G
    
    Created a new partition 3 of type 'Linux filesystem' and of size 8 GiB.
    Partition #3 contains a swap signature.
    
    Do you want to remove the signature? [Y]es/[N]o: y
    
    The signature will be removed by a write command.
    
    Command (m for help): n
    Partition number (4-128, default 4):
    First sector (17192960-250069646, default 17192960):
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (17192960-250069646, default 250069646):
    
    Created a new partition 4 of type 'Linux filesystem' and of size 111 GiB.
    Partition #4 contains a ext4 signature.
    
    Do you want to remove the signature? [Y]es/[N]o: y
    
    The signature will be removed by a write command.
    
    Command (m for help):
    
    
    Command (m for help): w
    
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
  20. 格式化分区

    [email protected] ~ # partprobe /dev/sda
    1 [email protected] ~ # mkfs.ext4 /dev/sda1
    [email protected] ~ # mkfs.ext2 /dev/sda2
    [email protected] ~ # mkswap /dev/sda3
    [email protected] ~ # mkfs.ext4 /dev/sda4
  21. 挂载文件系统

    分区 挂载点
    sda4 /
    sda2 /boot
    sda3 swap
    [email protected] ~ # mount /dev/sda4 /mnt
    [email protected] ~ # mkdir /mnt/boot
    [email protected] ~ # mount /dev/sda2 /mnt/boot
    [email protected] ~ # swapon /dev/sda3
    [email protected] ~ # swapon -a
    [email protected] ~ # swapon -s
    Filename                Type        Size    Used    Priority
    /dev/sda3                               partition   8388604 0   -2
    [email protected] ~ #
  22. 因为我们在步骤 14 有重启过系统,需要再次执行步骤 8,配置源。

  23. 刷新源

    [email protected] ~ # pacman -Syy
  24. 安装基本的 package

    [email protected] ~ # pacstrap /mnt base base-devel

    注:此步稍费时,去喝杯咖啡~

  25. chroot 环境下的配置:

    [email protected] ~ # arch-chroot /mnt
    [[email protected] /]# pacman -S vim

    注:安装 vim 编辑器,利于编辑(可选择任意你喜欢的编辑器即可)。

    1. 时区、时间配置

      [[email protected] /]# ln -sf /usr/share/zoneinfo/Asia/Beijing /etc/localtime
      [[email protected] /]# hwclock --systohc
    2. 主机名配置

      [[email protected] /]# vim /etc/hostname
    3. 本地化设置

      [[email protected] /]# vim /etc/locale.gen

      把 locale.gen 文件内的

      #en_US.UTF-8 UTF-8
      #zh_CN.UTF-8 UTF-8

      前边的注释符号 # 删除,使该语句生效。

      en_US.UTF-8 UTF-8
      zh_CN.UTF-8 UTF-8
    4. 执行下列语句使步骤 3 生效

      [[email protected] /]# locale-gen
    5. 配置 fstab。执行此步骤需要暂时退出 arch-chroot

      [[email protected] /]# exit
      exit
      arch-chroot /mnt  7.39s user 0.86s system 0% cpu 18:25.04 total
      [email protected] ~ # genfstab -U /mnt > /mnt/etc/fstab
      [email protected] ~ # cat /mnt/etc/fstab
      # /dev/sda4
      UUID=cc6af4fb-f72b-47a2-9a41-6e5253bf0167    /           ext4        rw,relatime 0 1
      
      # /dev/sda2
      UUID=bce9b3fa-b6ad-45ad-918f-5b3a46b3a04d    /boot       ext2        rw,relatime,block_validity,barrier,user_xattr,acl   0 2
      
      # /dev/sda3
      UUID=c9b5a804-988b-4a7c-8519-a1e3fe63554c    none        swap        defaults,pri=-2 0 0
      
      [email protected] ~ #
    6. 配置 grub。需要再次进入 arch-chroot

      [email protected] ~ # arch-chroot /mnt
      [[email protected] /]# pacman -S grub
    7. 网络配置

      我们可以安装 networkmanager 包来管理我们的网络:

      [[email protected] /]# pacman -S networkmanager

      启用 NetworkManager

      [[email protected] /]# sudo systemctl enable NetworkManager
      [[email protected] /]# sudo systemctl start NetworkManager
    8. 安装 openssh 并设置为开机启动

      [[email protected] /]# pacman -S openssh
      [[email protected] /]# sudo systemctl enable sshd
      Created symlink /etc/systemd/system/multi-user.target.wants/sshd.service → /usr/lib/systemd/system/sshd.service.
      [[email protected] /]# sudo systemctl start sshd
      Running in chroot, ignoring request: start
    9. 用户及权限配置

      1. 设置 root 用户密码

        [[email protected] /]# passwd
        New password:
        Retype new password:
        passwd: password updated successfully
      2. 配置 sudoers 文件

        [[email protected] /]# vim /etc/sudoers

        # %wheel ALL=(ALL) NOPASSWD: ALL 语句前边的注释符 # 删掉,:q! 强制保存退出。

      3. 添加一个与 root 同一个组的用户,并给该用户创建密码

        [[email protected] /]# useradd -m -G wheel eric
        [[email protected] /]# id eric
        uid=1000(eric) gid=1000(eric) groups=1000(eric),998(wheel)
        [[email protected] /]# passwd eric
        New password:
        Retype new password:
        passwd: password updated successfully
        [[email protected] /]#
    10. 再次配置 grub

    [[email protected] /]# grub-install /dev/sda
    Installing for i386-pc platform.
    grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
    grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
    grub-install: error: will not proceed with blocklists.

    发现执行错误。参考此帖,这里也是解释了为什么步骤 19-1 我们要分配 2M 的分区 /dev/sda1

    执行:

    [[email protected] /]# pacman -S parted
    [[email protected] /]# parted /dev/sda set 1 bios_grub on
    Information: You may need to update /etc/fstab.
    
    [[email protected] /]# parted /dev/sda print
    Model: ATA Lenovo SSD SL700 (scsi)
    Disk /dev/sda: 128GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags:
    
    Number  Start   End     Size    File system     Name  Flags
     1      1049kB  3146kB  2097kB  ext4                  bios_grub
     2      3146kB  213MB   210MB   ext2
     3      213MB   8803MB  8590MB  linux-swap(v1)
     4      8803MB  128GB   119GB   ext4
    
    [[email protected] /]#

    再次执行下列语句

    [[email protected] /]# grub-install /dev/sda
    Installing for i386-pc platform.
    Installation finished. No error reported.
    [[email protected] /]# grub-mkconfig -o /boot/grub/grub.cfg
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-linux
    Found initrd image: /boot/initramfs-linux.img
    Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
    done
    [[email protected] /]#

    成功。

    1. 安装 neofetch

      [[email protected] /]# pacman -S neofetch

      通过下边这条命令我们发现 arch Linux 基本已经安装好了:

      [[email protected] /]# neofetch
                         -`                    [email protected]
                        .o+`                   ------------
                       `ooo/                   OS: Arch Linux x86_64
                      `+oooo:                  Host: IdeaPad Y460 Rev 1.0
                     `+oooooo:                 Kernel: 4.20.6-arch1-1-ARCH
                     -+oooooo+:                Uptime: 2 hours, 9 mins
                   `/:-:++oooo+:               Packages: 186 (pacman)
                  `/++++/+++++++:              Shell: bash 5.0.0
                 `/++++++++++++++:             Terminal: /dev/pts/0
                `/+++ooooooooooooo/`           CPU: Intel i3 M 380 (4) @ 2.533GHz
               ./ooosssso++osssssso+`          GPU: Intel Core Processor
              .oossssso-````/ossssss+`         GPU: NVIDIA GeForce GT 425M
             -osssssso.      :ssssssso.        Memory: 247MiB / 3743MiB
            :osssssss/        osssso+++.
           /ossssssss/        +ssssooo/-
         `/ossssso+/:-        -:/+osssso+-
        `+sso+:-`                 `.-/+oso:
       `++:.                           `-/+/
       .`                                 `/
      
      [[email protected] /]#
    2. 退出 arch-chroot 环境。配置 NetworkManageropenssh 开机自启

      [[email protected] /]# exit
      exit
      arch-chroot /mnt  9.40s user 4.36s system 0% cpu 1:02:26.92 total
      [email protected] ~ # sudo systemctl start NetworkManager
      Failed to start NetworkManager.service: Unit NetworkManager.service not found.
      5 [email protected] ~ # sudo systemctl start sshd                                                      :(
      [email protected] ~ #
    3. 关闭 /mnt 下的所有挂载点,重启计算机

      [email protected] ~ # umount -R /mnt
      [email protected] ~ # reboot

      注:reboot 命令执行会关闭待装主机,主机关机时(重启前)拔下 U 盘。如果没来得及拔掉,直接用物理关机键强制关机,拔下 U 盘,然后开机。

  26. 留作扩充

  27. 参考帖子

    Archlinux安装第一部分

    解决Linux安装过程中不能安装Grub的问题

    以官方Wiki的方式安装ArchLinux

    Arch Linux 怎么安装?

以上是关于arch Linux的主要内容,如果未能解决你的问题,请参考以下文章

Vmware安装Arch Linux

Android内核源码bionic目录下的子目录arch-arm源码分析笔记

Linux 内核Linux 内核源码目录说明 ① ( arch 目录 | block 目录 | certs 目录 | crypto 目录 | Documentation 目录 )

Arch LINux 上未定义 O_DIRECT

Arch linux操作系统安装教程

linux内核配置与编译