Ubuntu Pastebin

Paste from TJ at Sun, 25 Oct 2015 17:21:09 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# create a logical volume for demonstration; this would be entire device e.g. /dev/sda

$ sudo lvcreate -L 1G -n demo VG_DATA
  Logical volume "demo" created.

# create a temporary 'plain' encrypted device (/dev/mapper/enc_demo) with a key from /dev/random

$ sudo cryptsetup open /dev/mapper/VG_DATA-demo enc_demo  --type plain --key-file /dev/random

# Now the big trick; by writing zeros into THE ENCRYPTED DEVICE the container itself is filled with
# random data (looking at /dev/mapper/VG_DATA-demo after this command would show randomised data)
# this is MANY TIMES FASTER than writing random data from /dev/urandom

$ sudo dd if=/dev/zero of=/dev/mapper/enc_demo bs=100M
dd: error writing ‘/dev/mapper/enc_demo’: No space left on device
11+0 records in
10+0 records out
1073741824 bytes (1.1 GB) copied, 17.1467 s, 62.6 MB/s
dd: closing input file ‘/dev/zero’: Bad file descriptor

# get rid of the temporary encrypted device node

$ sudo cryptsetup close enc_demo

# now create the permanent LUKS device (which just writes a LUKS header to the beginning of /dev/mapper/VG_DATA-demo)

$ sudo cryptsetup luksFormat /dev/mapper/VG_DATA-demo

WARNING!
========
This will overwrite data on /dev/mapper/VG_DATA-demo irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase: 


# open the encrypted device

$ sudo cryptsetup open --type luks /dev/mapper/VG_DATA-demo LUKS_demo
Enter passphrase for /dev/mapper/VG_DATA-demo: 

# create a file-system

$ sudo mkfs.ext4 -L Demo /dev/mapper/LUKS_demo
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 261632 4k blocks and 65408 inodes
Filesystem UUID: 742ace7f-1c28-4433-aaaa-e1eae736fcdd
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

$ sudo lsblk -f /dev/mapper/VG_DATA-demo
NAME         FSTYPE      LABEL UUID                                 MOUNTPOINT
VG_DATA-demo crypto_LUKS       704072a7-4f26-48d1-b719-d655a2234561 
└─LUKS_demo  ext4        Demo  742ace7f-1c28-4433-aaaa-e1eae736fcdd 
Download as text