Add hard disk and partition mount to virtual machine centos

1 Add a new hard drive

Settings -> Storage -> SATA Controller -> Right-click, select "Add Virtual Hard Disk"

2 Restart the virtual machine

View the disk space of the existing system
fdisk -l

You can see the newly added virtual hard disk, generally named: Disk /dev/sdb

  1. To the newly added hard disk partition
    fdisk /dev/sdb

Type m to see help information

Type n again for a new partition

Type p again to select the base partition

Type 1 again to create a partition

Enter

carriage return, carriage return

Type w and press enter

  1. format disk partition

Format /dev/sdb1 with ext4 format

mkfs.ext4 /dev/sdb1

  1. mount partition

Create a new mount point

mkdir /svn

Mount the new disk partition to the /svn directory

mount -t ext4 /dev/sdb1 /svn

View mounts

df -h
can see the newly added hard disk: /dev/sdb1

  1. Set up the automatic mount at boot and
    modify the file
    vi /etc/fstab
    to add a line:
    /dev/sdb1 /svn ext4 errors=remount-ro 0 1Complete
    !
    
    [root@localhost ~]# fdisk -l

Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (min. /best): 512 bytes / 512 bytes

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (min. /best): 512 bytes / 512 bytes
Disk Label Type: dos
Disk Identifier: 0x000a5daf

设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM

Disk /dev/mapper/centos-root: 39.7 GB, 39720058880 bytes, 77578240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/ O size (min/best): 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 (min/best): 512 bytes / 512 bytes

[root@localhost ~]# fidsk /dev/sdb
-bash: fidsk: command not found
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will stay in memory until you decide to write them to disk.
Think twice before using the write command.

Device does not contain a recognized partition table
to create a new DOS disk label with the disk identifier 0x3c8bf852.

命令(输入 m 获取帮助):m
命令操作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (enter 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
starting sector ( 2048-2147483647, default 2048):
will use default 2048
Last sector, +sector or +size{K,M,G} (2048-2147483647, default 2147483647):
will use default 2147483647
Partition 1 is set For Linux type, size is set to 1024 GiB

Command (enter m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Synchronizing disk.
[root@localhost ~]# mkfs.ext4 /dev/sdb
sdb sdb1
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
filesystem tags=
OS type: Linux
block size=4096 (log=2)
Block size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
67108864 inodes, 268435200 blocks 13421760 blocks (5.00%) reserved for the
super user
One data block=0
Maximum filesystem blocks=2415919104
8192 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, 78675968,
102400000, 214990848

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

[root@localhost ~]# cd..
-bash: cd..: command not found
[root@localhost ~]# cd /
[root@localhost /]# ls
bin boot dev etc home lib lib64 media mnt opt ​​proc root run sbin srv sys tmp usr var
[root@localhost /]# mkdir svn
[root@localhost /]# mount -t ext4 /dev/sdb1 /svn
[root@localhost /]# df -h
file system capacity used available used % mount point
/dev/mapper/centos-root 37G 1.3G 36G 4% /
devtmpfs 875M 0 875M 0% /dev
tmpfs 886M 0 886M 0% /dev/shm
tmpfs 886M 17M 869M 2% /run
tmpfs 886M 0 886M 0 % /sys/fs/cgroup
/dev/sda1 1014M 319M 696M 32% /boot
tmpfs 178M 0 178M 0% /run/user/0
/dev/sdb1 1008G 77M 957G 1% /svn
[root@localhost /]# vi / etc/fstab

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325947216&siteId=291194637