今天,在整理图片时,发现根目录硬盘空间已经所剩无几了,而网站和所有相关文件主要放置在根下data目录(/data)里,但/home下是有空间,而又不想把文件放到/home下面去,只有再加一个新硬盘,对以后/data目录的文件管理也比较好。
那么就先关掉主机,再加上新硬盘(其它电脑使用过的500G硬盘),插上后再启动电脑。
接下来,就开始工作了:
1. 查看硬盘信息:
feigo@figo:~$ sudo df -h
文件系统 容量 已用 可用 已用% 挂载点
rootfs 102G 92G 4.7G 96% /
udev 10M 0 10M 0% /dev
tmpfs 799M 1.8M 798M 1% /run
/dev/disk/by-uuid/3640f24a-4870-42e2-ae07-109cb9c35164 102G 92G 4.7G 96% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 4.6G 224K 4.6G 1% /run/shm
/dev/sda7 92M 26M 62M 30% /boot
/dev/sda9 201G 23G 169G 12% /home
feigo@figo:~$ sudo fdisk -l
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifIEr: 0x3f1e271a
Device Boot Start End Blocks Id System
/dev/sdb1 63 102414374 51207156 7 HPFS/NTFS/exFAT
/dev/sdb2 102414375 976768064 437176845 f W95 Ext'd (LBA)
/dev/sdb5 102414438 409625369 153605466 b W95 FAT32
/dev/sdb6 409625433 716836364 153605466 b W95 FAT32
/dev/sdb7 716836428 976768064 129965818+ 7 HPFS/NTFS/exFAT
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifIEr: 0xc35aebd4
Device Boot Start End Blocks Id System
/dev/sda1 * 63 104872319 52436128+ 7 HPFS/NTFS/exFAT
/dev/sda2 104872381 976771071 435949345+ f W95 Ext'd (LBA)
/dev/sda5 104872383 231962534 63545076 7 HPFS/NTFS/exFAT
/dev/sda6 231962598 300929579 34483491 b W95 FAT32
/dev/sda7 300931072 301125631 97280 83 Linux
/dev/sda8 301127680 517726207 108299264 83 Linux
/dev/sda9 517728256 945461247 213866496 83 Linux
/dev/sda10 945463296 976771071 15653888 82 Linux swap / Solaris
我们可以看到有两个硬盘,sda和sdb,其中sda是目前使用中的硬盘,sdb是新加上去的硬盘。
2. 针对sdb创建新硬盘分区:
先说明一下,fdisk 可以用 m 命令来看 fdisk 命令的内部命令:
a :命令指定启动分区
d :命令删除一个存在的分区
l :命令显示分区 ID 号的列表
m :查看 fdisk 命令帮助
n :命令创建一个新分区
p :命令显示分区列表
t :命令修改分区的类型 ID 号
w :命令是将对分区表的修改存盘让它发生作用
feigo@figo:~$ su
密码:
root@figo:/home/feigo# fdisk /dev/sdb
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)
由于sdb硬盘上已经有几个分区,人们需要先删除这些分区:
Command (m for help): d # 删除分区,依次输入数字
Partition number (1-7): 7
Command (m for help): d
Partition number (1-6): 6
Command (m for help): d
Partition number (1-5): 5
Command (m for help): d
Partition number (1-5): 2
Command (m for help): d
Selected partition 1
Command (m for help): w # 保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
再次查看硬盘分区信息,将会看到所有分区已被删除:
root@figo:/home/feigo# fdisk -l
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifIEr: 0x3f1e271a
Device Boot Start End Blocks Id System
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors