① 如何给虚拟机里面的linux添加磁盘
Linux添加硬盘是在原来安装的硬盘空间不够或者需要使用其他硬盘上的东西时候的解决办法,因为大多数初学者习惯使用虚拟机,这里以在Vmware虚拟机中实现linux添加硬盘的具体步骤来详细介绍说这个问题。
Vmware中为linux增加硬盘
1. 在vmware的setting中为虚拟机增加一个硬盘。
2. 在vmware中看见 第1个硬盘是 /dev/sda , 第2个硬盘是 /dev/sdb
3. 创建硬盘信息
fdisk /dev/sdb
a. 按n添加分区,选p(主分区);
b. 选1,也就是sdb1;
c. 然后就是空间划分,一路回车。默认是使用整个磁盘空间。
d. 然后按w写入分区信息
4. 格式化硬盘
mkfs -t ext3 /dev/sdb1
5. 创建需要mount的目录
mkdir -p /opt
6. mount到指定的目录
mount /dev/sdb1 /opt -o rw
7. 如果需要每次启动加载,修改/etc/fstab文件
在fstab文件里面添加一行:
/dev/sdb1 /opt ext3 defaults 1 1
这样我们就完成了在虚拟机上Linux添加硬盘问题的解决。
② linux虚拟机怎么添加新硬盘sdb
关机,编辑虚拟机设置,添加硬盘,启动虚拟机,就有sdb了
③ linux虚拟机卸载新硬盘的方法
装载:
1、启动vm,选择->Settings,按向导添加一块SCSI磁盘。进入Linux系统。
2、 fdisk -l 会看到有一块新的设置,如果你先前有一块硬盘(sda1, sda3...),新加的这块应该是(/dev/sdb)。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda3 14 1044 8281507+ 83 Linux
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
3、分区:
[root@localhost ~]# 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 1044.
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-1044, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044):
Using default value 1044
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda3 14 1044 8281507+ 83 Linux
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 83 Linux
4、格式化:
[root@localhost ~]# 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)
1048576 inodes, 2096474 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
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.
5、装载:
[root@localhost ~]# mount /dev/sdb1 /u01/app/oracle
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6.7G 5.8G 576M 92% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 233M 0 233M 0% /dev/shm
/dev/sdb1 7.9G 147M 7.4G 2% /u01/app/oracle
6、编辑fstab文件(不然重启电脑后系统将不会保存之前的挂载操作):
[root@localhost ~]# vi /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
/dev/sdc1 /u03 ext3 defaults 1 1
/dev/sdb1 /u01/app/oracle ext3 defaults 1 1
# Beginning of the block added by the VMware software
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5 0 0
# End of the block added by the VMware software
卸载:
[root@localhost ~]# umount /dev/sdb1
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6.7G 5.8G 576M 92% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 233M 0 233M 0% /dev/shm
④ 虚拟机新增硬盘,如何让Linux系统识别到
1、重启系统(不用动脑就搞定)
有人说,我比较懒,不想动脑,那么这种方法(重启系统,一切搞定)很适合你。
那么,万一要是此Linux系统有业务正在运行,而又不能重启呢?咋办,这时就要动手+动脑了。
出绝招了,请看下面方法。
2、执行命令,重新scan设备
#先cd到/sys/class/scsi_host/目录
[root@ilinux /]# cd /sys/class/scsi_host/
#我们来看看scsi_host目录有啥东西呢,这里有三个子目录哦
[root@ilinux scsi_host]# ls
host0 host1 host2
#执行如下命令
[root@ilinux scsi_host]# echo "- - -" > host0/scan
注意:“- - -”这三个“-”中间有空格滴。
#用fdisk命令来查看下吧
[root@ilinux scsi_host]# fdisk -l
#如果还是没有识别到,别着急,go on;
[root@ilinux scsi_host]# echo "- - -" > host1/scan
[root@ilinux scsi_host]# echo "- - -" > host2/scan
#我们再分别执行下上面host1和host2的命令,再fdisk下吧! [root@ilinux scsi_host]# fdisk -l
Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d1499
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 281 20887 165518336 83 Linux
Disk /dev/sdb: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
⑤ 虚拟机刚装了linux 系统,如何添加一块新硬盘
打开VMware Workstation
1、编辑虚拟机设置
2、硬件-添加-硬盘-下一步
选择使用物理磁盘,后面的步骤选择新硬盘即可。
⑥ linux虚拟机上怎么添加硬盘
虚拟机中的Linux添加新硬盘的方法
方法/步骤
1
打开VMware Workstation
1、编辑虚拟机设置
2、硬件-添加-硬盘-下一步
3.然后出现如下图:选择“创建一个新的虚拟磁盘(V)”
4.选择新磁盘的类型,设置默认如图:
5.选择新硬盘所在的虚拟位置:
6.设置新添加的硬盘的容量:
完成后的设备列表,可以看到已经多出一个2GB大小的硬盘:
然后启动虚拟机,进入打开终端,输入:fdisk –l 然后就可以看到已经发现了新的硬盘,大小为:2147MB。
然后输入:fdisk/dev/sdb 给新硬盘分区输入n ,进行分区,让我们选择1-4,那我们可以选择1
然后就一直回车。
当出现:Command (m for help):后再输入W ,存盘退出fdisk模式,完成后,我们对新硬盘进行格式化,输入Mkfs –t ext3 /dev/sdb出现Proceed anyway?(y,n)时,这时输入“Y”回车。
格式化完成后,我们要做的就是对新硬盘设定挂载点,可以新建目录,例如:mkdir /newdisk然后把新硬盘挂载到这个位置:mount /dev/sdb /newdisk 挂载好了,查看一下:df
12
还没有结束,我们要让系统重启后会自动挂载新硬盘,编辑:vi /etc/fstab 按Insert键插入一行:/dev/sdb/newdiskext31 2 ,输入完毕后Esc :wq保存退出,新硬盘也就添加完毕了。
⑦ 在虚拟机中如何添加一个虚拟的磁盘给linux系统
1.备份了/tmp目录
sudo
cp
/tmp
./tmp.old
2.删除/tmp目录做一个新的软连接
sudo
rm
/tmp
sudo
ln
-s
用户主目录
/tmp
经过第二步,/tmp依然存在,但是这个时候数据到/tmp目录时,并不是存放在/tmp下,而是放在用户主目录下。由于用户主目录的空间很大,这样就解决了/tmp空间不足的问题,最终达到了他想要的结果。只要想办法,问题总是可以解决的。
现在来看看,怎样给已装好的linux系统增加磁盘空间
退出linux系统,在vmware启动界面中选择vm菜单下的settings来增加磁盘,然后选择add,选择hard
disk,点击next。
选中create
a
new
virtual
disk,点击下一步,选择scsi,继续下一步。选择好你要新增磁盘的大小,勾选allocate
all
disk
space
now立即分配空间,下一步,在你的硬盘上选择一个目录来创建,点击完成结束。这样,一个新增的空间就创建好了。
输入新增这块硬盘的名字,它会默认放置在虚拟机所在的位置。
接着就能看到分好的硬盘了
进入linux系统,使用fdisk
-l可以看到如下效果
sudo
fdisk
-l
这里可以看到/dev/sdb就是我们新添加的硬盘,需要给新的硬盘分区。
1.
在终端输入:sudo
fdisk
/dev/sdb
之后键入:m,可以看到帮助信息
键入:n,添加新分区
键入:p,选择添加主分区
键入:1,选择主分区号为1,这样创建后的主分区为sdb1
之后,fdsik会让你选择该分区的开始值和结束值,直接回车
2.格式化磁盘
在终端输入:mkfs
-t
ext4
/dev/sdb1
用ext3格式对/dev/sdb1进行格式化
最后键入:w,保存所有并退出,完成新硬盘的分区
3.在用户主目录下新建一个文件,
如/home/linux/newdisk。以后就把新增的分区mount到这个目录下。
4.用root权限打开/etc/fstab文件。新增加一个选项。具体fstab的操作在这里不解释了。新增加如下:/dev/sdb1
/home/linux/newdisk
ext4
defaults
0
0
5.重新启动系统,就能看到你加载的硬盘了
注意:这个时候进入/home/linux/newdisk新建文件的时候,可能提示权限不够,
解决办法:sudo
chmod
777
/home/linux/newdisk。