一.环境:发行版本:ubuntu 14.04 64bit
二.获取要指定的用户及组id
使用id命令 (笔者获取的uid和gid都为1000)
三.获取识别的硬盘路径
sudo fdisk -l (笔者获取的路径是/dev/sdb1)
四.挂载fat(分区为fat文件系统才具有uid和gid选项)
sudo mount /dev/sdb1 /media -o uid=1000,gid=1000
五.挂载ext4
sudo mount /dev/sdb1 /media
再改一下权限:
sudo chown -R jello:jello /media (jello为笔者的用户名)
六.设置开机启动自动挂载
6.1 获取分区的uuid
sudo blkid
笔者的分区信息如下:
jello@jello:~$sudo blkid
/dev/sda1: UUID="DA70A0E270ACFGDR" TYPE="ntfs" PARTUUID="06cdfc10-01"
/dev/sda5: UUID="C63C5C1B4C543565" TYPE="ntfs" PARTUUID="06cdfc10-05"
/dev/sda6: LABEL="M-fM-^VM-^GM-fM-!M-#" UUID="000A053400091250" TYPE="ntfs" PARTUUID="06cdfc10-06"
/dev/sda7: LABEL="LFS" UUID="97df8b03-00d2-438a-8ed9-d2c263165021" TYPE="ext4" PARTUUID="06cdfc10-07"
/dev/sda8: UUID="bef418fa-4202-4513-b456-cde6a5d9753f" TYPE="ext4" PARTUUID="06cdfc10-08"
/dev/sda9: UUID="b68643ba-bcc0-4ed4-8325-8b9b0defc53c" TYPE="ext4" PARTUUID="06cdfc10-09"
/dev/sdb1: UUID="1faecb5a-a14d-4ac5-a47f-b3895d6f827e" TYPE="ext4" PARTUUID="d26fd14f-01"
/dev/sdb2: UUID="cf116c95-b7f0-4ce4-b0da-7f2856784c43" TYPE="ext4" PARTUUID="d26fd14f-02"
笔者想挂载/dev/sdb2分区
6.2打开文件/etc/fstab
sudo vi /etc/fstab
6.2 往etc/fstab文件中加入以下内容:
UUID=cf116c95-b7f0-4ce4-b0da-7f2856784c43 /media ext4 defaults 0 2
6.3 重新启动即可生效