fdisk入门

xiaoxiao2021-02-28  52

添加磁盘并挂载: 设置虚拟机系统里添加磁盘,重启虚拟机后,虚拟机目录/dev下会增加一个sdb设备。 使用fdisk /dev/sdb 管理磁盘分区,首先p 查看磁盘分区信息,然后n增加一个主分区,然后在敲入p进行分区操作,再输入1表示命名分区为sdb1,接着会提示输入开始扇区,直接回车跳过,然后在最后扇区那里输入+2G表示该分区大小设置为2G,使用p再次查看分区是否成功创建,显示有新的分区后,敲入w键表示写入磁盘。命令执行完成后,会自动退出fdisk。现在file /dev/sdb1查询分区信息,如果出错,敲入命令partprobe或者直接重启虚拟机即可。 因为Linux系统无法对没有格式化的磁盘进行读写操作,所以接下来还需要格式化创建好的分区。输入命令mkfs.xfs /dev/sdb1将其格式化为xfs文件系统格式,如果需要换成其他格式可以在敲完mkfs后再使用两次tab键来显示其他文件系统格式。 那么,现在我们只需要再挂载该分区到系统里就可以了,首先mkdir /newFS 在根目录创建文件夹用来挂载,然后就是mount /dev/sdb1 /newFS。现在就可以正常使用该分区了。但每次重启虚拟机后都需要再挂载一遍,所以我们可以在每次开机时自动挂载该分区,vi /etc/fstab 然后在文件末尾添加 /dev/sdb1 /newFS xfs defaults 0(表示是否开机磁盘自检) 0

下面是我在虚拟机里的操作过程记录

[root@localhost /]# fdisk /dev/sdb 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. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xf15825cf. Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xf15825cf Device Boot Start End Blocks Id System Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G Partition 1 of type Linux and of size 2 GiB is set Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xf15825cf Device Boot Start End Blocks Id System /dev/sdb1 2048 4196351 2097152 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost /]# ls /dev/sdb1 /dev/sdb1 [root@localhost /]# mkfs.ext2 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 524288 blocks 26214 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done [root@localhost /]# mount /dev/sdb1 /bp [root@localhost /]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda3 18555904 5090696 13465208 28% / devtmpfs 485292 0 485292 0% /dev tmpfs 499968 144 499824 1% /dev/shm tmpfs 499968 7224 492744 2% /run tmpfs 499968 0 499968 0% /sys/fs/cgroup /dev/sda1 303780 154756 149024 51% /boot tmpfs 99996 8 99988 1% /run/user/0 /dev/sdb1 2064208 3072 1956280 1% /bp [root@localhost /]# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda3 xfs 18555904 5090676 13465228 28% / devtmpfs devtmpfs 485292 0 485292 0% /dev tmpfs tmpfs 499968 144 499824 1% /dev/shm tmpfs tmpfs 499968 7224 492744 2% /run tmpfs tmpfs 499968 0 499968 0% /sys/fs/cgroup /dev/sda1 xfs 303780 154756 149024 51% /boot tmpfs tmpfs 99996 8 99988 1% /run/user/0 /dev/sdb1 ext2 2064208 3072 1956280 1% /bp [root@localhost /]#
转载请注明原文地址: https://www.6miu.com/read-72365.html

最新回复(0)