Vmware 虚机环境添加硬盘

今天学习了下Linux 文件系统的基础知识,这篇日志不会详细介绍LINUX文件系统知识,接下来将以一个实例,讲述如何在Vmware 上新增加一块disk ,并按照指定格式化,然后mount到指定目录。

1 在Vmware 上新增加一块disk,详细步骤略,在加硬盘过程中遇到点小麻烦, 新增硬盘后在操作系统通过 “fdisk -l “ 时读不到,后来才发现新增的硬盘需要改成IDE类型才能读到,因为主硬盘(linux安装时的disk)是 IDE模式吧,我想新增的硬盘应该与主硬盘类型应该一
样,如果哪位大侠了解的话,可以回贴指教下啊;

2 在步骤1中新增了一块容量为3G的硬盘, 规划如下:

分区 大小 类型 挂载点
/dev/hdb3 2048M ext3 /archive/pga
/dev/hdb1 1024M ext3 /pgdata

3 查看当前系统硬盘情况

1
2
3
4
5
6
7
8
9
10
11
[root@pg1 ~]# fdisk -l  
Disk /dev/hda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 1827 14675346 83 Linux
/dev/hda2 1828 1958 1052257+ 82 Linux swap / Solaris
Disk /dev/hdb: 3221 MB, 3221225472 bytes
16 heads, 63 sectors/track, 6241 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk /dev/hdb doesn't contain a valid partition table ----这句话说明disk /dev/hdb 还没有分区,可以使用;

4 给/dev/hdb 添加一个分区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
[root@pg1 ~]# fdisk /dev/hdb  
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 6241.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
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 (m for help): p ---查看分区情况
Disk /dev/hdb: 3221 MB, 3221225472 bytes
16 heads, 63 sectors/track, 6241 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4) ----选择主分区
p
Partition number (1-4): 3----选择分区编号
First cylinder (1-6241, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-6241, default 6241): +2048M ----选择大小,我这里设置成2G
Command (m for help): p
Disk /dev/hdb: 3221 MB, 3221225472 bytes
16 heads, 63 sectors/track, 6241 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
/dev/hdb3 1 3969 2000344+ 83 Linux
Command (m for help): w ----写入分区表The partition table has been altered!
Calling ioctl() to re-read partition table.
4 格式化分区,设置成 ext3 格式
[root@pg1 ~]# mkfs -t ext3 /dev/hdb3
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
250368 inodes, 500086 blocks
25004 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=515899392
16 block groups
32768 blocks per group, 32768 fragments per group
15648 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

5 挂载

1
[root@pg1 ~]# mount -t ext3 /dev/hdb3 /archive/pga

这里挂栽到目录 /archive/pga,同样的方法将 /dev/hdb1 mount到 /pgdata, 这里不一一列出。

6 开机自动挂载:

1
2
vim /etc/fstab  
/dev/hdb3 /archive/pga ext3 defaults 0 0

7 顺便介绍下umount
umount只能卸载“不忙”的文件系统,如果有任务进程在文件有有读,写操作,这个文件系统都算“繁忙” 可以通过 fuser 命令找出读此目录的进程

–以下umount /pgdata目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@pg1 /]# df -hv  
文件系统 容量 已用 可用 已用% 挂载点
/dev/hda1 14G 6.2G 6.8G 48% /
tmpfs 217M 0 217M 0% /dev/shm
none 217M 104K 217M 1% /var/lib/xenstored
/dev/hdb1 1.1G 34M 1012M 4% /pgdata
/dev/hdb3 1.9G 35M 1.8G 2% /archive/pga
[root@pg1 /]# umount /pgdata
umount: /pgdata: device is busy
umount: /pgdata: device is busy

[root@pg1 /]# fuser -m /pgdata
/pgdata: 3441c
[root@pg1 /]# ps -ef | grep 3441
root 949 3241 0 08:04 pts/1 00:00:00 grep 3441
root 3441 3439 0 07:16 pts/2 00:00:00 -bash
[root@pg1 /]# kill -9 3441
[root@pg1 /]# umount /pgdata

[root@pg1 /]# df -hv
文件系统 容量 已用 可用 已用% 挂载点
/dev/hda1 14G 6.2G 6.8G 48% /
tmpfs 217M 0 217M 0% /dev/shm
none 217M 104K 217M 1% /var/lib/xenstored
/dev/hdb3 1.9G 35M 1.8G 2% /archive/pga

再次查看发现,杀掉进程3441后, /pgdata目录已经 umount了。

最后推荐和张文升共同编写的《PostgreSQL实战》,本书基于PostgreSQL 10 编写,共18章,重点介绍SQL高级特性、并行查询、分区表、物理复制、逻辑复制、备份恢复、高可用、性能优化、PostGIS等,涵盖大量实战用例!

购买链接:https://item.jd.com/12405774.html

PostgreSQL实战
感谢支持!
0%