Linux(CentOS 7)服务器增加固态硬盘作为系统盘


更新日期:2020年11月4日
一台电脑需要装系统,开机不显示主板界面直接进系统,查资料后,开机一直按着‘Del’键(Delete键),成功进入BIOS

在BIOS标签下,设置u盘为第一启动盘,保存设置,重启


在实际操作前先做一下理论上的准备

总结:机器上装固态、装系统基本上没用什么命令,比在阿里云上加硬盘简单些。

可能用到的命令

1. fdisk -l查看分区(partition)表

fdisk -help
Usage:
 fdisk [options] <disk>    change partition table(修改分区表)
 fdisk [options] -l <disk> list partition table(s)
 fdisk -s <partition>      give partition size(s) in blocks

Options:
 -b <size>             sector(扇区) size (512, 1024, 2048 or 4096)
 -c[=<mode>]           compatible mode(兼容模式): 'dos' or 'nondos' (default)
 -h                    print this help text(等价于-help)
 -u[=<unit>]           display units(显示单元): 'cylinders(柱面数)' or 'sectors(扇区数)' (default)
 -v                    print program version
 -C <number>           specify the number of cylinders(指定柱面数)
 -H <number>           specify the number of heads(指定磁头数)
 -S <number>           specify the number of sectors per track(指定每个磁道的扇区数)

2. umount -l绝大多数情况下一定会有效的卸载分区方式

Usage:
 umount [-hV]
 umount -a [options]
 umount [options] <source> | <directory>

Options:
 -a, --all               unmount all filesystems(卸载所有文件系统)
 -A, --all-targets       unmount all mountpoins for the given device
                         in the current namespace(卸载当前命名空间下指定设备的所有挂载点)
 -c, --no-canonicalize   don't canonicalize paths(不规范化路径)
 -d, --detach-loop       if mounted loop device, also free this loop device(如果挂载了循环设备,也释放这个循环设备)
     --fake              dry run; skip the umount(2) syscall(演示:跳过umount(2))
 -f, --force             force unmount (in case of an unreachable NFS system)(在无法访问NFS时进行强制卸载)
 -i, --internal-only     don't call the umount.<type> helpers
 -n, --no-mtab           don't write to /etc/mtab(不要写入这个路径)
 -l, --lazy              detach the filesystem now, and cleanup all later(现在分离这个文件系统同时清理所有进程)
 -O, --test-opts <list>  limit the set of filesystems (限制文件系统集)(use with -a)
 -R, --recursive         recursively unmount a target with all its children(递归卸载一个目标及其所有子对象)
 -r, --read-only         In case unmounting fails, try to remount read-only(如果卸载失败,请尝试以只读的方式重新挂载)
 -t, --types <list>      limit the set of filesystem types
 -v, --verbose           say what is being done

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see umount(8).

3. fdisk <分区名称>修改分区表

例如:fdisk /dev/vda

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m
Command action
   a   toggle a bootable flag(切换一个启动标志)
   b   edit bsd disklabel(编辑磁盘标签)
   c   toggle the dos compatibility flag(切换dos兼容性标志)
   d   delete a partition(删除一个分区)
   g   create a new empty GPT partition table(创建一个新的空GTP分区表)
   G   create an IRIX (SGI) partition table(创建一个IRIX(SGI)分区表)
   l   list known partition types(列出已知的分区类型)
   m   print this menu(打印这个主菜单)
   n   add a new partition(添加一个新分区)
   o   create a new empty DOS partition table(创建一个新的空DOS分区表)
   p   print the partition table(打印分区表)
   q   quit without saving changes(不保存更改 退出)
   s   create a new empty Sun disklabel(创建一个新的空Sun磁盘标签)
   t   change a partition's system id(更改分区的系统ID)
   u   change display/entry units(改变显示/输入单元)
   v   verify the partition table(验证分区表)
   w   write table to disk and exit(将分区表写入磁盘 退出)
   x   extra functionality (experts only)(额外功能(仅限专家))

参考资料:df,dh,fdisk,lsblk区别

通知内核更新分区表。

