Theres lots of documents on using dm-crypt to encrypt your root partition but i couldn't find any using gpg. So heres how I did it. Please be gentle, this is my first gentoo howto post.
Thanks to hulk2nd for this post http://forums.gentoo.org/viewtopic.php? ... ypted+root
Thanks to veezi for this post http://forums.gentoo.org/viewtopic.php? ... ht=dmcrypt
Both of these were a great help!
Things to Note:
This is all explain in regards to my setup, yours will differ.
This was all done immediately after a fresh install!
I use lilo instead of grub, so things are explained with lilo
I have done this and it is currently working on my laptop for 3 days now.
Very Important:
You will need a spare partition that can hold the entire contents of your / directory.
All commands were done with regards to MY setup.
My Setup:
This was done on a Toshiba Tecra 8000, PentiumII, 256M ram, 10G HD. Heres how i partitioned, yours will be
different. Note: Im using hda3 as my / and ill be using hda7 as the backup /
Code: Select all
hda1 /boot ext2 25
hda2 swap sw 128
hda3 / ext3 2G
hda5 /usr ext3 4G
hda6 /usr/portage ext3 2G
hda7 ext3 900M
hda8 /var ext3 800M
You must be using udev!
You will need a LiveCD disk, I'm using Knoppix but the gentoo install disk will work.
I'm using development sources 2.6.10-rc1, You need the following in your kernel config:
Code: Select all
Device Drivers -->
Block Devices -->
<*> Loopback device support
<*> Cryptoloop Support
<*> RAM disk support
(8192) Default RAM disk size (kbytes)
[*] Initial RAM disk (initrd) support
[*] Support for Large Block Devices
Multi-device support (RAID and LVM) -->
[*] Multiple devices driver support (RAID and LVM)
<*> Device mapper support
<*> Crypt target support
File systems -->
Pseudo filesystems -->
[ ] /dev file system support
Cryptographic options -->
<*> SHA256 digest algorithm
<*> SHA384 and SHA512 digest algorithms
<*> AES cypher algorithms (i586)
You need the following programs emerged:
- udev
- hotplug
- coldplug
- device-mapper
- cryptsetup
- gnupg
- sharutils (needed for uuencode)
Code: Select all
nano /etc/conf.d/rc
set RC_DEVICE_TARBALL = no
Boot from your Live CD. Were going to make a mirror of your / directory then another backup.
Code: Select all
mkdir /{gentoo,newroot}
mount /dev/hda3 /gentoo
mke2fs -j /dev/hda7
mount /dev/hda7 /newroot
cp -r -p -v /gentoo/* /newroot/
tar -cjvvf /newroot/root.tar.bz2 /gentoo/*
mount /dev/hda1 /newroot/boot
mount /dev/hda5 /newroot/usr
mount /dev/hda6 /newroot/usr/portage
mount /dev/hda8 /newroot/var
mount -o bind /proc /newroot/proc
chroot /newroot /bin/bash
env-update
source /etc/profile
nano /etc/lilo.conf
Code: Select all
image=/boot/vmlinuz-2.6.10.0
root=/dev/hda7 (NOT /dev/hda3 LIKE THE ORIGINAL)
label=wonderland
Code: Select all
lilo
nano /etc/fstab
change the root=/dev/hda3 to root=/dev/hda7
exit
umount /newroot/{boot,usr/portage,usr,var,proc}
umount /newroot
umount /gentoo
reboot
Step 2
Now were on our new / (/dev/hda7) lets get some stuff installed
Code: Select all
mkdir /{rabbithole.rd,rabbithole,root/.gnupg}
mount /boot
cd /boot
Code: Select all
head -c 2880 /dev/urandom | uuencode -m - | head -n 65 | \
tail -n 64 | gpg -ac >/boot/rabbithole.key
Code: Select all
gpg --quiet -d /boot/rabbithole.key
now lets create our RAM disk
Code: Select all
cd /root
touch rabbithole.rd
dd if=/dev/zero of=/root/rabbithole.rd bs=1024k count=8
losetup /dev/loop0 /root/rabbithole.rd
mke2fs /dev/loop0
mount /dev/loop0 /rabbithole.rd
cd /rabbithole.rd
mkdir {bin,boot,dev,etc,lib,proc,rabbithole,root,root/.gnupg,.gnupg}
cp /boot/rabbithole.key /rabbithole.rd/boot/
cp /root/.gnupg/* /rabbithole.rd/root/.gnupg/
cp /root/.gnupg/* /rabbithole.rd/.gnupg/
touch linuxrc
chmod +x linuxrc
Lets populate the rabbithole.rd
Code: Select all
cp /bin/{sh,cat,mount,umount,mkdir,chroot,cryptsetup} /rabbithole.rd/bin/
cp /sbin/{pivot_root,blockdev} /rabbithole.rd/bin/
cp /usr/bin/gpg /rabbithole.rd/bin/
needed libraries by typing ldd filename, heres and example:
Code: Select all
ldd /rabbithole.rd/blockdev
linux-gate.so.1 => (0xffffe000)
libc.so.6 => /lib/libc.so.6 (0xb7ece000)
/lib/ld-linux.so.2 (0xb7f3b000)
Code: Select all
cp /lib/libc.so.6 /rabbithole.rd/lib/
cp /lib/ld-linux.so.2 /rabbithole.rd/lib/
there needed libraries over.
Step 4
Now lets create the devices on the RAM disk
Code: Select all
mknod /rabbithole.rd/dev/console c 5 1
mknod /rabbithole.rd/dev/null c 1 3
mknod /rabbithole.rd/dev/hda3 b 3 3
mknod /rabbithole.rd/dev/tty c 4 0
mkdir /rabbithole.rd/dev/mapper
mknod /rabbithole.rd/dev/mapper/control c 10 63
mknod /rabbithole.rd/dev/random c 1 8
mknod /rabbithole.rd/dev/urandom c 1 9
Now lets create the linuxrc (thanks veezi)
Code: Select all
nano /rabbithole.rd/linuxrc
Code: Select all
#!/bin/sh
export PATH=/bin
#grab the command line:
mount -t proc proc /proc
CMDLINE=`cat /proc/cmdline`
umount /proc
#mount the rabbithole and fall through it:
gpg --quiet -d /boot/rabbithole.key | cryptsetup -h plain -c aes \
-s 256 create rabbithole /dev/hda3
mount /dev/mapper/rabbithole /rabbithole
cd /rabbithole
mkdir potion
pivot_root . potion
#drink the potion and away we go
exec chroot . /bin/sh <<- EOF >dev/console 2>&1
umount potion
rm -rf potion
/sbin/blockdev --flushbufs /dev/ram0
exec /sbin/init ${CMDLINE}
EOF
Lets check the RAM disk to make sure it works properly
Code: Select all
cd /
chroot /rabbithole.rd /bin/sh
/bin/blockdev --help
/bin/cat --help
/bin/chroot --help
/bin/cryptsetup --help
/bin/gpg --help
/bin/mkdir --help
/bin/mount --help
/bin/pivot_root --help
/bin/sh --help
/bin/umount --help
/bin/gpg --quiet -d /boot/rabbithole.key
exit
gpg should decrypt the key. If theres missing library's, exit,
copy them over and try again. when all is good:
Code: Select all
umount /rabbithole.rd
mount /boot
cp /root/rabbithole.rd /boot
Now lets prepare our encrypted root
Code: Select all
dd if=/dev/zero of=/dev/hda3
gpg --quiet -d /boot/rabbithole.key | cryptsetup -h plain -c aes \
-s 256 create rabbithole /dev/hda3
mke2fs -j /dev/mappper/rabbithole
mount /dev/mapper/rabbithole /rabbithole
cd /rabbithole
tar jxvf /root.tar.bz2
mv gentoo/* ./
rmdir gentoo/lost*
rm gentoo/.bash*
rmdir gentoo
cd /rabbithole/etc/
nano fstab
Code: Select all
/dev/mapper/rabbithole / ext3 noatime 0 1
Code: Select all
nano /etc/lilo.confthings dont go so well)
Code: Select all
image=/boot/vmlinuz-2.6.10.0
root=/dev/hda7
read-only
label=wonderland-bak
image=/boot/vmlinuz-2.6.10.0
label=wonderland
root=/dev/ram0
read-write
initrd=/boot/rabbithole.rd
append="init=linuxrc"
Code: Select all
liloCode: Select all
Warning: '/proc/partitions' does not match '/dev' directory structure.
Name change: '/dev/dm-0' -> '/dev/mapper/rabbithole'
now lets finish things up
Code: Select all
cp /etc/lilo.conf /rabbithole/etc/lilo.conf
losetup -d /dev/loop0
umount /rabbithole
umount /boot
cryptsetup remove rabbithole
file system error, enter root password. I just ignored this and it restarted as normal. If things went ok you'll be a happy camper. I have been running this for a while now and it works pretty good. Havent had any problems.




