【linux】新建磁盘、及后续操作

任务1VMWare 加磁盘
1.1. VMWare 虚拟机添加磁盘

1: 右键需要增加磁盘的虚拟机,设置-> 添加按钮


2:选择磁盘, 点击下一步”;


3:选择 SCSI, 下一步


4:选择创建新虚拟磁盘,下一步


5:设置添加磁盘大小, 下一步


6:修改名称或执行路径(默认也可), 完成


7:点击确定按钮, 完成添加磁盘动作



8
: 重启操作系统,使 Linux 系统识别刚刚添加的磁盘

[root@wang ~]# reboot

Broadcast message from root (pts/1) (Wed Aug 31 17:16:08 2016):

 

The system is going down for reboot NOW!

 

9.查看磁盘分区情况:

[root@wang ~]# fdisk -l

 

Disk /dev/sdb: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

Disk /dev/sdb doesn't contain a valid partition table

 

Disk /dev/sda: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14         535     4192965   82  Linux swap / Solaris

/dev/sda3             536        5221    37640295   83  Linux

 

1.2. 对新添加磁盘进行分区
1) fdisk /dev/sdb 进行分区

[root@wang ~]# fdisk /dev/sdb

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 3916.

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): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-3916, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-3916, default 3916): 2100

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@wang ~]#

[root@wang ~]# fdisk /dev/sdb

 

The number of cylinders for this disk is set to 3916.

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)

 

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): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 2

First cylinder (2101-3916, default 2101):

Using default value 2101

Last cylinder or +size or +sizeM or +sizeK (2101-3916, default 3916):

Using default value 3916

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

2) 查看已分区的磁盘

[root@wang ~]# fdisk -l

 

Disk /dev/sdb: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        2100    16868218+  83  Linux

/dev/sdb2            2101        3916    14587020   83  Linux

 

Disk /dev/sda: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14         535     4192965   82  Linux swap / Solaris

/dev/sda3             536        5221    37640295   83  Linux

[root@wang ~]#

 

1.3. 格式化已分区的磁盘

/dev/sdb1, 格式化为文件系统

[root@wang ~]# mkfs -t ext3 /dev/sdb1

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

2109408 inodes, 4217054 blocks

210852 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

129 block groups

32768 blocks per group, 32768 fragments per group

16352 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

        4096000

 

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 31 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@wang ~]#

 

1.4. 挂载文件系统

1) 创建挂载点

[root@wang ~]# mkdir /data

[root@wang ~]# ls -l | grep data

drwxr-xr-x   2 root   root      4096 Aug 31 17:32 data

[root@wang ~]#

 

2) 挂载磁盘

[root@wang ~]# mount /dev/sdb1 /data

[root@wang ~]#

[root@wang ~]# cd /data

[root@wang data]# ls

lost+found

[root@wang data]#

 

1.5. 启用 swap 空间
1) 查看 swap 空间大小

[root@wang data]# free -m

             total       used       free     shared    buffers     cached

Mem:          1988        482       1505          0         35        292

-/+ buffers/cache:        155       1833

Swap:         4094          0       4094

 

2) 启用新增加的 swap 空间

/dev/sdb2, 格式化为 swap 分区

[root@wang ~]# mkswap /dev/sdb2

Setting up swapspace version 1, size = 14937104 kB

 

——启用新的swap分区/dev/sdb2

[root@wang ~]# swapon /dev/sdb2

 

3) 验证已增加的 swap 空间

[root@wang ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1988        495       1492          0         35        293

-/+ buffers/cache:        166       1821

Swap:        18339          0      18339

此时/dev/sdb2还没有挂载;

1.6. 设置磁盘自动挂载

[root@wang ~]# vi /etc/fstab

"/etc/fstab" 8L, 533C

LABEL=/                 /              ext3    defaults        1 1

LABEL=/boot             /boot          ext3    defaults        1 2

tmpfs                   /dev/shm       tmpfs   defaults        0 0

devpts                  /dev/pts       devpts  gid=5,mode=620  0 0

sysfs                   /sys           sysfs   defaults        0 0

proc                    /proc          proc    defaults        0 0

LABEL=SWAP-sda2         swap           swap    defaults        0 0

/dev/sdb1               /data          ext3    defaults        0 0

"/etc/fstab" 8L, 608C written

[root@wang ~]#


任务2: 增加 swap 空间

2.1. 方法一:新建 swap 分区

步骤已在1.5列出;

2.2. 方法二:增加 swap 分区

1) 首先在空间合适处创建用于分区的 swap 文件

省略创建磁盘/dev/sdc及重启生效过程;

 

——查看分区情况:

[root@wang ~]# fdisk -l

 

Disk /dev/sda: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14         535     4192965   82  Linux swap / Solaris