运行partprobe <数据盘设备名>或者partx -u <数据盘设备名>,通知内核数据盘的分区表已经修改,需要同步更新。

4. fsck和e2fsck

FSCK(8)                           System Administration                          FSCK(8)

NAME
       fsck - check and repair a Linux filesystem

SYNOPSIS
       fsck  [-lrsAVRTMNP]  [-C  [fd]]  [-t  fstype] [filesystem...]  [--] [fs-specific-
       options]

DESCRIPTION
       fsck is used to check and  optionally  repair  one  or  more  Linux  filesystems.
       filesys  can  be  a device name (e.g.  /dev/hdc1, /dev/sdb2), a mount point (e.g.
       /,   /usr,   /home),   or   an   ext2   label    or    UUID    specifier    (e.g.
       UUID=8868abf6-88c5-4a83-98b8-bfc24057f7bd  or  LABEL=root).   Normally,  the fsck
       program will try to handle filesystems on different physical disk drives in  par‐
       allel to reduce the total amount of time needed to check all of them.

       If  no  filesystems  are  specified on the command line, and the -A option is not
       specified, fsck will default to  checking  filesystems  in  /etc/fstab  serially.
       This is equivalent to the -As options.

       The exit code returned by fsck is the sum of the following conditions:

              0      No errors
              1      Filesystem errors corrected
              2      System should be rebooted
              4      Filesystem errors left uncorrected

5. fdisk和lsblk

总结:fdis可以操作分区表;lsblk只能以文件的形式查看设备(block service)
fdisk:

FDISK(8)                          System Administration                         FDISK(8)

NAME
       fdisk - manipulate disk partition table(操作磁盘分区表)

SYNOPSIS
       fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device

       fdisk -l [-u] [device...]

       fdisk -s partition...

       fdisk -v

       fdisk -h

