error
在Linux系统中,/dev/sda
通常用于表示传统的SATA或SCSI硬盘设备,而 /dev/nvme0n1
则表示NVMe(Non-Volatile Memory Express)固态硬盘。NVMe设备的命名方式与传统的SATA设备不同,通常以 nvme
开头,后面跟着控制器编号和命名空间编号。
1. 确认设备类型
你提到的 /dev/nvme0n1
是一个NVMe设备,而不是传统的SATA设备。因此,你不会在 /dev
目录下看到 sda
,而是看到 nvme0n1
及其分区(如 nvme0n1p1
、nvme0n1p2
等)。
2. 检查LUKS加密分区
如果你的系统使用了LUKS加密分区,通常你需要先解锁加密分区,然后才能访问其中的文件系统。你可以通过以下步骤来检查和解锁LUKS加密分区:
2.1 列出NVMe设备的分区
使用 lsblk
或 fdisk
命令来查看设备的分区情况:
lsblk /dev/nvme0n1
或者:
fdisk -l /dev/nvme0n1
这将显示 nvme0n1
设备的所有分区。
2.2 解锁LUKS加密分区
假设你的LUKS加密分区是 /dev/nvme0n1p3
,你可以使用以下命令来解锁它:
sudo cryptsetup luksOpen /dev/nvme0n1p3 my_encrypted_partition
这将解锁加密分区并将其映射到 /dev/mapper/my_encrypted_partition
。
2.3 挂载解锁后的分区
解锁后,你可以像挂载普通分区一样挂载它:
sudo mount /dev/mapper/my_encrypted_partition /mnt
3. 检查系统日志
如果你仍然无法找到设备,可以检查系统日志(如 dmesg
或 /var/log/syslog
)以获取更多信息:
dmesg | grep nvme
这将显示与NVMe设备相关的内核消息,帮助你诊断问题。
4. 总结
/dev/nvme0n1
是NVMe设备,而不是传统的SATA设备,因此你不会看到sda
。- 使用
lsblk
或fdisk
查看分区。 - 使用
cryptsetup luksOpen
解锁LUKS加密分区。 - 使用
mount
挂载解锁后的分区。
如果你有其他问题或需要进一步的帮助,请随时提问!
其实,磁盘的调整,直接用启动盘里的GParted就行,至少对ext4格式的可以,命令封装成图形界面多方便,fw才要记命令
先放结果——30G的swap space
问题描述:网上的方法修改交换分区尺寸失败
尝试增大swap
sudo swapoff -a
sudo resize2fs /dev/vgubuntu/root 400G
失败
/dev/vgubuntu/root 上的文件系统已被挂载于 /;需要进行在线调整大小
resize2fs: 不支持在线缩小大小
解决方案
在Linux中,某些文件系统(如ext4)不支持在线缩小大小,因此在尝试缩小逻辑卷之前,你需要先卸载该文件系统。由于 /dev/vgubuntu/root
是根文件系统,直接卸载它会导致系统无法正常运行。因为必须用U盘中的ubuntu来修改主机的swap尺寸。
step0. 创建一个USB的ubuntu启动盘
最安全的方法是使用Live CD或USB启动系统,这样你可以在不挂载根文件系统的情况下进行操作。以下是步骤:
-
创建一个Live USB:使用Ubuntu或其他Linux发行版的ISO文件创建一个Live USB。
-
从Live USB启动:重启计算机并从Live USB启动。
process manually
- expand crypt disk
sudo cryptsetup luksOpen /dev/sda3 test
- you will found
/root
andswap
appear in/dev/
* further, you can find decrypted disk under
/dev/mapper
- check integrity of root
/dev/mapper$ sudo e2fsck -f /dev/mapper/vgubuntu-root
e2fsck 1.45.5 (07-Jan-2020)
Pass 1: Checking inodes, blocks, and sizes
Inode 3540723 extent tree (at level 1) could be shorter. Optimize<y>? yes
Inode 15212859 extent tree (at level 1) could be shorter. Optimize<y>? yes
Inode 15212860 extent tree (at level 1) could be shorter. Optimize<y>? yes
Pass 1E: Optimizing extent trees
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vgubuntu-root: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/vgubuntu-root: 370292/31072256 files (0.5% non-contiguous), 13769225/124261376 blocks
- resize filesystem
/dev/mapper$ sudo resize2fs /dev/mapper/vgubuntu-root 400G
resize2fs 1.45.5 (07-Jan-2020)
Resizing the filesystem on /dev/mapper/vgubuntu-root to 104857600 (4k) blocks.
The filesystem on /dev/mapper/vgubuntu-root is now 104857600 (4k) blocks long.
- reduce lvm size
/dev/mapper$ sudo lvreduce -L 400G /dev/mapper/vgubuntu-root
WARNING: Reducing active logical volume to 400.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vgubuntu/root? [y/n]: y
Size of logical volume vgubuntu/root changed from <474.02 GiB (121349 extents) to 400.00 GiB (102400 extents).
Logical volume vgubuntu/root successfully resized.
- check integrity of fs again
/dev/mapper$ sudo e2fsck -f /dev/mapper/vgubuntu-root
e2fsck 1.45.5 (07-Jan-2020)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vgubuntu-root: 370292/26214400 files (0.6% non-contiguous), 13464272/104857600 blocks
- another test
sudo mkdir /mnt/test
sudo mount /dev/mapper/vgubuntu-root /mnt/test
$ df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgubuntu-root 393G 45G 329G 12% /mnt/test
do the same thing to swap
- check integrity, the waring is ok
/dev/mapper$ sudo e2fsck -f /dev/mapper/vgubuntu-swap_1
e2fsck 1.45.5 (07-Jan-2020)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/mapper/vgubuntu-swap_1
The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>
/dev/mapper/vgubuntu-swap_1 contains a swap file system
- resize lvm of swap
/dev/mapper$ sudo lvresize -L +23G /dev/mapper/vgubuntu-swap_1
Size of logical volume vgubuntu/swap_1 changed from 976.00 MiB (244 extents) to 23.95 GiB (6132 extents).
Logical volume vgubuntu/swap_1 successfully resized.
# equally
/dev/mapper$ sudo lvextend -L +6G /dev/mapper/vgubuntu-swap_1
Size of logical volume vgubuntu/swap_1 changed from 23.95 GiB (6132 extents) to 29.95 GiB (7668 extents).
Logical volume vgubuntu/swap_1 successfully resized.
Note
since swap space is not filesystem, when you run following cmd and get warning, it’s normal.
ubuntu@ubuntu:/dev/mapper$ sudo resize2fs /dev/mapper/vgubuntu-swap_1 24G
resize2fs 1.45.5 (07-Jan-2020)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/vgubuntu-swap_1
Couldn't find valid filesystem superblock.
You don’t need to execute the cmd .
3. make swap space
/dev/mapper$ sudo mkswap /dev/mapper/vgubuntu-swap_1
mkswap: /dev/mapper/vgubuntu-swap_1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 30 GiB (32161918976 bytes)
no label, UUID=cbed5615-dc56-4e02-8638-645bf8dcaf80
- add to system
/dev/mapper$ sudo swapon /dev/mapper/vgubuntu-swap_1
- check
ubuntu@ubuntu:/dev/mapper$ sudo swapon --show
NAME TYPE SIZE USED PRIO
/dev/dm-2 partition 30G 0B -2
ubuntu@ubuntu:/dev/mapper$ free -h
total used free shared buff/cache available
Mem: 11Gi 791Mi 5.7Gi 212Mi 5.1Gi 10Gi
Swap: 29Gi 0B 29Gi
link
- 如何在 Linux 中减小 LVM 大小:https://linux.cn/article-12740-1.html
- 如何在 Linux 中扩展/增加 LVM 大小:https://linux.cn/article-12673-1.html
- https://www.sysgeek.cn/ubuntu-swap-size/
- Linux创建LVM:https://linux.cn/article-12670-1.html