准备
- 一块固态盘
- 关机插入固态盘
-
开机进入root
image.png
查找固态硬盘
fdisk -l
image.png
root@cfl:~# fdisk -l
Disk /dev/nvme0n1: 238.47 GiB, 256060514304 bytes, 500118192 sectors
Disk model: Maxsun 256GB SSD
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: 999B2368-5B92-4403-B05D-EEF3F717E10E
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System
/dev/nvme0n1p2 1050624 500117503 499066880 238G Linux filesystem
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: WDC WD10EZEX-08M
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 97E2547D-DAD3-4F38-B8F0-12271B73B5C8
Device Start End Sectors Size Type
/dev/sda1 2048 2203647 2201600 1G EFI System
/dev/sda2 2203648 316776447 314572800 150G Linux filesystem
/dev/sda3 316776448 325165055 8388608 4G Linux filesystem
/dev/sda4 325165056 392273919 67108864 32G Linux filesystem
/dev/sda5 392273920 1952555007 1560281088 744G Linux filesystem
格式化分区
mkfs.ext4 /dev/nvme0n1p1
mkfs.ext4 /dev/nvme0n1p2
注意了,这里我们要记录下Filesystem UUID ,给后面永久挂载做准备。
image.pngroot@cfl:~# mkfs.ext4 /dev/nvme0n1p1
mkfs.ext4 /dev/nvme0n1p2
mke2fs 1.46.5 (30-Dec-2021)
/dev/nvme0n1p1 contains a vfat file system
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 131072 4k blocks and 32768 inodes
Filesystem UUID: b95b0b0b-4272-443b-9b6c-213a41ed858b
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
mke2fs 1.46.5 (30-Dec-2021)
/dev/nvme0n1p2 contains a ext4 file system
last mounted on / on Sat Mar 16 02:44:32 2024
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 62383360 4k blocks and 15597568 inodes
Filesystem UUID: cbceb881-268e-429f-8d10-eda7542b1d2d
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
创建需要挂载的目录
mkdir data
mkdir data2
挂载固态
sudo mount /dev/nvme0n1p1 /data
sudo mount /dev/nvme0n1p2 /data2
开机自动挂载(永久挂载)
sudo vim /etc/fstab
image.png
添加如下:
# /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).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/4b76c3cf-31f1-453e-a354-5b2aff4560ce / ext4 defaults 0 1
/dev/disk/by-uuid/b95b0b0b-4272-443b-9b6c-213a41ed858b /data ext4 defaults 0 0
/dev/disk/by-uuid/cbceb881-268e-429f-8d10-eda7542b1d2d /data2 ext4 defaults 0 0
# /boot was on /dev/sda3 during curtin installation
/dev/disk/by-uuid/a8fef6eb-6c93-470a-8849-a0f89e269516 /boot ext4 defaults 0 1
# /swap was on /dev/sda4 during curtin installation
/dev/disk/by-uuid/95163fc9-1bda-449a-9ffe-2c179eb1bdc0 /swap ext4 defaults 0 1
# /home was on /dev/sda5 during curtin installation
/dev/disk/by-uuid/9818944b-3399-41ec-bfdb-3a24b10792d7 /home ext4 defaults 0 1
# /boot/efi was on /dev/sda1 during curtin installation
/dev/disk/by-uuid/BA2A-8DED /boot/efi vfat defaults 0 1
/swap.img none swap sw 0 0
执行一下
sudo mount -a
查看已挂载分区
df -h
image.png
验证
重启主机
reboot
再次执行 df -h , 我们可以看到已经挂载了
image.png权限问题
之前我们都是在root用户下操作的,重新开机默认不是root 用户,可以发现多了新的硬盘,但是可能会出现一个问题,就是无法新建文件夹。使用以下命令即可解决
sudo chown -R 你的用户名 挂载目录
# 举例
sudo chown -R cfl /data
网友评论