---
# System prepended metadata

title: （九）20-23題

---

# （九）20-23題
## 20
:::info
點選KVM10-設定
:::
![](https://i.imgur.com/HQGtJey.png)
:::info
在存放裝置中新增硬碟
:::
![](https://i.imgur.com/ucOk87b.png)
:::info
建立3個新的硬碟
（VDI :arrow_right:	動態分配 :arrow_right:	新增分別為**2G/6G/10G**的硬碟）
:::
![](https://i.imgur.com/3I19k2f.png)
![](https://i.imgur.com/9vn3jzA.png)
![](https://i.imgur.com/wd95v1R.png)
![](https://i.imgur.com/RpITpAL.png)
:::warning
新增完後記得選擇加入硬碟:heavy_exclamation_mark: 
:::
![](https://i.imgur.com/tPiOOWQ.png)
![](https://i.imgur.com/UqIo2gH.png)
```
$ fdisk -l
```
:::success
確認是否有12-31行的內容，有出現才有成功新增硬碟
:::
```dockerfile=
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 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
Disklabel type: dos
Disk identifier: 0xc6f284e9

Device     Boot   Start       End   Sectors Size Id Type
/dev/sda1  *       2048   2099199   2097152   1G 83 Linux
/dev/sda2       2099200 104857599 102758400  49G 8e Linux LVM

Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 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
Disklabel type: dos
Disk identifier: 0x647d74db

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048 2050047 2048000 1000M 83 Linux

Disk /dev/sdc: 6 GiB, 6442450944 bytes, 12582912 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/sdd: 10 GiB, 10737418240 bytes, 20971520 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/mapper/cs-root: 45 GiB, 48351936512 bytes, 94437376 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/mapper/cs-swap: 4 GiB, 4257218560 bytes, 8314880 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/mapper/mysdb-vo: 96 MiB, 100663296 bytes, 196608 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
```
```
$ fdisk /dev/sdb
```
```dockerfile=
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4194303, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): +1000M

Created a new partition 1 of type 'Linux' and of size 1000 MiB.

Command (m for help): wq
The partition table has been altered.
Syncing disks.
```
```
$ pvcreate /dev/sdb1
```
```dockerfile=
Physical volume "/dev/sdb1" successfully created.
```
:::success
出現上面這行才表示執行成功
:::
```
$ pvs
```
```dockerfile=
PV         VG Fmt  Attr PSize    PFree   
/dev/sda2  cs lvm2 a--   <49.00g       0 
/dev/sdb1     lvm2 ---  1000.00m 1000.00m
```
```
$ vgcreate mysdc /dev/sdb1
```
```dockerfile=
Volume group "mysdb" successfully created
```
```
$ vgs
```
```dockerfile=
VG    #PV #LV #SN Attr   VSize   VFree  
cs      1   2   0 wz--n- <49.00g      0 
mysdb   1   0   0 wz--n- 996.00m 996.00m
```
```
$ lvcreate -L 93M -n vo mysdb
```
```dockerfile=
Rounding up size to full physical extent 96.00 MiB
Logical volume "vo" created.
```
```
$ lvdisplay mysdc
```
```dockerfile=
--- Logical volume ---
LV Path                /dev/mysdb/vo
LV Name                vo
VG Name                mysdb
LV UUID                gg8f3a-vub7-JZA6-epdA-Ka2w-w2Yn-g7iMHU
LV Write Access        read/write
LV Creation host, time kvm10.chuck.im.shu, 2021-10-01 03:59:03 -0400
LV Status              available
# open                 0
LV Size                96.00 MiB
Current LE             24
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     8192
Block device           253:3
```
```
$ mkfs.ext4 /dev/mysdb/vo
```
```dockerfile=
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 98304 1k blocks and 24576 inodes
Filesystem UUID: 8b798ffc-449e-471a-b412-1fee67b4fad0
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 
```
```
$ vim /etc/fstab
```
:::warning
在檔案內容加入13行
:::
```dockerfile=
# /etc/fstab
# Created by anaconda on Wed Jun 30 09:26:04 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cs-root     /                       xfs     defaults        0 0
UUID=82c7adc8-366d-4387-afca-71a5dd37aaa4 /boot                   xfs     defaults        0 0
/dev/mapper/cs-swap     none                    swap    defaults        0 0
/dev/mapper/mysdb-vo    /reports                ext4    defaults        1 2
```
```
$ mkdir /reports
$ mount -a
$ df -Th    (確認是否掛載成功-9)
```
```dockerfile=
Filesystem           Type      Size  Used Avail Use% Mounted on
devtmpfs             devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                tmpfs     1.9G  8.5M  1.9G   1% /run
tmpfs                tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/cs-root  xfs        46G  3.4G   42G   8% /
/dev/sda1            xfs      1014M  200M  815M  20% /boot
tmpfs                tmpfs     374M     0  374M   0% /run/user/0
/dev/mapper/mysdb-vo ext4       89M  1.6M   81M   2% /reports
```
## 21、22
```
$ fdisk -l
```
:::success
確認是否有6GiB的硬碟（22-25）
:::
```dockerfile=
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 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
Disklabel type: dos
Disk identifier: 0xc6f284e9

Device     Boot   Start       End   Sectors Size Id Type
/dev/sda1  *       2048   2099199   2097152   1G 83 Linux
/dev/sda2       2099200 104857599 102758400  49G 8e Linux LVM

Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 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
Disklabel type: dos
Disk identifier: 0x647d74db

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048 2050047 2048000 1000M 83 Linux

Disk /dev/sdc: 6 GiB, 6442450944 bytes, 12582912 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/sdd: 10 GiB, 10737418240 bytes, 20971520 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/mapper/cs-root: 45 GiB, 48351936512 bytes, 94437376 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/mapper/cs-swap: 4 GiB, 4257218560 bytes, 8314880 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/mapper/mysdb-vo: 96 MiB, 100663296 bytes, 196608 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
```
```
$ fdisk /dev/sdc
```
```dockerfile=
Welcome to fdisk (util-linux 2.32.1).
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 0x3ba440f6.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +200M

Created a new partition 1 of type 'Linux' and of size 200 MiB.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (411648-20971519, default 411648): 
Last sector, +sectors or +size{K,M,G,T,P} (411648-20971519, default 20971519): +4900M

Created a new partition 2 of type 'Linux' and of size 4.8 GiB.

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
```
```
$ mkfs.ext4 /dev/sdc1
```
```dockerfile=
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 9c751bf3-653d-4dac-afcd-5722147789f4
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 
```
```
$ mkdir /test
$ vim /etc/fstab
```
:::warning
在檔案內容加入14行
:::
```dockerfile=
# /etc/fstab
# Created by anaconda on Wed Jun 30 09:26:04 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cs-root     /                       xfs     defaults        0 0
UUID=82c7adc8-366d-4387-afca-71a5dd37aaa4 /boot                   xfs     defaults        0 0
/dev/mapper/cs-swap     none                    swap    defaults        0 0
/dev/mapper/mysdb-vo    /reports                ext4    defaults        1 2
/dev/sdc1       /test                           ext4    defaults        0 0
```
```
$ mount -a
$ df -Th    (確認是否掛載成功-10)
```
```dockerfile=
Filesystem           Type      Size  Used Avail Use% Mounted on
devtmpfs             devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                tmpfs     1.9G  8.6M  1.9G   1% /run
tmpfs                tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/cs-root  xfs        46G  3.4G   42G   8% /
/dev/sda1            xfs      1014M  200M  815M  20% /boot
tmpfs                tmpfs     374M     0  374M   0% /run/user/0
/dev/mapper/mysdb-vo ext4       89M  1.6M   81M   2% /reports
/dev/sdc1            ext4      190M  1.6M  175M   1% /test
```
## 23
:::info
因為一開始就將會用到的磁碟數量掛載好
所以只要用**lsblk**查看有沒有一個空的磁碟即可
:::
```
$ lsblk
```
```dockerfile=
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda            8:0    0   50G  0 disk 
├─sda1         8:1    0    1G  0 part /boot
└─sda2         8:2    0   49G  0 part 
  ├─cs-root  253:0    0   45G  0 lvm  /
  └─cs-swap  253:1    0    4G  0 lvm  [SWAP]
sdb            8:16   0    2G  0 disk 
└─sdb1         8:17   0 1000M  0 part 
  └─mysdb-vo 253:2    0   96M  0 lvm  /reports
sdc            8:32   0    6G  0 disk 
└─sdc1         8:33   0 1000M  0 part 
  └─mysdc-vo 253:3    0   96M  0 lvm  
sdd            8:48   0   10G  0 disk 
sr0           11:0    1 1024M  0 rom  
```