微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

给ubuntu14.04Desktop 64Bit版本加一个硬盘草稿版本

http://zwkufo.blog.163.com/blog/static/258825120141283942244/ Ubuntu环境下挂载新硬盘 2014-02-28 16:22:12| 分类: Linux | 标签:ubuntu 硬盘 挂载 配置 |举报|字号 订阅 下载LOFTER我的照片书 | Ubuntu系统的硬盘空间不够用了,需要增加新的硬盘扩容。将硬盘分区、格式化、自动挂载配置的整个过程记下来,备忘。 一、硬盘分区 | Hard disk add new partition 1、显示硬盘及所属分区情况。在终端窗口中输入如下命令: sudo fdisk -lu 显示当前的硬盘及所属分区的情况。如下图所示: 系统提示disk /dev/sdb doesn't contain a valid partition table。 Ubuntu环境下挂载新硬盘 rootroot@cm-System-Product-Name:~$ rootroot@cm-System-Product-Name:~$ sudo fdisk -lu disk /dev/sda: 2000.4 GB,2000398934016 bytes 255 heads,63 sectors/track,243201 cylinders,total 3907029168 sectors Units = 扇区 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes disk identifier: 0x00027761 设备 启动 起点 终点 块数 Id 系统 /dev/sda1 2046 3907028991 1953513473 5 扩展 /dev/sda5 2048 3907028991 1953513472 83 Linux disk /dev/sdb: 2000.4 GB,total 3907029168 sectors Units = 扇区 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes disk identifier: 0x00000000 disk /dev/sdb doesn't contain a valid partition table disk /dev/sdc: 3000.6 GB,3000592982016 bytes 255 heads,364801 cylinders,total 5860533168 sectors Units = 扇区 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes disk identifier: 0x00000000 disk /dev/sdc doesn't contain a valid partition table disk /dev/sdd: 240.1 GB,240057409536 bytes 255 heads,29185 cylinders,total 468862128 sectors Units = 扇区 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes disk identifier: 0x00058aad 设备 启动 起点 终点 块数 Id 系统 /dev/sdd1 * 2046 423940095 211969025 5 扩展 /dev/sdd2 423940096 468860927 22460416 83 Linux /dev/sdd5 2048 501759 249856 83 Linux /dev/sdd6 503808 9879551 4687872 82 Linux 交换 / Solaris /dev/sdd7 9881600 423940095 207029248 83 Linux rootroot@cm-System-Product-Name:~$ rootroot@cm-System-Product-Name:~$ 2、对硬盘进行分区。在终端窗口中输入如下命令: sudo fdisk /dev/sdb 如下图所示: 在Command (m for help)提示符后面输入m显示一个帮助菜单。 Ubuntu环境下挂载新硬盘 rootroot@cm-System-Product-Name:~$ rootroot@cm-System-Product-Name:~$ sudo fdisk /dev/sdc Device contains neither a valid DOS partition table,nor Sun,sgi or OSF disklabel Building a new DOS disklabel with disk identifier 0x8aa85295. Changes will remain in memory only,until you decide to write them. After that,of course,the prevIoUs content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: The size of this disk is 3.0 TB (3000592982016 bytes). DOS partition table format can not be used on drives for volumes larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID partition table format (GPT). The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended,or performance may be impacted. 命令(输入 m 获取帮助): m 命令操作 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) 命令(输入 m 获取帮助): 在Command (m for help)提示符后面输入n,执行 add a new partition 指令给硬盘增加一个新分区。 出现Command action时,输入e,指定分区为扩展分区(extended)。 出现Partition number(1-4)时,输入1表示只分一个区。 后续指定起启柱面(cylinder)号完成分区。 Ubuntu环境下挂载新硬盘 命令(输入 m 获取帮助): n Partition type: p primary (0 primary,0 extended,4 free) e extended Select (default p): e 分区号 (1-4,认为 1): 1 起始 sector (2048-4294967295,认为 2048): 将使用认值 2048 Last sector,+扇区 or +size{K,M,G} (2048-4294967294,认为 4294967294): 将使用认值 4294967294 命令(输入 m 获取帮助): 在Command (m for help)提示符后面输入p,显示分区表。 系统提示如下: Device Boot Start End Blocks Id System /dev/sdb1 1 26108 209712478+ 5 Extended Ubuntu环境下挂载新硬盘 命令(输入 m 获取帮助): p disk /dev/sdc: 3000.6 GB,total 5860533168 sectors Units = 扇区 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes disk identifier: 0x8aa85295 设备 启动 起点 终点 块数 Id 系统 /dev/sdc1 2048 4294967294 2147482623+ 5 扩展 命令(输入 m 获取帮助): 在Command (m for help)提示符后面输入w,保存分区表。 系统提示:The partition table has been altered! Ubuntu环境下挂载新硬盘 命令(输入 m 获取帮助): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. rootroot@cm-System-Product-Name:~$ 在终端窗口中输入如下命令: sudo fdisk -lu 如下图所示: 系统已经识别了硬盘 /dev/sdb 的分区。 Ubuntu环境下挂载新硬盘 rootroot@cm-System-Product-Name:~$ sudo fdisk -lu disk /dev/sda: 2000.4 GB,3000592982016 bytes 90 heads,3 sectors/track,21705678 cylinders,total 5860533168 sectors Units = 扇区 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes disk identifier: 0x8aa85295 设备 启动 起点 终点 块数 Id 系统 /dev/sdc1 2048 4294967294 2147482623+ 5 扩展 disk /dev/sdd: 240.1 GB,total 468862128 sectors Units = 扇区 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes disk identifier: 0x00058aad 设备 启动 起点 终点 块数 Id 系统 /dev/sdd1 * 2046 423940095 211969025 5 扩展 /dev/sdd2 423940096 468860927 22460416 83 Linux /dev/sdd5 2048 501759 249856 83 Linux /dev/sdd6 503808 9879551 4687872 82 Linux 交换 / Solaris /dev/sdd7 9881600 423940095 207029248 83 Linux rootroot@cm-System-Product-Name:~$ 二、硬盘格式化 | Format hard disk 1、显示硬盘及所属分区情况。在终端窗口中输入如下命令: sudo mkfs -t ext4 /dev/sdb 说明: -t ext4 表示将分区格式化成ext4文件系统类型。 Ubuntu环境下挂载新硬盘 rootroot@cm-System-Product-Name:~$ rootroot@cm-System-Product-Name:~$ sudo mkfs -t ext4 /dev/sdc mke2fs 1.42.9 (4-Feb-2014) /dev/sdc is entire device,not just one partition! 无论如何也要继续? (y,n) y 文件系统标签= OS type: Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks,Stripe width=0 blocks 183148544 inodes,732566646 blocks 36628332 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=4294967296 22357 block groups 32768 blocks per group,32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768,98304,163840,229376,294912,819200,884736,1605632,2654208,4096000,7962624,11239424,20480000,23887872,71663616,78675968,102400000,214990848,512000000,550731776,644972544 Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 rootroot@cm-System-Product-Name:~$ 三、挂载硬盘分区 | Mount hard disk partition 1、显示硬盘挂载情况。在终端窗口中输入如下命令: sudo df -l 新硬盘分区没有挂载,无法进入和查看。 rootroot@cm-System-Product-Name:~$ rootroot@cm-System-Product-Name:~$ sudo df -l 文件系统 1K-blocks 已用 可用 已用% 挂载点 /dev/sdd2 21976268 6501312 14335552 32% / none 4 0 4 0% /sys/fs/cgroup udev 8175996 4 8175992 1% /dev tmpfs 1637348 1396 1635952 1% /run none 5120 0 5120 0% /run/lock none 8186732 76 8186656 1% /run/shm none 102400 48 102352 1% /run/user /dev/sdd5 237869 35858 185423 17% /boot /dev/sda5 1922728752 1805924332 19112364 99% /home /dev/sdb 1922729864 1536942996 288094756 85% /home/cb2t1651 /dev/sdd7 203648856 127989080 65291932 67% /home/wwt rootroot@cm-System-Product-Name:~$ rootroot@cm-System-Product-Name:~$ 在终端窗口中输入如下命令: sudo mount -t ext4 /dev/sdb /devdata 说明: 指定硬盘分区文件系统类型为ext4 ,同时将 /dev/sdb 分区挂载到目录 /devdata。 rootroot@cm-System-Product-Name:~$ sudo mount -t ext4 /dev/sdc /home/rediron mount:挂载点 /home/rediron 不存在 rootroot@cm-System-Product-Name:~$ mkdir /home/rediron mkdir: 无法创建目录"/home/rediron": 权限不够 rootroot@cm-System-Product-Name:~$ sudo mkdir /home/rediron rootroot@cm-System-Product-Name:~$ sudo chmod 777 /home/rediron/ -R rootroot@cm-System-Product-Name:~$ sudo mount -t ext4 /dev/sdc /home/rediron 再次在终端窗口中输入如下命令: sudo df -l 新硬盘分区已经挂载,如下图最下面的红色方框内容。 Ubuntu环境下挂载新硬盘 rootroot@cm-System-Product-Name:~$ sudo df -l 文件系统 1K-blocks 已用 可用 已用% 挂载点 /dev/sdd2 21976268 6501340 14335524 32% / none 4 0 4 0% /sys/fs/cgroup udev 8175996 4 8175992 1% /dev tmpfs 1637348 1396 1635952 1% /run none 5120 0 5120 0% /run/lock none 8186732 76 8186656 1% /run/shm none 102400 48 102352 1% /run/user /dev/sdd5 237869 35858 185423 17% /boot /dev/sda5 1922728752 1805924336 19112360 99% /home /dev/sdb 1922729864 1536942996 288094756 85% /home/cb2t1651 /dev/sdd7 203648856 127989080 65291932 67% /home/wwt /dev/sdc 2884154032 74736 2737549584 1% /home/rediron rootroot@cm-System-Product-Name:~$ 2、配置硬盘在系统启动自动挂载。在文件 /etc/fstab 中加入如下配置: # /devdata was on /dev/sdb UUID=37eaa526-5d96-4237-8468-603df5216ce9 /devdata ext4 defaults 0 3 Ubuntu环境下挂载新硬盘 rootroot@cm-System-Product-Name:~$ 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> # / was on /dev/sdb2 during installation UUID=ef4a9a3d-a8a7-476d-b85c-ebc1eaf7ec75 / ext4 errors=remount-ro 0 1 # /boot was on /dev/sdb5 during installation UUID=058b1b8d-16cd-4cd7-9009-50ebd95a87ba /boot ext4 defaults 0 2 # /home was on /dev/sda5 during installation UUID=fb2b6d90-9e78-420c-b02c-c94074f2df2e /home ext4 defaults 0 2 # /home/wwt was on /dev/sdb7 during installation UUID=5353d865-0eb1-4d39-88ea-cb7eb0135e0f /home/wwt ext4 defaults 0 2 # swap was on /dev/sdb6 during installation UUID=4a0354b9-2d36-4ae0-86d8-9d78da16771f none swap sw 0 0 # 2016-12-16 14:47 wenyuanbo add 2TB SeaGate HDD /dev/sdb /home/cb2t1651/ ext4 defaults 0 0 rootroot@cm-System-Product-Name:~$ ========================== /etc/fstab 配置 注意!!========================== 这一部分我的设置与原作者不同,用上面无法成功自动挂载的话,请尝试下面的配置: rootroot@cm-System-Product-Name:~$ ll /etc/fstab -rw-rw-r-- 1 root root 1129 12月 16 14:49 /etc/fstab rootroot@cm-System-Product-Name:~$ cp /etc/fstab /home/wwt/ rootroot@cm-System-Product-Name:~$ chmod 777 /home/wwt/fstab rootroot@cm-System-Product-Name:~$ cd /etc/ rootroot@cm-System-Product-Name:/etc$ ll fs* -rw-rw-r-- 1 root root 1129 12月 16 14:49 fstab -rw-rw-r-- 1 root root 1009 8月 10 2016 fstab~ -rw-r--r-- 1 root root 1009 12月 16 14:44 fstab.bak fstab.d: 总用量 16 drwxr-xr-x 2 root root 4096 4月 17 2014 ./ drwxr-xr-x 135 root root 12288 5月 4 10:21 ../ rootroot@cm-System-Product-Name:/etc$ sudo cp fstab fstab.bak2 rootroot@cm-System-Product-Name:/etc$ cd - /home/rootroot rootroot@cm-System-Product-Name:~$ sudo cp /home/wwt/fstab /etc/ rootroot@cm-System-Product-Name:~$ ll /etc/fstab -rw-rw-r-- 1 root root 1201 5月 4 10:26 /etc/fstab rootroot@cm-System-Product-Name:~$ sync rootroot@cm-System-Product-Name:~$ rootroot@cm-System-Product-Name:~$ rootroot@cm-System-Product-Name:~$ 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> # / was on /dev/sdb2 during installation UUID=ef4a9a3d-a8a7-476d-b85c-ebc1eaf7ec75 / ext4 errors=remount-ro 0 1 # /boot was on /dev/sdb5 during installation UUID=058b1b8d-16cd-4cd7-9009-50ebd95a87ba /boot ext4 defaults 0 2 # /home was on /dev/sda5 during installation UUID=fb2b6d90-9e78-420c-b02c-c94074f2df2e /home ext4 defaults 0 2 # /home/wwt was on /dev/sdb7 during installation UUID=5353d865-0eb1-4d39-88ea-cb7eb0135e0f /home/wwt ext4 defaults 0 2 # swap was on /dev/sdb6 during installation UUID=4a0354b9-2d36-4ae0-86d8-9d78da16771f none swap sw 0 0 # 2016-12-16 14:47 wenyuanbo add 2TB SeaGate HDD /dev/sdb /home/cb2t1651/ ext4 defaults 0 0 /dev/sdc /home/rediron ext4 defaults 0 0 rootroot@cm-System-Product-Name:~$ Ubuntu环境下挂载新硬盘 其中,“/Projects”与“/AMAX”都是挂载点,可以根据需要自定义。 上面是ext4格式硬盘为例子。如果是ntfs,则“ext4”要修改为“auto”,“defaults”要修改为“nosuid,nodev,nofail”。 在Ubuntu,可以使用更直观的方式:用系统自带disks或者disk Utility界面化工具。 ========================================================================= 附录1:fdisk命令详解 | Appendix part 1: fdisk command Syntax fdisk 命令的语法如下: fdisk [-b sectorsize] device fdisk -l [-u] [device...] fdisk -s partition... fdisk -v 说明: -b 指定每个分区的大小。也可以执行fdisk device(如:fdisk /dev/sdb)后,在系统提示时指定。 -l 列出指定的外围设备的分区表状况。如果仅执行 fdisk -l ,系统会列出已知的分区。 -u 搭配"-l"参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址。 -s 将指定的分区的大小输出到标准输出上,单位为区块。 -v 显示fdisk的版本信息。 附录2:mkfs命令详解 | Appendix part 2: mkfs command Syntax mkfs 命令的语法如下: mkfs [-V] [-t fstype] [fs-options] filesys 说明: -V 显示简要的使用方法。 -t 指定要建立何种文件系统,如:ext3,ext4。 fs 指定建立文件系统时的参数。 -v 显示版本信息与详细的使用方法。 附录3:mount命令详解 | Appendix part 3: mount command Syntax mkfs 命令的语法如下: mount [-afFnrsvw] [-t vfstype] [-L label] [-o options] device dir mount [-lhv] 说明: -a 加载文件/etc/fstab中设置的所有设备。 -f 不实际加载设备。可与-v等参数同时使用以查看mount的执行过程。 -F 需与-a参数同时使用。所有在/etc/fstab中设置的设备会被同时加载,可加快执行速度。 -t vfstype 指定加载的文件系统类型,如:ext3,ext4。 -L label 给挂载点指定一个标签名称。 -l 显示分区的label。 -h 显示帮助信息。 -v 显示mount的版本信息。 device 要挂载的分区或文件。如果device是一个文件,挂载时须加上 -o loop参数。 dir 分区的挂载点。 附录4:fstab配置详解 | Appendix part 4: fstab detail configuration /etc/fstab 中一共有6列: file system:指定要挂载的文件系统的设备名称(如:/dev/sdb)。也可以采用UUID,UUID可以通过使用blkid命令来查看(如:blkid /dev/sdb)指定设备的UUID号。 mount point:挂载点。就是自己手动创建一个目录,然后把分区挂载到这个目录下。 type:用来指定文件系统的类型。如:ext3,ext4,ntfs等。 option dump:0表示不备份;1表示要将整个中的内容备份。此处建议设置为0。 pass:用来指定fsck如何来检查硬盘。0表示不检查;挂载点为分区/(根分区)必须设置为1,其他的挂载点不能设置为1;如果有挂载ass设置成大于1的值,则在检查完根分区后,然后按pass的值从小到大依次检查,相同数值的同时检查。如:/home 和 /boot 的pass 设置成2,/devdata 的pass 设置成3,则系统在检查完根分区,接着同时检查/boot和/home,再检查/devdata。 【非常感谢 hitrust,这篇文章90%的内容来自他的《Ubuntu - 硬盘分区、格式化、自动挂载配置》】 【本文链接:http://zwkufo.blog.163.com/blog/static/258825120141283942244/】

原文地址:https://www.jb51.cc/ubuntu/353098.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