通常在增加磁盘或新系统,必不可少的就是格式化磁盘,分区,挂载分区。
玩过阿里等虚拟主机的朋友都知道,数据盘是需要自己分区并挂载的,对于新手确实是个难题,特记之,以供参考!
使用 df -lh 命令查看 ,系统只有系统盘.
1root@debian-nas:~# df -lh
2Filesystem Size Used Avail Use% Mounted on
3udev 466M 0 466M 0% /dev
4tmpfs 97M 4.3M 93M 5% /run
5/dev/mapper/debian--nas--vg-root 19G 2.5G 15G 15% /
6tmpfs 482M 0 482M 0% /dev/shm
7tmpfs 5.0M 0 5.0M 0% /run/lock
8tmpfs 482M 0 482M 0% /sys/fs/cgroup
9/dev/sda1 236M 49M 175M 22% /boot
10tmpfs 97M 0 97M 0% /run/user/0
使用 fdisk -l 查看磁盘情况,从下图可看到 有一个磁盘未分区,并记住为分区的 标识,我们这里是 /dev/sdb:
1root@debian-nas:~# fdisk -l
2Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
3Disk model: VMware Virtual S
4Units: sectors of 1 * 512 = 512 bytes
5Sector size (logical/physical): 512 bytes / 512 bytes
6I/O size (minimum/optimal): 512 bytes / 512 bytes
7
8
9Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
10Disk model: VMware Virtual S
11Units: sectors of 1 * 512 = 512 bytes
12Sector size (logical/physical): 512 bytes / 512 bytes
13I/O size (minimum/optimal): 512 bytes / 512 bytes
14Disklabel type: dos
15Disk identifier: 0x31b1f6c9
16
17Device Boot Start End Sectors Size Id Type
18/dev/sda1 * 2048 499711 497664 243M 83 Linux
19/dev/sda2 501758 41940991 41439234 19.8G 5 Extended
20/dev/sda5 501760 41940991 41439232 19.8G 8e Linux LVM
21
22
23Disk /dev/mapper/debian--nas--vg-root: 18.8 GiB, 20124270592 bytes, 39305216 sectors
24Units: sectors of 1 * 512 = 512 bytes
25Sector size (logical/physical): 512 bytes / 512 bytes
26I/O size (minimum/optimal): 512 bytes / 512 bytes
27
28
29Disk /dev/mapper/debian--nas--vg-swap_1: 1020 MiB, 1069547520 bytes, 2088960 sectors
30Units: sectors of 1 * 512 = 512 bytes
31Sector size (logical/physical): 512 bytes / 512 bytes
32I/O size (minimum/optimal): 512 bytes / 512 bytes
执行 fdisk /dev/sdb 对磁盘分区,需要依次输入 “n” ,“p”,“1”,两次回车,“wq”:
1root@debian-nas:~# fdisk /dev/sdb
2
3Welcome to fdisk (util-linux 2.33.1).
4Changes will remain in memory only, until you decide to write them.
5Be careful before using the write command.
6
7Device does not contain a recognized partition table.
8Created a new DOS disklabel with disk identifier 0x58dd983e.
9
10Command (m for help): n
11Partition type
12 p primary (0 primary, 0 extended, 4 free)
13 e extended (container for logical partitions)
14Select (default p): p
15Partition number (1-4, default 1): 1
16First sector (2048-20971519, default 2048):
17Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519):
18
19Created a new partition 1 of type 'Linux' and of size 10 GiB.
20
21Command (m for help): wq
22The partition table has been altered.
23Calling ioctl() to re-read partition table.
24Syncing disks.
完毕后执行 fdisk -l 即可看到已经分区的磁盘,并记住盘符标识我们这里是 /dev/sdb1
1root@debian-nas:~# fdisk -l
2Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
3Disk model: VMware Virtual S
4Units: sectors of 1 * 512 = 512 bytes
5Sector size (logical/physical): 512 bytes / 512 bytes
6I/O size (minimum/optimal): 512 bytes / 512 bytes
7Disklabel type: dos
8Disk identifier: 0x58dd983e
9
10Device Boot Start End Sectors Size Id Type
11/dev/sdb1 2048 20971519 20969472 10G 83 Linux
12
13
14Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
15Disk model: VMware Virtual S
16Units: sectors of 1 * 512 = 512 bytes
17Sector size (logical/physical): 512 bytes / 512 bytes
18I/O size (minimum/optimal): 512 bytes / 512 bytes
19Disklabel type: dos
20Disk identifier: 0x31b1f6c9
21
22Device Boot Start End Sectors Size Id Type
23/dev/sda1 * 2048 499711 497664 243M 83 Linux
24/dev/sda2 501758 41940991 41439234 19.8G 5 Extended
25/dev/sda5 501760 41940991 41439232 19.8G 8e Linux LVM
26
27
28Disk /dev/mapper/debian--nas--vg-root: 18.8 GiB, 20124270592 bytes, 39305216 sectors
29Units: sectors of 1 * 512 = 512 bytes
30Sector size (logical/physical): 512 bytes / 512 bytes
31I/O size (minimum/optimal): 512 bytes / 512 bytes
32
33
34Disk /dev/mapper/debian--nas--vg-swap_1: 1020 MiB, 1069547520 bytes, 2088960 sectors
35Units: sectors of 1 * 512 = 512 bytes
36Sector size (logical/physical): 512 bytes / 512 bytes
37I/O size (minimum/optimal): 512 bytes / 512 bytes
格式化分区 /dev/sdb1
1root@debian-nas:~# mkfs.ext4 /dev/sdb1
2mke2fs 1.44.5 (15-Dec-2018)
3Creating filesystem with 2621184 4k blocks and 655360 inodes
4Filesystem UUID: d9cc08e4-8759-44d3-a4cf-c26f1010b3e0
5Superblock backups stored on blocks:
6 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
7
8Allocating group tables: done
9Writing inode tables: done
10Creating journal (16384 blocks): done
11Writing superblocks and filesystem accounting information: done
格式化完毕后,挂载之前创建的分区 /dev/sdb1
- 将分区信息写入fstab
1echo '/dev/sdb1 /mydata ext4 defaults 0 0' >> /etc/fstab
- 挂载分区
1mount -a
再用 df -lh 命令查看,就有新分区了。
至此,整个Linux磁盘分区并挂载完毕。
评论