k3os的磁盘挂载必须在系统启动时通过启动命令实现,具体如何实现呢?
首先查看磁盘列表
sudo fdisk -l
Disk /dev/loop1: 56.89 MiB, 59629568 bytes, 116464 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 /dev/loop2: 289.5 MiB, 303554560 bytes, 592880 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 /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: VMware Virtual I
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: 0xbd81ae90
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 268435455 268433408 128G 83 Linux
Disk /dev/sdb: 1 TiB, 1099511627776 bytes, 2147483648 sectors
Disk model: VMware Virtual I
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
可以看到/dev/sdb这个磁盘还没有挂载,进入磁盘
sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x00cf8313.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-2147483647, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2147483647, default 2147483647):
Created a new partition 1 of type 'Linux' and of size 1024 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
再执行sudo fdisk -l,可以看到新的分区
k3os-node2 [~]$ sudo fdisk -l
Disk /dev/loop1: 56.89 MiB, 59629568 bytes, 116464 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 /dev/loop2: 289.5 MiB, 303554560 bytes, 592880 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 /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: VMware Virtual I
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: 0xbd81ae90
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 268435455 268433408 128G 83 Linux
Disk /dev/sdb: 1 TiB, 1099511627776 bytes, 2147483648 sectors
Disk model: VMware Virtual I
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: 0x00cf8313
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2147483647 2147481600 1024G 83 Linux
分区格式化
k3os-node2 [~]$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 268435200 4k blocks and 67108864 inodes
Filesystem UUID: 5bbe2db5-37bb-43d8-a947-c0629eab91e8
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
挂载分区到/data目录
k3os-node2 [~]$ sudo mkdir /data
k3os-node2 [~]$ sudo mount /dev/sdb1 /data
k3os-node2 [~]$ cd /data
k3os-node2 [/data]$ ls
lost+found
设置启动时自动挂载
注意,k3os不能通过修改/etc/fstab文件来设置启动时自动加载磁盘,要实现自动加载磁盘,可以通过以下方式进行。
$ sudo vi /var/lib/rancher/k3os/config.yaml
#加入以下内容
boot_cmd:
- "echo boot command..."
run_cmd:
- "echo run command..."
- "echo mount device..."
- "sudo mount /dev/sdb1 /data" #加载/dev/sdb1到/data目录
评论区