milch's shitty blog


Posts Tagged ‘luks’

hdd formatiern auf kommandozeile

Sunday, April 8th, 2012

tja wie das so ist: wenn es schoene guis gibt die das denken fuer einen uebernehmen macht mans nicht mehr selbst, so auch beim formatiern meiner hdds. Disk Utility (anscheinend von RedHat) versagt, gparted versagt, muss mans also per hand machen, kann ja nicht so schwer sein. Also, einmal angenommen wir wollen eine hdd voellig loeschen und dann in 2 Partitionen unterteilen, eine davon mit luks gesichertes ext4, die andere NTFS. Sollte doch moeglich sein, oder?
Also: 500Gb HDD, wird erkannt als /dev/sdc
zuerst mal fdisk anwenden um alles neu zu machen:

$ sudo fdisk /dev/sdc
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)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-976773167, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-976773167, default 976773167): +400G

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 2):
Using default value 2
First sector (838862848-976773167, default 838862848):
Using default value 838862848
Last sector, +sectors or +size{K,M,G} (838862848-976773167, default 976773167):
Using default value 976773167

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

man sollte es kaum glauben, aber das wars schon. wir ahben jetzt 2 partitionen, eine 400GB gross und eine ~100GB. wird jetzt zeit da mal ein ordentliches FS drauf zu machen. Auf die partition1 (400GB) kommt erstmal ein layer crypto:

$ sudo cryptsetup -c aes-xts-plain -s 512 luksFormat /dev/sdc1

WARNING!
========
This will overwrite data on /dev/sdc1 irrevocably.

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

crypto ist auch fertig, was brauchen wir noch? ach ja, filesysteme… das geht aber nur wenn der cryptocontainer geoeffnet wird:

$ sudo cryptsetup luksOpen /dev/sdc1 data
Enter passphrase for /dev/sdc1:

der container ist jetzt geoeffnet unter dem namen “data”, kann man gerne anders machen. also weiter gehts, fs muss da ja schliesslich auch drauf. ich hab mich fuer ext4 entschieden, das sieht dann so aus:

$ sudo mkfs.ext4 /dev/mapper/data
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
26214400 inodes, 104857095 blocks
5242854 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
3200 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

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

das sieht so weit also auch gut aus, nun bruachen wir nur noch die zweite partition, mit dem NTFS:

$ sudo mkfs.ntfs /dev/sdc2
Cluster size has been automatically set to 4096 bytes.
Initializing device with zeroes: 100% - Done.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.

leider dauert das erstellen des NTFS doch SEHR viel laenger als alles andere zusammen, aber es funktioniert ;)