DESCRIPTION
       fdisk (in the first form of invocation) is a menu-driven program for creation and
       manipulation of partition tables. 
       (fdisk(第一种调用形式)是一个菜单驱动程序,用于创建和操作分区表。)
        It understands  GPT  (experimental  for  now), MBR, Sun, SGI and BSD partition tables.
        (它理解GPT(目前还处于试验阶段)、MBR、Sun、SGI和BSD分区表。)

       fdisk does not use DOS-compatible mode and cylinders as display units by default.
       (默认情况下,磁盘不使用与dos兼容的模式和柱面作为显示单元。)
       The old deprecated DOS behavior can be enabled  with  the  '-c=dos  -u=cylinders'
       command-line options.
       (可以通过命令行选项'-c= DOS -u=cylinder '来启用旧的已弃用的DOS模式。)

       Hard disks can be divided into one or more logical disks called partitions.
       (硬盘可以被划分为一个或多个逻辑磁盘,称为分区。)  
       This division is recorded in the partition table, found in sector 0 of the disk.
       这个分区记录在磁盘扇区0中的分区表中。  
        (In the BSD world one talks about `disk slices' and a `disklabel'.)
		(在BSD领域中有人称其为“磁盘片”和“磁盘标签”。)

      Linux  needs at least one partition, namely for its root file system.
       (Linux至少需要一个分区,即用于它的根文件系统。)
      It can use swap files and/or swap partitions, but the latter are more efficient. 
       (它可以使用交换文件 和/或 交换分区,但是后者更有效。)
      So,  usually  one  will  want  a  second Linux partition dedicated as swap partition. (因此,通常需要一个专用的Linux分区作为交换分区。)
      On Intel-compatible hardware, the BIOS that boots the system can often  only  access
      the  first  1024  cylinders of the disk.(在intel兼容的硬件上,引导系统的BIOS通常只能访问磁盘的前1024个柱面。)
      For this reason people with large disks often create a third partition, just a few MB large, typically mounted on  /boot, to store the kernel image and a few auxiliary files needed at boot time, so as to make sure that this stuff is accessible to the BIOS.  
    (因此,拥有大磁盘的人通常会创建第三个分区,只有几MB大,通常挂载在/boot上,以存储内核映像和引导时需要的一些辅助文件,以便确保BIOS可以访问这些文件。)
	  There  may  be  reasons  of security,  ease  of  administration  and backup, or testing, to use more than the minimum number of partitions.
     (可能出于安全性、易于管理和备份或测试的原因,使用的分区数量超过了最小分区数。)

DEVICES
       The device is usually /dev/sda, /dev/sdb or so.  A  device  name  refers  to  the
       entire  disk.  Old systems without libata (a library used inside the Linux kernel
       to support ATA host controllers and devices) make a difference  between  IDE  and
       SCSI  disks.   In  such  cases the device name will be /dev/hd* (IDE) or /dev/sd*
       (SCSI).
       The partition is a device name followed by  a  partition  number.   For  example,
       /dev/sda1  is the first partition on the first hard disk in the system.  See also
       Linux kernel documentation (the Documentation/devices.txt file).

lsblk:

LSBLK(8)                          System Administration                         LSBLK(8)

NAME
       lsblk - list block devices(列出设备文件)

SYNOPSIS
       lsblk [options] [device...]

DESCRIPTION
       lsblk  lists information about all available or the specified block devices. (lsblk列出关于所有可用的或指定的块设备的信息。) The
       lsblk command reads the sysfs filesystem to gather information.(lsblk命令读取sysfs文件系统以收集信息。)

       The command prints all block devices (except RAM disks) in a tree-like format  by
       default.(该命令默认情况下以类似树的格式打印所有块设备(RAM磁盘除外)。)  Use lsblk --help to get a list of all available columns.(使用lsblk——帮助获取所有可用列的列表。)

       The  default  output,  as  well  as the default output from options like --fs and
       --topology, is subject to change. (默认输出以及--fs和--topology等选项的默认输出都可以更改。) So whenever possible, you should  avoid  using
       default  outputs  in  your scripts. (因此,只要可能,您应该避免在脚本中使用默认输出。) Always explicitly define expected columns by
       using --output columns-list in environments where a stable output is required.(在需要稳定输出的环境中,始终使用--output columns-list显式定义预期的列。)

OPTIONS
       -a, --all
              Also list empty devices.  (By default they are skipped.)

       -b, --bytes
              Print the SIZE column in bytes rather than in a human-readable format.

6.格式化分区 mkfs、mkfs.ext3、mke2fs

mkfs:make filesystem的缩写
总结:mkfs是一系列构建分区工具的前端,实际执行mkfs过程中根据要构建的文件系统类型,调用对应的工具,例如mkfs.ext3、mkfs.ext2调用的是mke2fs

MKFS(8)                           System Administration                          MKFS(8)

NAME
       mkfs - build a Linux filesystem(构建Linux文件系统)

SYNOPSIS
       mkfs [options] [-t type] [fs-options] device [size]

DESCRIPTION
       mkfs  is used to build a Linux filesystem on a device, usually a hard disk parti‐
       tion. 
       (mkfs用于在设备(通常是硬盘部件)上构建Linux文件系统。)  
       The  device  argument  is  either  the  device  name  (e.g.    /dev/hda1,/dev/sdb2),  
       or a regular file that shall contain the filesystem. 
       (设备参数要么是设备名称(例如/dev/hda1、/dev/sdb2),要么是一个包含文件系统的常规文件。) 
       The size argument is the number of blocks to be used for the filesystem.
       (大小参数是用于文件系统的块数。)

       The exit code returned by mkfs is 0 on success and 1 on failure.
       (mkfs返回的退出代码成功时为0,失败时为1。)

       In actuality, mkfs is simply a front-end  for  the  various  filesystem  builders
       (mkfs.fstype) available under Linux. 
       (实际上,mkfs只是Linux下可用的各种文件系统构建器(mkfs.fstype)的前端。) 
       The filesystem-specific builder is searched for in a  number  of  directories,  
       like  perhaps  /sbin,  /sbin/fs,  /sbin/fs.d, /etc/fs,  /etc (the precise list is defined 
       at compile time but at least contains /sbin and /sbin/fs), and finally in the 
       directories listed in the  PATH  environment  variable.
       (特定于文件系统的构建器在许多目录中搜索,比如/sbin、/sbin/fs、/sbin/fs.d, /etc/fs, /etc(精确的列表是在编译时定义的,但至少包含/sbin和/sbin/fs),最后在PATH环境变量中列出的目录中。)  
       Please see the filesystem-specific builder manual pages for fur‐
       ther details.(详细信息请参见特定于文件系统的构建器手册页面。)

OPTIONS
       -t, --type type
              Specify the type of filesystem to be built.  If not specified, the default
              filesystem type (currently ext2) is used.
              (指定要构建的文件系统的类型。如果未指定,则使用默认的文件系
              统类型(当前为ext2)。)

       fs-options
              Filesystem-specific  options  to be passed to the real filesystem builder.
              Although not guaranteed, the  following  options  are  supported  by  most
              filesystem builders.
              (特定于文件系统的选项被传递给真正的文件系统构建器。虽然没有得到
              保证,但大多数文件系统构建器都支持以下选项。)

       -V, --verbose
              Produce  verbose  output,  including all filesystem-specific commands that
              are executed.  Specifying this option more than once inhibits execution of
              any filesystem-specific commands.  This is really only useful for testing.

       -V, --version
              Display  version  information  and  exit.  (Option -V will display version
              information only when it is the only parameter, otherwise it will work  as
              --verbose.)

       -h, --help
              Display help and exit.
MKE2FS(8)                        System Manager's Manual                       MKE2FS(8)

NAME
       mke2fs - create an ext2/ext3/ext4 filesystem(创建ext2/ext3/ext4文件系统)

SYNOPSIS
       mke2fs  [  -c  | -l filename ] [ -b block-size ] [ -D ] [ -f fragment-size ] [ -g
       blocks-per-group ] [ -G number-of-groups ] [ -i bytes-per-inode ] [ -I inode-size
       ]  [  -j  ]  [ -J journal-options ] [ -N number-of-inodes ] [ -n ] [ -m reserved-
       blocks-percentage ] [ -o creator-os ] [ -O feature[,...]  ] [ -q ] [ -r  fs-revi‐
       sion-level ] [ -E extended-options ] [ -v ] [ -F ] [ -L volume-label ] [ -M last-
       mounted-directory ] [ -S ] [ -t fs-type ] [ -T usage-type ] [ -U UUID ]  [  -V  ]
       device [ blocks-count ]

       mke2fs  -O journal_dev [ -b block-size ] [ -L volume-label ] [ -n ] [ -q ] [ -v ]
       external-journal [ blocks-count ]

DESCRIPTION
       mke2fs is used to create an ext2, ext3, or ext4 filesystem,  usually  in  a  disk
       partition.   
       (mke2fs用于创建ext2、ext3或ext4文件系统,通常在磁盘分区中。)
       device  is  the  special  file  corresponding  to  the  device  (e.g
       /dev/hdXX).  
       (设备是设备对应的特殊文件)
       blocks-count is the number of blocks on  the  device.  (块计数是设备上的块数)
        If  omitted,mke2fs  automagically  figures  the  file  system size.  If called as 
        mkfs.ext3 a journal is created as if the -j option was specified.
        (如果省略,mke2fs自动绘制文件系统大小。如果作为mkfs调用。
        ext3日志被创建,就像指定了-j选项一样)

       The defaults of the parameters for the newly created filesystem, if not  overrid‐
       den  by the options listed below, are controlled by the /etc/mke2fs.conf configu‐
       ration file.
       (新创建的文件系统的默认参数,如果没有下面列出的选项的overrid‐den,
       则由/etc/mke2fs.conf配置‐ration文件控制。)
         See the mke2fs.conf(5) manual page for more details.

7.mount A B 将分区A挂载到位置B

-V, --version  output version information and exit

Source:
 -L, --label <label>     synonym for LABEL=<label>
 -U, --uuid <uuid>       synonym for UUID=<uuid>
 LABEL=<label>           specifies device by filesystem label(按文件系统标签指定设备)
 UUID=<uuid>             specifies device by filesystem UUID(按文件系统UUID指定设备)
 PARTLABEL=<label>       specifies device by partition label(按分区标签指定设备)
 PARTUUID=<uuid>         specifies device by partition UUID(按分区UUID指定设备)
 <device>                specifies device by path(按路径指定设备)
 <directory>             mountpoint for bind mounts (see --bind/rbind)(用于挂载设备的挂载点)
 <file>                  regular file for loopdev setup(用于设置loopdev的常规文件)

Operations:
 -B, --bind              mount a subtree somewhere else (same as -o bind)
 -M, --move              move a subtree to some other place
 -R, --rbind             mount a subtree and all submounts somewhere else
 --make-shared           mark a subtree as shared
 --make-slave            mark a subtree as slave
 --make-private          mark a subtree as private
 --make-unbindable       mark a subtree as unbindable
 --make-rshared          recursively mark a whole subtree as shared
 --make-rslave           recursively mark a whole subtree as slave
 --make-rprivate         recursively mark a whole subtree as private
 --make-runbindable      recursively mark a whole subtree as unbindable

For more details see mount(8).

8.设置开机自动挂载:vi /etc/fstab

思路

  1. 备份数据
  2. 服务器关机
  3. 拔下旧硬盘
  4. 插上新硬盘
  5. 进入BIOS,设置启动引导方式
  6. 安装CentOS7系统
  7. 系统配置
  8. 关机
  9. 插上旧硬盘
  10. 将旧硬盘作为数据盘进行挂载
  11. 设置开机自动挂载
  12. 完成

总结

先总结这次过程中一些操作导致的麻烦问题

问题1: 初始root密码设置的有些复杂,导致后面系统装成功后,总是提示密码错误

没办法,只能再次重装

解决办法:测试用的root密码设简单点就好…( _ _)ノ|

问题2:新系统盘和旧系统盘同时连上,想进入光盘引导程序的安装界面时提示“There is a problem with your existing storage configuration: multiple LVM volume groups with the same name”

在这里插入图片描述
原因:存在多个相同名称的LVM卷组
解决方法:按下ctrl-alt-f1 和 ctrl-b进入引导安装界面的命令行界面如下图,键入命令pvs -o +vg_uuid查看现有的LVM卷组,发现两者名称相同,使用命令vgrame <VG_UUID> vg1将其中一个LVM卷组的名称改为vg1。最后重启就可以正常进入引导安装界面
在这里插入图片描述
参考资料:https://mellowhost.com/billing/index.php?rp=/knowledgebase/84/How-to-Rename-Volume-Group-when-there-are-multiple-Volume-Group-with-the-same-name.html

问题3:两个系统启动顺序设置

将新固态盘的SATA接口接在主板SATA接口1的位置
开机根据屏幕上提示的进入BIOS快捷键,进入BIOS界面。
在菜单栏中找到BOOT,进入
在这里插入图片描述
找到boot option#1选项,回车,设置第一启动方式(还可以通过Add New Boot Option选项增加其它顺序的启动选项)

设置完后,找到save&exit菜单,在里面找到保存退出的选项,保存并退出

问题4:安装光盘中仅有最简化安装CentOS 7一个选项,最简化安装的系统需要配置一下才能联网

查看IP信息,ip addr
发现仅有1:lo:<LOOPBACK,UP,LOWER_UP>
和 2:ens33(网卡名,下一步会用到):等信息
看不到IP,说明网卡没有启动

进入网络配置文件目录cd /etc/sysconfig/network-scripts
使用ls查看该路径下的文件,使用vi ens33(网卡名)进行编辑,设置ON_BOOT=''yes''开机启用,其它保持不变即可。(我这边有路由会根据MAC地址自动分配指定IP,所以不用设置静态IP)

重启后,使用命令ping www.baidu.com发现可以ping通,联网成功

过程

装系统没有什么太多的步骤,在划分分区时根据需求进行划分即可。
可以浏览这篇文章:传送门

最简化系统装好,可以联网能用yum后,直接装个图形界面吧,会很省劲儿!
yum groupinstall "GNOME Desktop" "Graphical Administration Tools"

启动命令:
startx
参考文章:传送门

  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值