linux虚拟机格式化新硬盘,挂载,设置开机自动挂载

linux虚拟机格式化新硬盘,挂载,设置开机自动挂载


查看新硬盘,在虚拟机上通过 fdisk -l指令查看:
[root@HSS-data-comparison-OSS ~]# fdisk -l

Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x00061b3f

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 419307519 209140736 8e Linux LVM

Disk /dev/sdb: 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 /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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/mapper/centos-home: 158.3 GB, 158318198784 bytes, 309215232 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

格式化硬盘,如果不需要分区,直接格式化就行:
[root@HSS-data-comparison-OSS ~]# mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19660800 inodes, 78643200 blocks
3932160 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2227175424
2400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

格式化完成后,就可以选一个挂载点进行挂载:
[root@HSS-data-comparison-OSS ~]# mount /dev/sdb /home/udcm
查看是否已经挂载上了:
[root@HSS-data-comparison-OSS ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 8.0G 39G 18% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 84K 16G 1% /dev/shm
tmpfs 16G 8.9M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/sda1 477M 134M 315M 30% /boot
/dev/mapper/centos-home 146G 3.1G 135G 3% /home
tmpfs 3.2G 16K 3.2G 1% /run/user/42
tmpfs 3.2G 0 3.2G 0% /run/user/1001
/dev/sdb 296G 24G 257G 9% /home/udcm

通过修改 /etc/fstab 设置开机自动挂载:
[root@HSS-data-comparison-OSS ~]# cat /etc/fstab

/dev/sdb[两个tab键]/home/udcm[两个tab]ext4[一个tab键]defaults[一个tab键]0[1个空格]0

重启后一切正常。

你可能感兴趣的:(虚拟机)