虛擬機centos添加硬盤和分區掛載
設置-》存儲-》SATA控制器-》右擊,選擇“添加虛擬硬盤”
2重啟虛擬機
查看現有系統的磁盤空間
fdisk -l
可看到新加的虛擬硬盤,一般名為:Disk /dev/sdb
- 給新加的硬盤分區
fdisk /dev/sdb
鍵入m,可看到幫助信息
再鍵入n表示新分區
再鍵入p選擇基本分區
再鍵入1表示建一個分區
回車
回車,再回車
鍵入w ,再回車
- 格式化磁盤分區
用ext4格式對/dev/sdb1進入格式化
mkfs.ext4 /dev/sdb1
- 掛載分區
創建新的掛載點
mkdir /svn
將新磁盤分區掛載到/svn目錄下
mount -t ext4 /dev/sdb1 /svn
查看掛載
df -h
可以看到新加的硬盤:/dev/sdb1
- 設置開機自動掛載
修改文件
vi /etc/fstab
加入一行:
/dev/sdb1 /svn ext4 errors=remount-ro 0 1
完成![root@localhost ~]# fdisk -l
磁盤 /dev/sdb:1099.5 GB, 1099511627776 字節,2147483648 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/sda:42.9 GB, 42949672960 字節,83886080 個扇區
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x000a5daf
設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
磁盤 /dev/mapper/centos-root:39.7 GB, 39720058880 字節,77578240 個扇區
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 字節,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
[root@localhost ~]# fidsk /dev/sdb
-bash: fidsk: 未找到命令
[root@localhost ~]# fdisk /dev/sdb
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。
Device does not contain a recognized partition table
使用磁盤標識符 0x3c8bf852 創建新的 DOS 磁盤標簽。
命令(輸入 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)
命令(輸入 m 獲取幫助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分區號 (1-4,默認 1):1
起始 扇區 (2048-2147483647,默認為 2048):
將使用默認值 2048
Last 扇區, +扇區 or +size{K,M,G} (2048-2147483647,默認為 2147483647):
將使用默認值 2147483647
分區 1 已設置為 Linux 類型,大小設為 1024 GiB
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盤。
[root@localhost ~]# mkfs.ext4 /dev/sdb
sdb sdb1
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: 完成
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
67108864 inodes, 268435200 blocks
13421760 blocks (5.00%) reserved for the super user
第一個數據塊=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: 完成
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@localhost ~]# cd..
-bash: cd..: 未找到命令
[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
文件系統 容量 已用 可用 已用% 掛載點
/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
虛擬機centos添加硬盤和分區掛載