2:dmesg | tail -20 (显示当前U盘挂在哪里,例如[33888.066470] sd 8:0:0:0: [sdb] Attached SCSI disk,我们可以看到当前U盘在sdb)
3:此步可省略!检查坏道sudo badblocks -c 10240 -s -w -t random -v /dev/sdb (耗时较长,500G需要好几个小时)
4:创建分区表,格式化U盘sudo fdisk /dev/sdb(此步也可以用其它GUI磁盘工具实现)
代码: 全选
sudo fdisk /dev/sdb
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): w (此处输入w参数后按回车)
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
sudo fdisk /dev/sdb (继续执行此命令)
The number of cylinders for this disk is set to 60801.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): o (此参数创建dos分区表)
Command (m for help): n (此参数创建新分区)
Command action
e extended
p primary partition (1-4)
p (输入p)
Partition number (1-4): 1 (选择1)
First cylinder (1-60801, default 1): (输入 default后的号码)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-60801, default 60801): (输入 default后的号码)
Using default value 60801
Command (m for help): p (打印信息)
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xcd5bdf9b
Device Boot Start End Blocks Id System
/dev/sdb1 1 60801 488384001 83 Linux
Command (m for help): w (写入并退出)
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
5:sudo modprobe dm-crypt
sudo modprobe sha256_generic
sudo modprobe aes_generic
(以上是载入加密模块)
6:sudo cryptsetup --verify-passphrase luksFormat /dev/sdb1 -c aes -s 256 -h sha256
(正式开始加密工作,过程中需要输2次密码)
--verify-passphrase 确认输入2次密码以保证用户输入的是正确的。
-c aes -s 256 使用256位aes加密
-h sha256 使用256位sha散列算法
7:sudo cryptsetup luksOpen /dev/sdb1 securebackup
(挂载加密盘并自动映射到/dev/mapper/securebackup)
8: sudo mkfs -t ext4 /dev/mapper/securebackup
9:sudo chown -R yourname: /media/disk
(上面是用超级用户创建的,你不能在u盘里创建文件,此步是把u盘属主改变成你的命令)
10:成功后你可以在文件管理器里点击你的加密盘那一个,会询问你密码,输入后就可访问了。不用时要缷载掉加密盘那一个哦。(比如我16G的,在我管理器里会出现几个16G的盘符,缷载时请选择有加密字样的那个)