Commit | Line | Data |
---|---|---|
25b16ae2 AE |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2012-2020 Ruben Rodriguez <ruben@trisquel.info> | |
4 | # Copyright (C) 2020 Andrew Engelbrecht <andrew@fsf.org> | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | # | |
20 | ||
21 | set -e | |
22 | ||
23 | usage(){ | |
36f232d0 | 24 | echo |
25b16ae2 AE |
25 | echo You need to run this script as root |
26 | echo Usage: sudo $0 distro.iso /dev/sdX | |
97a175de | 27 | echo Example: sudo $0 trisquel_11.0-fsf_amd64.iso /dev/sdb |
25b16ae2 AE |
28 | echo |
29 | echo WARNING!: this script will delete all data on the whole disk you pass as the second parameter. Make sure it is your USB drive and not your internal hard drive! | |
30 | echo ANOTHER WARNING!: This script can bite your dog. Use it with care, backup your data. | |
36f232d0 | 31 | echo |
25b16ae2 AE |
32 | exit 1 |
33 | } | |
34 | ||
35 | [ $(id -u) != 0 ] && usage | |
36 | [ $# != 2 ] && usage | |
37 | ||
38 | ISO=$1 | |
39 | DEV=$2 | |
40 | PERSISTENCESIZE=4096 # Size of the persistence file, in MB | |
41 | ||
42 | ISOTMP=$(mktemp -d) | |
43 | DEVTMP=$(mktemp -d) | |
44 | ||
45 | umount $DEV* || true | |
46 | mount -o loop $ISO $ISOTMP | |
47 | ||
48 | # Create FAT32 LBA partition taking all disk | |
49 | echo 'start=2048, type=c' | sfdisk $DEV | |
50 | mkfs.vfat -I -F32 ${DEV}1 -n FSF-LIVE | |
51 | ||
52 | # Copy the data | |
53 | mount ${DEV}1 $DEVTMP | |
54 | cp -vr $ISOTMP/* $ISOTMP/.disk $DEVTMP || true | |
55 | ||
56 | cp -vr $DEVTMP/isolinux $DEVTMP/syslinux | |
57 | mv $DEVTMP/syslinux/isolinux.cfg $DEVTMP/syslinux/syslinux.cfg | |
58 | ||
59 | # Create persistency file | |
60 | # dd if=/dev/zero of=$DEVTMP/casper-rw bs=1M count=$PERSISTENCESIZE oflag=sync status=progress | |
61 | # mkfs.ext4 -L casper-rw -F $DEVTMP/casper-rw | |
62 | # sed -i 's/noprompt --/noprompt persistent --/' $DEVTMP/syslinux/txt.cfg $DEVTMP/isolinux/txt.cfg | |
63 | ||
64 | umount $DEVTMP | |
65 | umount $ISOTMP | |
66 | ||
19d53a74 AE |
67 | rmdir $DEVTMP |
68 | rmdir $ISOTMP | |
25b16ae2 | 69 | |
19d53a74 | 70 | # the order of steps might be wrong, so we run these commands twice |
613fa196 | 71 | # (for the sake of GRUB booting) |
19d53a74 AE |
72 | for times in 1 2 ; do |
73 | # Set up bootloader, requires syslinux. version 6.04 has been tested. | |
74 | syslinux --directory /syslinux/ --install ${DEV}1 | |
75 | sudo dd if=/usr/lib/SYSLINUX/mbr.bin of=${DEV} | |
76 | parted $DEV set 1 boot on | |
77 | done | |
c5b0a313 AE |
78 | |
79 | rmdir $DEVTMP | |
80 | rmdir $ISOTMP | |
81 | ||
2f56ad2d | 82 | #eject $DEV |
25b16ae2 AE |
83 | sync |
84 |