阿里云/腾讯云等VPS重装Rocky Linux 10的步骤

先要装一个旧版本的Centos 7.9,然后开始新装系统

步骤 1: 使用 GParted 分割现有分区

工具选择:GParted 是图形化分区工具,支持在线分区操作,适合 Linux 系统。

操作步骤:

  1. 下载 GParted Live:
    # cd /mnt
    # wget https://sourceforge.net/projects/gparted/files/gparted-live-stable/1.7.0-12/gparted-live-1.7.0-12-amd64.iso
  2. 使用GRUB将GParted Live安装到硬盘,创建 grub2 自定义文件 /etc/grub.d/40_custom,内容如下:
    menuentry "Gparted live" {
      set isofile="/mnt/gparted-live-1.7.0-12-amd64.iso"
      loopback loop $isofile
      linux (loop)/live/vmlinuz boot=live config union=overlay username=user components noswap noeject vga=788 ip= net.ifnames=0 toram=filesystem.squashfs findiso=$isofile
      initrd (loop)/live/initrd.img
    }
  3. 更新您的 grub2 配置:
    # grub2-mkconfig -o /boot/grub2/grub.cfg
  4. 分区操作(尽量将iso安装分区弄到最后一个分区,也就是分区4):
    • 选择要分割的主分区(如 /dev/sda2)。
    • 右键点击分区 → Resize/Move。
    • 调整分区大小,释放出至少 2GB 未分配空间。
    • 点击 Resize/Move → Apply。
    • 重启
  5. 格式化新分区并挂载:
    mkfs.ext4 /dev/vda4 # 格式化为 ext4 文件系统
    mkdir /mnt/iso_install
    mount /dev/vda4 /mnt/iso_install

步骤 2: 分配目录并下载 ISO 文件

将 Rocky Linux 10 的 ISO 镜像下载到刚刚创建的新分区挂载点。

  1. 下载 ISO:
    cd /mnt/iso_install
    # 请确认 Rocky Linux 10.1 已正式发布,目前最新版可能是 10 Beta 或其他版本。
    # 假设该链接有效:
    wget https://download.rockylinux.org/pub/rocky/10/isos/x86_64/Rocky-10.1-x86_64-minimal.iso

步骤 3: 修改 GRUB 启动 ISO

这是最复杂且最容易出错的一步。您需要修改当前系统的引导加载程序 GRUB,使其在下次启动时引导 ISO 文件中的安装内核,而不是当前系统。

定位 GRUB 配置文件: 通常在 /etc/default/grub/boot/grub/grub.cfg

创建自定义 GRUB 配置条目:

  1. 使用lsblk获得uuid, 使用fdisk获得分区类型(msdos或者gpt)以及第几分区:
    # lsblk -f
    NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
    vda
    ├─vda1 ext4         c8b5b2da-5565-4dc1-b002-2a8b07573e22 /
    ├─vda2 ext4         8f0484e1-9f99-4932-8639-1fcb32417376
    ├─vda3 ext4         3556fbff-c61b-4e9c-864c-dc5c1d772277
    └─vda4 ext4         e15d6a20-ac3e-4385-a784-2914ab270a85 /mnt/iso_install
    
    # fdisk -l
    
    Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000edc45
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048    79691775    39844864   83  Linux
    /dev/vda2        79691776    79693823        1024   83  Linux
    /dev/vda3        79693824    79695871        1024   83  Linux
    /dev/vda4        79695872    83886079     2095104   83  Linux
  2. /etc/grub.d/40_custom 文件末尾添加一个新的启动项。
    vi /etc/grub.d/40_custom
  3. 添加以下内容(根据您的分区和 ISO 文件名调整, 新分区的 UUID,并替换上述 [YOUR_VDA4_UUID]):
    menuentry "Install Rocky Linux 10 via ISO Final" {
        set isofile="/Rocky-10.1-x86_64-minimal.iso"
        
        # 查找 UUID 为 [YOUR_VDA4_UUID] 的分区
        search --no-floppy --fs-uuid [YOUR_VDA4_UUID] --set=root
    
        # 挂载 ISO 文件
        loopback loop ($root)$isofile
    
        # !! 使用正确的路径 /images/pxeboot/vmlinuz !!
        # inst.stage2 参数告诉安装程序去哪里找安装文件
        linux (loop)/images/pxeboot/vmlinuz inst.stage2=hd:UUID=[YOUR_VDA4_UUID]:/ rhgb quiet
    
        # !! 使用正确的路径 /images/pxeboot/initrd.img !!
        initrd (loop)/images/pxeboot/initrd.img
    }
  4. 更新 GRUB 配置: 运行命令生成新的 grub.cfg。
    grub2-mkconfig -o /boot/grub2/grub.cfg
    # 如果您的系统使用旧版 GRUB: update-grub
  5. 重启 VPS
    reboot