/dev/sda3             536        5221    37640295   83  Linux

 

Disk /dev/sdb: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        2100    16868218+  83  Linux

/dev/sdb2            2101        3916    14587020   83  Linux

 

Disk /dev/sdc: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

Disk /dev/sdc doesn't contain a valid partition table

 

——增加swap分区文件大小
[root@wang ~]# dd if=/dev/sdc of=/home/swapfile bs=1M count=1024

1024+0 records in

1024+0 records out

1073741824 bytes (1.1 GB) copied, 41.7869 seconds, 25.7 MB/s

[root@wang ~]#

if 表示 infileof 表示 outfilebs=1M 代表增加的模块大小, count=1024 代表 1024 个模块,也就是 1G 空间

 

2) /home/swapfile 文件设置为 swap 分区文件

[root@wang ~]# mkswap /home/swapfile

Setting up swapspace version 1, size = 1073737 kB

 

4) 启用 swap 空间

先查看swap分区:

[root@wang ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1988       1060        928          0         10        870

-/+ buffers/cache:        179       1808

Swap:         4094          0       4094

 

启用swap

[root@wang ~]# swapon /home/swapfile

[root@wang ~]#

验证:

[root@wang ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1988       1061        927          0         10        870

-/+ buffers/cache:        180       1807

Swap:         5118          0       5118

[root@wang ~]#

2.3. 设置磁盘自动挂载

[root@wang ~]# vi /etc/fstab

LABEL=/                 /             ext3    defaults        1 1

LABEL=/boot             /boot         ext3    defaults        1 2

tmpfs                   /dev/shm      tmpfs   defaults        0 0

devpts                  /dev/pts      devpts  gid=5,mode=620  0 0

sysfs                   /sys          sysfs   defaults        0 0

proc                    /proc         proc    defaults        0 0

LABEL=SWAP-sda2         swap          swap    defaults        0 0

/dev/sdb1               /data         ext3    defaults        0 0

/dev/sdb2               swap          swap    defaults        0 0

/home/swapfile          swap          swap    defaults        0 0

~

"/etc/fstab" 10L, 760C written

[root@wang ~]#

 

任务3: 扩大 tmpfs
Oracle 11g 引入了 MEMORY_TARGET 参数,memory_target /dev/shm (即 tmpfs)有紧密联系,tmpfs 的大小制约了 memory_target 的使用范围。


1) 查看 tmpfs 大小
默认/dev/shm 为实际物理内存的 1/2,使用 df h 命令查看

SQL> show parameter memory_target;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ----------

memory_target                        big integer 796M

 

--查看tmpfs大小:(默认是物理内存的1/2)

[root@wang ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3              35G   15G   19G  46% /

/dev/sda1              99M   22M   73M  23% /boot

tmpfs                 995M     0  995M   0% /dev/shm

/dev/sdb1              16G  173M   15G   2% /data

[root@wang ~]#

2) 编辑/etc/fstab,增加tmpfs的大小到1.5G;
注: size 的大小必须是整数, 比如: 要加大至 1.5g, 那么, size 不能写成 1.5g, 而要写成 1500M, 因为 1.5 非整数

[root@wang ~]# vi /etc/fstab

 

"/etc/fstab" 10L, 760C

LABEL=/             /           ext3    defaults        1 1

LABEL=/boot         /boot       ext3    defaults        1 2

tmpfs              /dev/shm  tmpfs defaults,size=1500M  0 0

devpts             /dev/pts     devpts  gid=5,mode=620  0 0

sysfs              /sys         sysfs   defaults        0 0

proc               /proc        proc    defaults        0 0

LABEL=SWAP-sda2         swap    swap    defaults        0 0

/dev/sdb1               /data   ext3    defaults        0 0

/dev/sdb2               swap    swap    defaults        0 0

/home/swapfile          swap    swap    defaults        0 0

~

"/etc/fstab" 10L, 771C written

[root@wang ~]#


3) 重新挂载(即使新设置的tmpfs大小生效)也可以用一条命令完成: # mount -o remount /dev/shm)

[root@wang ~]# umount /dev/shm   (先卸载)

[root@wang ~]# mount tmpfs /dev/shm  (再挂载)

mount: you must specify the filesystem type

You have new mail in /var/spool/mail/root
——解决:(直接将写挂载点,省略文件系统)

[root@wang ~]# mount /dev/shm

 

4) 验证

[root@wang ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3              35G   15G   19G  46% /

/dev/sda1              99M   22M   73M  23% /boot

/dev/sdb1              16G  173M   15G   2% /data

tmpfs                 1.5G     0  1.5G   0% /dev/shm

 

请使用浏览器的分享功能分享到微信等