磁盤擴展
查看磁盤
現(xiàn)有一個300GB的磁盤設(shè)備/dev/vda,有一個主分區(qū)并掛載于/dev/vda1下。
[root@kubernetes ~]# fdisk -l /dev/vda
Disk /dev/vda: 322.1 GB, 322122547200 bytes, 629145600 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 label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 209713151 104855552 83 Linux
查看分區(qū)所占存儲大小
可以看到主分區(qū)分配了100G的磁盤空間
[root@kubernetes ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 60G 34G 64% /
還有200GB的存儲空間實際上是新增的存儲,還沒有分配使用。
查看文件系統(tǒng)類型
查看一下該分區(qū)所使用的文件系統(tǒng)類型,這里實際是使用的ext4。
[root@kubernetes rpms]# blkid /dev/vda1
/dev/vda1: UUID="eb448abb-3012-4d8d-bcde-94434d586a31" TYPE="ext4"
創(chuàng)建新分區(qū)及分配存儲空間
[root@kubernetes ~]# fdisk -u /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/vda: 322.1 GB, 322122547200 bytes, 629145600 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 label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 209713151 104855552 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (209713152-629145599, default 209713152):
Using default value 209713152
Last sector, +sectors or +size{K,M,G} (209713152-629145599, default 629145599):
Using default value 629145599
Partition 2 of type Linux and of size 200 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
其中有一段WARNING
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
可以使用partprobe指令處理,具體詳情可以考慮該文檔
查看新分區(qū)情況
lsblk /dev/vda
通過該指令將看到新的分區(qū)/dev/vda2.
格式化新的分區(qū)
使用mkfs.ext4指令創(chuàng)建ext4文件系統(tǒng):
[root@kubernetes ~]# mkfs.ext4 /dev/vda2
mke2fs 1.42.9 (28-Dec-2013)
warning: 256 blocks unused.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13132800 inodes, 52428800 blocks
2621439 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2199912448
1600 block groups
32768 blocks per group, 32768 fragments per group
8208 inodes per group
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 (32768 blocks): done
Writing superblocks and filesystem accounting information: done
查看新分區(qū)的詳情
[root@kubernetes ~]# blkid /dev/vda2
/dev/vda2: UUID="f7f6ca5e-7271-yyyy-xxxx-c746164ad124" TYPE="ext4"
將新分區(qū)掛載到文件系統(tǒng)指定路徑
運行mount /dev/vda2 /mnt掛載文件系統(tǒng)。
[root@kubernetes ~]# mount /dev/vda2 /mnt
查看磁盤使用情況
[root@kubernetes ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 83G 11G 89% /
/dev/vda1 99G 83G 11G 89% /
/dev/vda2 197G 61M 187G 1% /mnt
//TODO
系統(tǒng)啟動自動掛載新分區(qū)
5.設(shè)置開機自動掛載,打開自動掛載文件:vi /etc/fstab,加入如下圖所示內(nèi)容行:

image
保存退出,重啟主機看下是否自動掛載:df -lh

image