2 # Filename: mkpersistenthome
3 # Purpose: mkpersistenthome - create grml home directory image
4 # Authors: grml-team (grml.org), (c) Klaus Knopper Feb 2003, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 # Latest change: Fre Mär 16 19:59:53 CET 2007 [mika]
8 ################################################################################
10 export PATH="/bin:/sbin:/usr/bin:/usr/sbin"
12 if [ "`id -u`" != "0" ] ; then
15 export HOME='/home/grml'
19 DIRECTORY=$(mktemp -d /mnt/XXXXXX)
23 [ -n "$DIRECTORY" ] && umount "$DIRECTORY" 2>/dev/null
24 [ -d "$DIRECTORY" ] && rmdir "$DIRECTORY"
25 rm -f "$TMP" "$TMP.done" "$TMP.err"
31 HOMEKB="$(du -sk $HOME 2>/dev/null | awk '{print $1}')"
33 # Language-dependent messages
36 TITLE1="Permanentes grml Heimverzeichnis anlegen"
37 MESSAGE1="Dieses Skript richtet ein permanentes Heimverzeichnis für den User \"grml\" auf Ihrer Festplatte oder einem Wechselmedium wie Memorystick, Compactflash oder ZIP-Medium ein. Dadurch ist es möglich, Daten und persönliche Konfigurationen über einen Reboot hinaus zu speichern, sofern sie im persönlichen Heimverzeichnis des Benutzers abgelegt werden. Per Bootoption, z.B. \"home=/dev/sda1\" für die erste Partition einer SCSI-Festplatte oder eines USB-Memorystick, können Sie beim Systemstart das permanente Heimverzeichnis wieder aktivieren. Die Bootoption \"home=scan\" durchsucht automatisch alle Partitionen und erkannten Speichermedien nach einem persistenten grml-Heimverzeichnis.
39 Möchten Sie das Heimverzeichnis des Benutzers \"grml\" permanent speichern?"
40 MESSAGE2="Bitte wählen Sie die Partition, auf der Sie das Heimverzeichnis (oder ein Image davon) anlegen möchten."
41 MESSAGE3="Möchten Sie die KOMPLETTE Partition verwenden und mit den Linux-Dateisystem formatieren?
43 NEIN=Image-Datei auf bestehendem Dateisystem anlegen."
46 Die grml-Konfiguration wurde erfolgreich gespeichert. Ihre Konfigurationsdateien werden beim nächsten grml-Bootvorgang in die Ramdisk restauriert, wenn Sie im Bootscreen \"grml floppyconfig\" (Diskette) bzw. \"grml myconfig=/mnt/verzeichnisname\" angeben."
47 ERROR="Leider konnte die grml-Konfiguration NICHT gespeichert werden:"
48 MESSAGE_NO_PARTS="Keine passende Partition gefunden. Zur Erinnerung: NTFS-Partitonen können mit Linux nicht beschrieben werden."
51 TITLE1="Create persistent grml home directory"
52 MESSAGE1="This script creates a persistent home directory for the \"grml\" account on your harddisk or on a changeable medium like memory stick, compact flash or zip media. Using this features makes it possible to store personal data and config files permanently over a reboot, if they are stored inside the home directory of the \"grml\" user. The boot option \"home=/dev/sda1\", for the first partition of a SCSI harddisk or USB memory stick as example, activates the persistent home directory at system startup. You can also let grml scan all autodetected storage devices using the boot option \"home=scan\".
54 Do you want to create a persistent home directory for the \"grml\" user?"
56 MESSAGE2="Please select partition for creating persistent homedir (or image):"
57 MESSAGE3="Do you want to use the ENTIRE Partition, and would like to format it with the Linux filesystem?
59 NO=Just create an image in the existing filesystem."
62 Creation of grml configuration floppy was successful. Your configuration files will be reinstalled to the ramdisk on next grml boot if you specify \"grml floppyconf\" (floppy disk), or \"grml myconfig=/mnt/directoryname\" at the boot prompt."
63 ERROR="The grml configuration could NOT be saved:"
64 MESSAGE_NO_PARTS="No suitable partitions could be found. Remember that NTFS-Partitions are not writable with linux."
68 $DIALOG --cr-wrap --clear --title "$TITLE1" --yesno "$MESSAGE1" 18 75 || bailout
73 for i in `fdisk -l | grep -v NTFS | awk '/^\/dev\// { print $1 }'` ; do
74 PARTITIONS="$PARTITIONS ${i} [Disk/Partition] off"
75 echo "PARTITIONS=$PARTITIONS ${i} [Disk/Partition] off" >> /tmp/part
77 [ -z "$PARTITIONS" ] && { $DIALOG --cr-wrap --clear --title "$TITLE1" --msgbox "$ERROR $MESSAGE_NO_PARTS" 10 75; bailout; }
80 while [ -z "$PARTITION" -o -z "$DIRECTORY" -o ! -e "$DIRECTORY" ]; do
82 $DIALOG --cr-wrap --clear --title "$TITLE1" --radiolist "$MESSAGE2" 18 75 9 $PARTITIONS 2>"$TMP" || bailout
87 if $DIALOG --cr-wrap --clear --title "$TITLE1" --defaultno --yesno "$MESSAGE3" 15 75; then
91 FILEINFO="grml.img on $PARTITION"
92 DEVICE="$DIRECTORY/grml.img"
93 mount | grep -q "$DIRECTORY" || mount -r $PARTITION "$DIRECTORY" 2>"$TMP.err"
94 [ "$?" != "0" ] && { $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
95 mount | grep -q "$DIRECTORY.*ntfs" && { $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR NTFS" 10 75; bailout; }
96 mount -o remount,rw $PARTITION "$DIRECTORY"
99 # More language-dependent messages
102 MESSAGE4="Sind Sie ABSOLUT SICHER, dass Sie die Partition $PARTITION formatieren möchten? ALLE DATEN WERDEN DADURCH GELÖSCHT!"
103 MESSAGE5="Möchten Sie Ihr Heimverzeichnis mit AES256 (=Advanced Encryption Standard 256bit, s.a. http://csrc.nist.gov/encryption/aes/) verschlüsselt speichern? Hierzu ist die Eingabe eines sehr langen Passwortes beim Einrichten sowie beim Einbinden des Verzeichnisses beim Systemstart erforderlich. NEIN=unverschlüsselt"
104 MESSAGE6="Bitte geben Sie die gewünschte Größe Ihres persistenten Heimverzeichnisses in MB an (aktuell belegt: $HOMEKB Kilobyte, verfügbar:"
105 MESSAGE7="Formatiere $FILEINFO mit dem ext2 Dateisystem und kopiere Daten..."
106 MESSAGE8="Lege Datenbereich für Linux an..."
107 SUCCESS="$FILEINFO wurde erfolgreich mit dem Linux ext2 Dateisystem formatiert, und Ihre Heimverzeichnis-Daten wurden darauf transferiert.
109 Sie können jetzt Ihren Computer neu starten, und beim grml boot:-Prompt durch Eingabe von \"grml home=$PARTITION\" oder \"grml home=scan\" Ihr permanentes Heimverzeichnis aktivieren. Falls Sie außerdem (mit dem save-config Skript) die Systemeinstellungen gesichert haben, können Sie diese Option mit der Angabe von \"myconf=$PARTITION\" kombinieren."
112 MESSAGE4="Are you positively SURE that you want to format partition $PARTITION? ALL DATA WILL BE LOST!"
113 MESSAGE5="Do you want to save your home directory encrypted with AES256 (Advanced Encryption Standard, see http://csrc.nist.gov/encryption/aes/)? If yes, you will have to specify a very long password at homedir creation and boot time."
114 MESSAGE6="Please enter the desired size of your persistent homedir in MB (currently used: $HOMEKB kB, available:"
115 MESSAGE7="Formatting $FILEINFO with ext2 filesystem and copying data..."
116 MESSAGE8="Preparing for Linux filesystem..."
117 SUCCESS="$FILEINFO has been succeessfully formatted with the Linux ext2 filesystem, and your home directory has been transferred to it.
119 You may now reboot your computer and type \"grml home=$PARTITION\" or \"grml home=scan\" at the grml boot: prompt to take advantage of your new persistent home directory. If you have also saved the system configuration (using the save-config script), you can use this in combination with \"myconf=$PARTITION\"."
126 while [ ! -e "$TMP.done" ]; do
127 echo "$status" ; status="`expr \( 100 - $status \) / 4 + $status`"; sleep 2;
128 done | $DIALOG --title "$TITLE1" --gauge "$1" 8 75 0
133 touch "$TMP.done" ; wait ; rm -f "$TMP.done"
136 if [ "$DEVICE" = "$PARTITION" ]; then
137 $DIALOG --cr-wrap --clear --title "$TITLE1" --defaultno --yesno "$MESSAGE4" 6 75 || bailout
140 AVAIL="$(df -m $DIRECTORY/. | awk '/^\/dev\//{print $4}')"
142 until [ "$AMOUNT" -ge 1 -a "$AMOUNT" -le "$AVAIL" ] 2>/dev/null; do
143 $DIALOG --cr-wrap --clear --title "$TITLE1" --inputbox "$MESSAGE6 $AVAIL MB)" 10 62 "30" 2>"$TMP" || bailout
148 dd if=/dev/urandom of="$DEVICE" bs=1M count="$AMOUNT" 1>/dev/null || { killgauge; sleep 2; bailout; }
152 # Normal loopback file or partition
154 umount "$DEVICE" 2>/dev/null
157 mke2fs -F -m0 "$DEVICE" 1>/dev/null 2>"$TMP.err" || { killgauge; $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
161 [ -f "$DEVICE" ] && LOOPOPT="-o loop"
162 mkdir -p /tmp/grmlhome
163 mount -t ext2 $LOOPOPT "$DEVICE" /tmp/grmlhome 2>"$TMP.err" && rsync -Ha "$HOME/" /tmp/grmlhome 2>"$TMP.err" || { killgauge; umount /tmp/grmlhome 2>/dev/null; $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
166 umount "$DIRECTORY" 2>/dev/null
169 $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$SUCCESS" 17 65
173 ## END OF FILE #################################################################