ubuntu20.04挂载拓展盘保姆级流程

背景:跑模型玩时,发现机子硬盘太小了,搞个1t固态作为挂载盘。以下为操作全流程记录

1、开始root权限操作

sudo su

若进不去,考虑是否给root设置过密码,新系统第一次进入需要设置密码。

进入成功:

root@y:/#

2、查看硬盘挂载情况

lsblk

3、将未分配的硬盘的创建分区

fdish /dev/sda	# 注意指令名称为2中表示的挂载盘名称
终端提示:
Command (m for help):输入:n
依次输入p 和 1
接着便会提示卷的起始地址和结束地址,都保持默认按回车的即可(意思是只分一个区)
输入“w”保存并推出

检测分区成功:fdish -l

Device     Start        End    Sectors   Size Type
/dev/sda1   2048 1953525134 1953523087 931.5G Linux filesystem

至此,/dev/sda盘以分区成功(sda1,是正常的)

参考

4、初始化为pv

pvcreate /dev/sda1

创建成功校验:

root@y:/# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda1
  VG Name               
  PV Size               931.51 GiB / not usable 4.69 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              238466
  Free PE               130
  Allocated PE          238336
  PV UUID               nvOIhv-ccpX-40nH-u9x0-ZXBu-Jgnv-s3RTg

5、创建卷组(vg)并把pv加入卷组中

vgcreate h /dev/sda1

创建成功校验:
root@y:/# vgdisplay 
  --- Volume group ---
  VG Name               h
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <931.51 GiB
  PE Size               4.00 MiB
  Total PE              238466
  Alloc PE / Size       238336 / 931.00 GiB
  Free  PE / Size       130 / 520.00 MiB
  VG UUID               YAy8nO-qfYK-5cZy-pFJz-ixAh-WVPZ-f3M4qV

6、基于卷组(vg)创建逻辑卷(lv)

lvcreate -n d -L 931G h

注意,d 是自己取的名字,931G是自己挂载盘的大小,此两根据个人情况调整

创建成功校验:

root@y:/# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/h/d
  LV Name                d
  VG Name                h
  LV UUID                712DiJ-DX8o-UINn-AUMT-REFm-UotT-nDUii7
  LV Write Access        read/write
  LV Creation host, time y, 2023-10-06 16:05:37 +0800
  LV Status              available
  # open                 1
  LV Size                931.00 GiB
  Current LE             238336
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

7、格式化逻辑卷并挂载

mkfs.ext4 /dev/h/d	# 格式化逻辑卷,需要给全路径
mount /dev/h/d /mnt	# 将已初始化的逻辑卷挂载到/mnt目录(该文件夹装系统时已自带且为空,可根据个人实际情况调整,注意给全路径)

参考

8、系统自动挂载操作

1)查看UUID与类型

sudo blkid

在打印输出查看挂载盘信息:

/dev/mapper/h-d: UUID="6b684323-82ca-47a9-bec9-d26b09364fdd" TYPE="ext4"

2)修改fstab文件

sudo vim /etc/fstab

目的添加

uuid	挂载文件夹	文件类型	defaults	0	2
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#                
# / was on /dev/nvme0n1p7 during installation
UUID=a80478f4-abf2-4354-9e01-5c986515f58d /               ext4    errors=remount-ro 0       1
# /boot was on /dev/nvme0n1p5 during installation
UUID=0eda1190-5b7f-4670-a18a-f09d81ab5937 /boot           ext4    defaults        0       2
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=A5EB-573A  /boot/efi       vfat    umask=0077      0       1
# /home was on /dev/nvme0n1p8 during installation
UUID=07093e4a-3b5c-4b14-ae7f-ff1b5cb5616d /home           ext4    defaults        0       2
# swap was on /dev/nvme0n1p6 during installation
UUID=d63a283a-2fab-4c0f-837c-20e47e9b81a5 none            swap    sw              0       0

# ylh_231006 /dev/mapper/h-d expand dish
UUID=6b684323-82ca-47a9-bec9-d26b09364fdd	/mnt	ext4	defaults	0	2

具体字段含义可参考

3)重启

reboot

4)校验自动挂载成功

(base) ylh@y:~$ df -lh
Filesystem       Size  Used Avail Use% Mounted on
udev              16G     0   16G   0% /dev
tmpfs            3.2G  2.2M  3.2G   1% /run
/dev/nvme0n1p7    47G   24G   21G  54% /
tmpfs             16G  252M   16G   2% /dev/shm
tmpfs            5.0M  4.0K  5.0M   1% /run/lock
tmpfs             16G     0   16G   0% /sys/fs/cgroup
/dev/loop0       128K  128K     0 100% /snap/bare/5
/dev/loop2        46M   46M     0 100% /snap/snap-store/638
/dev/loop1        64M   64M     0 100% /snap/core20/1828
/dev/loop3       205M  205M     0 100% /snap/cloudcompare/208
/dev/loop9       347M  347M     0 100% /snap/gnome-3-38-2004/119
/dev/loop4        56M   56M     0 100% /snap/core18/2790
/dev/loop5        64M   64M     0 100% /snap/core20/2015
/dev/loop8        50M   50M     0 100% /snap/snapd/18357
/dev/loop6        41M   41M     0 100% /snap/snapd/20092
/dev/loop7        92M   92M     0 100% /snap/gtk-common-themes/1535
/dev/loop10      350M  350M     0 100% /snap/gnome-3-38-2004/143
/dev/mapper/h-d  916G  181M  869G   1% /mnt
/dev/nvme0n1p5   943M  193M  685M  22% /boot
/dev/nvme0n1p8   101G   32G   64G  33% /home
/dev/nvme0n1p1   300M   51M  250M  17% /boot/efi
tmpfs            3.2G   20K  3.2G   1% /run/user/126
tmpfs            3.2G   44K  3.2G   1% /run/user/1000
/dev/mapper/h-d  916G  181M  869G   1% /mnt	# 表示自动挂载成功

#############
好记性不如烂笔头
积少成多

觉得还不错的话,点赞收藏哈

你可能感兴趣的:(others,linux)