进入安装界面: 重启后,您通常需要通过 VPS 提供商的 VNC 或 Web 控制台快速进入 GRUB 菜单,选择您刚刚添加的 “Install Rocky Linux 10 via ISO” 选项。

执行安装: 按照 Rocky Linux 安装程序的提示进行安装。在分区步骤,确保您将旧的系统分区格式化,并正确配置新的挂载点。

步骤 4: 回收 ISO 分区

  1. 使用 fdisk 删除 vda4 并创建新的 Swap 分区
    # fdisk /dev/vda
    
    Welcome to fdisk (util-linux 2.40.2).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    This disk is currently in use - repartitioning is probably a bad idea.
    It's recommended to umount all file systems, and swapoff all swap
    partitions on this disk.
    
    Command (m for help): p
    
    Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
    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: dos
    Disk identifier: 0x000edc45
    
    Device     Boot    Start      End  Sectors  Size Id Type
    /dev/vda1  *        2048  2099199  2097152    1G 83 Linux
    /dev/vda2        2099200 71723007 69623808 33.2G 83 Linux
    /dev/vda4       79695872 83886079  4190208    2G 83 Linux
    
    Command (m for help): d
    Partition number (1,2,4, default 4): 4
    
    Partition 4 has been deleted.
    
    Command (m for help): p
    Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
    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: dos
    Disk identifier: 0x000edc45
    
    Device     Boot   Start      End  Sectors  Size Id Type
    /dev/vda1  *       2048  2099199  2097152    1G 83 Linux
    /dev/vda2       2099200 71723007 69623808 33.2G 83 Linux
    
    Command (m for help): n
    Partition type
       p   primary (2 primary, 0 extended, 2 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (3,4, default 3):
    First sector (71723008-83886079, default 71723008): 75916900
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (75916900-83886079, default 83886079):
    
    Created a new partition 3 of type 'Linux' and of size 3.8 GiB.
    
    Command (m for help): t
    Partition number (1-3, default 3):
    Hex code or alias (type L to list all): 82
    
    Changed type of partition 'Linux' to 'Linux swap / Solaris'.
    
    Command (m for help): w
    The partition table has been altered.
    Syncing disks.
  2. 重启系统

    分区表修改后,您必须重启系统才能使内核识别新的分区布局。

    reboot

    重启后,通过 VNC 重新连接。

  3. 格式化并启用 Swap 分区

    现在 /dev/vda3 应该是一个 Swap 分区了。

    mkswap /dev/vda3
    swapon /dev/vda3
  4. 永久挂载 Swap

    编辑 /etc/fstab 文件,使 Swap 在每次启动时自动挂载。

    vi /etc/fstab

    在文件末尾添加以下行:

    /dev/vda3   swap    swap    defaults        0 0
  5. 扩展 vda2 文件系统(最复杂的一步)
    # fdisk /dev/vda
    
    Welcome to fdisk (util-linux 2.40.2).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    This disk is currently in use - repartitioning is probably a bad idea.
    It's recommended to umount all file systems, and swapoff all swap
    partitions on this disk.
    
    Command (m for help): p
    
    Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
    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: dos
    Disk identifier: 0x000edc45
    
    Device     Boot    Start      End  Sectors  Size Id Type
    /dev/vda1  *        2048  2099199  2097152    1G 83 Linux
    /dev/vda2        2099200 71723007 69623808 33.2G 83 Linux
    /dev/vda3       75916900 83886079  7969180  3.8G 82 Linux swap / Solaris
    
    Command (m for help): e
    Partition number (1-3, default 3): 2
    
    New <size>{K,M,G,T,P} in bytes or <size>S in sectors (default 35.2G):
    
    Partition 2 has been resized.
    
    Command (m for help): p
    Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
    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: dos
    Disk identifier: 0x000edc45
    
    Device     Boot    Start      End  Sectors  Size Id Type
    /dev/vda1  *        2048  2099199  2097152    1G 83 Linux
    /dev/vda2        2099200 75916899 73817700 35.2G 83 Linux
    /dev/vda3       75916900 83886079  7969180  3.8G 82 Linux swap / Solaris
    
    Command (m for help): F
    
    Unpartitioned space /dev/vda: 0 B, 0 bytes, 0 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    
    Command (m for help): w
    The partition table has been altered.
    Syncing disks.
    
    # 扩展文件系统到最大可用空间
    sudo xfs_growfs /dev/vda2
    
    #  验证扩容结果
    df -hT /dev/vda2
    文件系统       类型  大小  已用  可用 已用% 挂载点
    /dev/vda2      xfs    36G  1.8G   34G    6% /

至此全新Rocky Linux 10已经安装完毕,剩下就是标准配置了.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理