背景
新买华为云主机,附带100G存储盘,需要挂载用来存储数据,从网上找到一个可用版本,搬到自己博客备用。
操作过程
1、查询硬盘信息
fdisk -lu root@ecs-d213:/usr/local# fdisk -lu disk /dev/vda: 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: 1AAC48CB-BE7A-495D-8BC2-EAECBD2B9071 Device Start End Sectors Size Type /dev/vda1 2048 1050623 1048576 512M EFI System /dev/vda2 1050624 83884031 82833408 39.5G Linux filesystem disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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
上面的/dev/vdb就是我们的数据盘,100GB
2、初始化分区
fdisk /dev/vdb 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 0xe70df40c.
依次输入:m、n、p、回车、回车、
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 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-209715199, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199,default 209715199): Created a new partition 1 of type 'Linux' and of size 100GiB.
3、保存设置
依次输入p、w后如下
Command (m for help): p disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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: 0xe70df40c Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 209715199 209713152 100G 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
4、格式化文件系统
mkfs.ext4 /dev/vdb1 mke2fs 1.44.1 (24-Mar-2018) Creating filesystem with 26214144 4k blocks and 6553600 inodes Filesystem UUID: b7785c1a-d86e-4329-aa45-6ee1c7cdea46 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 (131072 blocks): done Writing superblocks and filesystem accounting information:
done
5、挂载分区
经过以上初始化及格式化设置,我们的分区是/dev/vdb1,接下来进行分区挂载
查询分区UUID
ls -l /dev/disk/by-uuid total 0 lrwxrwxrwx 1 root root 10 Aug 21 10:06 3224fdc9-53ff-4610-974f-c0ad3c81d717 -> ../../vda2 lrwxrwxrwx 1 root root 10 Aug 24 13:30 b7785c1a-d86e-4329-aa45-6ee1c7cdea46 -> ../../vdb1 lrwxrwxrwx 1 root root 10 Aug 21 10:06 FD20-359A -> ../../vda1
/dev/vdb1的UUID是 b7785c1a-d86e-4329-aa45-6ee1c7cdea46
编辑分区表
mkdir /data
vim /etc/fstab #添加 UUID=b7785c1a-d86e-4329-aa45-6ee1c7cdea46 /data/ ext4 rw 0 1
reboot重启后我们的分区如下:
root@ecs-d213:~# df -h Filesystem Size Used Avail Use% Mounted on udev 16G 0 16G 0% /dev tmpfs 3.2G 6.9M 3.2G 1% /run /dev/vda2 39G 3.2G 34G 9% / tmpfs 16G 0 16G 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/vdb1 98G 61M 93G 1% /data /dev/vda1 512M 264K 512M 1% /boot/efi tmpfs 3.2G 0 3.2G 0% /run/user/0
参考:
https://blog.csdn.net/zhengchaooo/article/details/79500116?biz_id=102&utm_term=ubuntu%E6%8C%82%E5%9C%A8%E7%A1%AC%E7%9B%98&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-79500116&spm=1018.2118.3001.4187