一、创建分区
首先查看一下当前的硬盘及分区情况:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
root@database-test:~# sudo fdisk -l Disk /dev/loop0: 96.6 MiB, 101318656 bytes, 197888 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/loop1: 125.9 MiB, 131960832 bytes, 257736 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: 97 MiB, 101695488 bytes, 198624 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/xvda: 40 GiB, 42949672960 bytes, 83886080 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: gpt Disk identifier: 19CDE2AC-49E1-48BA-9ADC-36799BBE6DAC Device Start End Sectors Size Type /dev/xvda1 2048 4095 2048 1M BIOS boot /dev/xvda2 4096 83884031 83879936 40G Linux filesystem Disk /dev/xvdb: 150 GiB, 161061273600 bytes, 314572800 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操作要挂载的硬盘,输入m看一下帮助菜单:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
root@database-test:~# sudo fdisk /dev/xvdb Welcome to fdisk (util-linux 2.31.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 0x9a4d11c1. Command (m for help): m Help: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Generic d delete a partition F list free unpartitioned space l list known partition types n add a new partition p print the partition table t change a partition type v verify the partition table i print information about a partition Misc m print this menu u change display/entry units x extra functionality (experts only) Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file Save & Exit w write table to disk and exit q quit without saving changes Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table |
输入n,执行add a new partition,给硬盘增加一个新分区:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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): First sector (2048-314572799, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-314572799, default 314572799): Created a new partition 1 of type 'Linux' and of size 150 GiB. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. |
出现Command action时,输入p,指定分区为primary分区。出现Partition number(1-4)时,输入1表示只分一个区。后续指定开始和结束扇区,完成分区。最后,在Command (m for help)提示符后面输入w,保存分区表。
再次运行fdisk -l,就可以看到新硬盘/dev/xvdb对应的分区了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
root@database-test:~# sudo fdisk -l Disk /dev/loop0: 96.6 MiB, 101318656 bytes, 197888 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/loop1: 125.9 MiB, 131960832 bytes, 257736 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: 97 MiB, 101695488 bytes, 198624 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/xvda: 40 GiB, 42949672960 bytes, 83886080 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: gpt Disk identifier: 19CDE2AC-49E1-48BA-9ADC-36799BBE6DAC Device Start End Sectors Size Type /dev/xvda1 2048 4095 2048 1M BIOS boot /dev/xvda2 4096 83884031 83879936 40G Linux filesystem Disk /dev/xvdb: 150 GiB, 161061273600 bytes, 314572800 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: 0x9a4d11c1 Device Boot Start End Sectors Size Id Type /dev/xvdb1 2048 314572799 314570752 150G 83 Linux |
二、格式化分区
将分区格式化成ext4文件系统类型:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
root@database-test:~# sudo mkfs -t ext4 /dev/xvdb mke2fs 1.44.1 (24-Mar-2018) Found a dos partition table in /dev/xvdb Proceed anyway? (y,N) y Creating filesystem with 39321600 4k blocks and 9830400 inodes Filesystem UUID: 9350fb17-eea7-4326-af43-99094d0e4403 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 (262144 blocks): done Writing superblocks and filesystem accounting information: done |
三、挂载分区
新分区只有在挂载后才能看到,现在还看不到:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
root@database-test:~# df -l Filesystem 1K-blocks Used Available Use% Mounted on udev 973024 0 973024 0% /dev tmpfs 200944 1012 199932 1% /run /dev/xvda2 41019616 4815284 34090952 13% / tmpfs 1004708 0 1004708 0% /dev/shm tmpfs 5120 0 5120 0% /run/lock tmpfs 1004708 0 1004708 0% /sys/fs/cgroup /dev/loop0 98944 98944 0 100% /snap/core/9804 /dev/loop1 128896 128896 0 100% /snap/docker/471 /dev/loop2 99328 99328 0 100% /snap/core/9665 tmpfs 200940 0 200940 0% /run/user/1000 tmpfs 200940 0 200940 0% /run/user/0 |
将新分区挂载上:
1 2 |
root@database-test:~# mkdir /data root@database-test:~# mount -t ext4 /dev/xvdb /data |
之后就可以看到新分区挂载到/data下了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
root@database-test:~# df -lh Filesystem Size Used Avail Use% Mounted on udev 951M 0 951M 0% /dev tmpfs 197M 1012K 196M 1% /run /dev/xvda2 40G 4.6G 33G 13% / tmpfs 982M 0 982M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 982M 0 982M 0% /sys/fs/cgroup /dev/loop0 97M 97M 0 100% /snap/core/9804 /dev/loop1 126M 126M 0 100% /snap/docker/471 /dev/loop2 97M 97M 0 100% /snap/core/9665 tmpfs 197M 0 197M 0% /run/user/1000 tmpfs 197M 0 197M 0% /run/user/0 /dev/xvdb 147G 61M 140G 1% /data |
配置硬盘在系统启动自动挂载,在文件/etc/fstab最后加入新分区对应的配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
root@database-test:~# vim /etc/fstab root@database-test:~# cat /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/xvda2 during curtin installation /dev/disk/by-uuid/633d74a8-f61d-48c6-8dcb-9804a0d8f5ba / ext4 defaults 0 0 /swap.img none swap sw 0 0 /dev/xvdb /data ext4 defaults 0 0 |
转载时请保留出处,违法转载追究到底:进城务工人员小梅 » Ubuntu 18.04挂载新硬盘