Ubuntu磁盘管理
2011-04-18 11:36 RayLee 阅读(2736) 评论(0) 编辑 收藏 举报为避免风险,建议你在虚拟机里面先玩玩,如果你已经掌握这些方法并深知可能的风险,you just do it。
gparted是Ubuntu上一个很好的图形化磁盘管理工具(使用“sudo apt-get install gparted”安装),直观,易用,适合新手。
1. 如何添加一块新硬盘
Virtual Machine Setting -> Add -> Hard Disk -> create a new virtual disk -> ...
添加成功后,启动Ubuntu。
1)查看硬盘信息:
ray@ray-ubuntu:~$ sudo fdisk -l
[sudo] password for ray:
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0001d2ab
Device Boot Start End Blocks Id System
/dev/sda1 * 1 5036 40450048 83 Linux
/dev/sda2 5037 5222 1489921 5 Extended
/dev/sda5 5037 5222 1489920 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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
Disk /dev/sdb doesn't contain a valid partition table
从显示信息看,包含两块硬盘,分别为/dev/sda和/dev/sdb,对应的容量为42.9G和10.7G。/dev/sdb当前还未分区。
2)给/dev/sdb分区
ray@ray-ubuntu:~$ sudo fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
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)
选择n,添加一个新分区。接着选择默认设置即可。最后选w,执行操作并退出。
完成后,再次检查硬盘信息。
ray@ray-ubuntu:~$ sudo fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0001d2ab
Device Boot Start End Blocks Id System
/dev/sda1 * 1 5036 40450048 83 Linux
/dev/sda2 5037 5222 1489921 5 Extended
/dev/sda5 5037 5222 1489920 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x976fd8e8
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
经确认,新增的硬盘分区成功。
2. 分区格式化
格式化成ex3文件系统。
ray@ray-ubuntu:/dev$ sudo mke2fs -j sdb1
[sudo] password for ray:
mke2fs 1.41.11 (14-Mar-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
注:格式化ex3文件系统还可使用命令“sudo mkfs.ext3 /dev/sdb1”
检查分区格式:
ray@ray-ubuntu:~$ sudo df -hT /dev/sdb1
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdb1 ext3 9.9G 151M 9.2G 2% /media/sdb1
3. 如何开机自动挂载
在谈如何自动挂载前,先来说说如何手动挂载。
先在/media/目录下建立disk-2文件夹(当然你可以指定任意的mount point):
ray@ray-ubuntu:/media$ sudo mkdir disk-2
ray@ray-ubuntu:/media$ ls -al
total 16
drwxr-xr-x 4 root root 4096 2011-04-15 17:15 .
drwxr-xr-x 22 root root 4096 2011-03-31 09:45 ..
drwxr-xr-x 2 root root 4096 2011-04-15 17:15 disk-2
lrwxrwxrwx 1 root root 7 2010-08-16 16:34 floppy -> floppy0
drwxr-xr-x 2 root root 4096 2010-08-16 16:34 floppy0
ray@ray-ubuntu:/media$ sudo mount /dev/sdb1 disk-2
ray@ray-ubuntu:/media$ cd disk-2
ray@ray-ubuntu:/media/disk-2$ ls
lost+found
这样就mount成功了。
1)开机自动
脚本文件为/etc/fstab,添加如下:
# mount the second hard disk
/dev/sdb1 /media/sdb1 ext3 defaults 0 0
六个参数分别是:
<file system> <mount point> <type> <options> <dump> <pass>
前三个参数的含义显而易见。
options: 指定加载该设备的文件系统是需要使用的特定参数选项,多个参数是由逗号分隔开来。对于大多数系统使用"defaults"就可以满足需要。
其他常见的选项包括:
ro 以只读模式加载该文件系统
sync 不对该设备的写操作进行缓冲处理,这可以防止在非正常关机时情况下破坏文件系统,但是却降低了计算机速度
user 允许普通用户加载该文件系统
quota 强制在该文件系统上进行磁盘定额限制
noauto 不再使用mount -a命令(例如系统启动时)加载该文件系统
dump: 该选项被"dump"命令使用来检查一个文件系统应该以多快频率进行转储,若不需要转储就设置该字段为0
pass: 该字段被fsck命令用来决定在启动时需要被扫描的文件系统的顺序,根文件系统"/"对应该字段的值应该为1,其他文件系统应该为2。若该文件系统无需在启动时扫描则设置该字段为0
附:一个很好的Ubuntu 命令技巧总结 http://wiki.ubuntu.org.cn/UbuntuSkills#.E6.B7.BB.E5.8A.A0.E4.B8.80.E4.B8.AA.E6.9C.8D.E5.8A.A1