【转】ubuntu如何修改/添加/删除硬盘分区的挂载(点)?
我(macroliu)的问题:安装ubuntu时,/home单独挂载在一个分区,此后我想调整分区大小,删除了/home对应的分区以及另外几个分区,导致开机时找不到挂载点。把硬盘空闲空间分好区后,想把1个分区重新挂载到/home。
挂载点设置在etc/fstab文件里,先打开这个文件。
$ gedit /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' 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/sda2 during installation
UUID=7b1c60be-8b84-4459-9bef-9559d9431447 / ext4 errors=remount-ro 0 1
#/homewas on /dev/sda5 during installation
UUID=3aa554c2-e8ea-4f35-819f-7cb4573c0d67 /home ext4 defaults 0 2
# /windows was on /dev/sda6 during installation
# UUID=50C5-059A /windows vfat utf8,umask=007,gid=46 0 1
#swapwas on /dev/sda3 during installation
UUID=8c5324bb-9e42-422d-b507-26bafa5ac7de none swap sw 0 0
显然,当我格式化分区(删除分区?)后,分区的uuid变了,所以找不到了。
查找分区UUID的方法如下:
在终端的窗口里输入命令:
$ fdisk -l
Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 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: 0xf517e314
Device Boot Start End Blocks Id System
/dev/sda1 * 1 5222 41945683+ 7 HPFS/NTFS
/dev/sda2 5223 7712 19999744 83 Linux
/dev/sda3 7712 7961 1999872 82 Linux swap / Solaris
/dev/sda4 7962 38913 248621940 5 Extended
/dev/sda5 7962 17687 78124063+ 83 Linux
/dev/sda6 17688 25520 62918541 7 HPFS/NTFS
/dev/sda7 25521 38913 107579241 7 HPFS/NTFS
这里可以看到/dev/sda5,这应该是我想挂载在home下的分区。
$ ls -l /dev/disk/by-uuid
看一下sda5的UUID
总计 0
lrwxrwxrwx 1 root root 10 2011-04-03 16:06 3aa554c2-e8ea-4f35-819f-7cb4573c0d67 -> ../../sda5
lrwxrwxrwx 1 root root 10 2011-04-03 16:06 4E8091348091240D -> ../../sda7
lrwxrwxrwx 1 root root 10 2011-04-03 16:06 7b1c60be-8b84-4459-9bef-9559d9431447 -> ../../sda2
lrwxrwxrwx 1 root root 10 2011-04-03 16:06 8c5324bb-9e42-422d-b507-26bafa5ac7de -> ../../sda3
lrwxrwxrwx 1 root root 10 2011-04-03 16:06 AAA87F76A87F403D -> ../../sda6
lrwxrwxrwx 1 root root 10 2011-04-03 16:06 C478ECC978ECBAF6 -> ../../sda1
将sda5的UUID填到fstab关于home的挂载那一行。
另外,windows这个挂载点我不需要了,将fstab对应那几行用#号注掉。
补充:
通过修改etc/fstab方式, 不仅可以增加/删除同一个硬盘里各个分区的挂载, 也可以增加/删除其它硬盘里各个分区的挂载.
比如: ubutnu服务器初始安装时只有一个硬盘, 分成3个区挂载了"/", "/home", "swap". 开发团队里各个人均在/home下有个目录来存放项目文件. 后来又买了个硬盘分成1个分区, 但不挂载. 则开机后这个分区会被当作外部设备mount到/media目录. 这样使用起来不方便, 如果想把它挂载到"/home/disk2", 则在etc/fstab文件增加一行对应记录即可.