给vmware的ubuntu虚拟机增加硬盘、增加新的分区并自动挂载

本文介绍了如何在Ubuntu系统中自动挂载新增的硬盘分区。通过编辑/etc/fstab文件并利用UUID来标识设备,确保即使在磁盘变动的情况下也能正确挂载。此外,还介绍了使用mount命令手动挂载分区的方法,并推荐了一款名为mountpy的Python工具,简化了挂载过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考 http://qingyang.me/2012/ubuntu-1204-automatically-mount-other-partitions-on-system-startup/





root@Ubuntu32:/etc/init.d# 

把第二块硬盘sdb的信息加入到 /etc/fstab中,就可以自动挂载


root@Ubuntu32:/etc/init.d# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=7c76f0b7-85c4-4a27-9bf1-b7c2f3d4aa4e /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
UUID=0f42e1e0-a4cb-4b88-9d66-3281612cd77c none            swap    sw              0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0
UUID=8767f1c9-3fa5-49ec-b18d-c2c8600abd34 /home/zhangbin/alex ext4 defaults 0 2


root@Ubuntu32:/etc/init.d# 
root@Ubuntu32:/etc/init.d# mount -t /dev/sda3 /home/zhangbin/zbhome
Usage: mount -V                 : print version
       mount -h                 : print this help
       mount                    : list mounted filesystems
       mount -l                 : idem, including volume labels
So far the informational part. Next the mounting.
The command is `mount [-t fstype] something somewhere'.
Details found in /etc/fstab may be omitted.
       mount -a [-t|-O] ...     : mount all stuff from /etc/fstab
       mount device             : mount device at the known place
       mount directory          : mount known device here
       mount -t type dev dir    : ordinary mount command
Note that one does not really mount a device, one mounts
a filesystem (of the given type) found on the device.
One can also mount an already visible directory tree elsewhere:
       mount --bind olddir newdir
or move a subtree:
       mount --move olddir newdir
One can change the type of mount containing the directory dir:
       mount --make-shared dir
       mount --make-slave dir
       mount --make-private dir
       mount --make-unbindable dir
One can change the type of all the mounts in a mount subtree
containing the directory dir:
       mount --make-rshared dir
       mount --make-rslave dir
       mount --make-rprivate dir
       mount --make-runbindable dir
A device can be given by name, say /dev/hda1 or /dev/cdrom,
or by label, using  -L label  or by uuid, using  -U uuid .
Other options: [-nfFrsvw] [-o options] [-p passwdfd].
For many more details, say  man 8 mount .

=============

这次新增加一个分区


























================

挂载一个新增加的分区到一个目录下:

root@Ubuntu32:/etc/init.d# mount -t ext4 /dev/sda3 /home/zhangbin/zbhome
root@Ubuntu32:/etc/init.d# 



把这个命令加入到 /etc/rc.local


==============

参考 http://www.blogbus.com/apit-logs/62852260.html


这个文章还介绍了一个mount的封装的py工具:


[sudo] password for zhangbin: 
root@Ubuntu32:/home/zhangbin# apt-get install mountpy
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  mountpy
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.4 kB of archives.
After this operation, 98.3 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/universe mountpy i386 0.8.1 [12.4 kB]
Fetched 12.4 kB in 0s (21.8 kB/s)
Selecting previously unselected package mountpy.
(Reading database ... 566309 files and directories currently installed.)
Unpacking mountpy (from .../mountpy_0.8.1_i386.deb) ...
Processing triggers for man-db ...
Setting up mountpy (0.8.1) ...
root@Ubuntu32:/home/zhangbin# 
root@Ubuntu32:/home/zhangbin# 
root@Ubuntu32:/home/zhangbin# mountpy
/dev/sdb seems to be already mounted on /home/zhangbin/alex                    
/dev/sda3 seems to be already mounted on /home/zhangbin/zbhome                    
/dev/sda1 seems to be already mounted on /                    
Found nothing to mount                    
root@Ubuntu32:/home/zhangbin# gedit /etc/rc.local 
root@Ubuntu32:/home/zhangbin# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

等风来不如迎风去

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值