1
+ #! /bin/sh
2
+
3
+ me=` id -u `
4
+ if [ " $me " -gt 0 ] ; then
5
+ echo ' Please run this script with root privileges!'
6
+ fi
7
+
8
+ source stage0n_variables
9
+
10
+ case ${CLFS_ARCH} in
11
+ x86)
12
+ echo ' ---> Currently only supported on x86, continuing'
13
+ ;;
14
+ * )
15
+ echo ' ***> Currently only supported on x86, exiting'
16
+ exit 0
17
+ ;;
18
+ esac
19
+
20
+ for bin in parted kpartx dmsetup mkfs.ext4 mkfs.msdos ; do
21
+ if which $bin ; then
22
+ echo " $bin found"
23
+ else
24
+ echo " $bin " ' is missing. Exiting!'
25
+ exit 1
26
+ fi
27
+ done
28
+
29
+ [ -z " $SYSTEMSIZE " ] && SYSTEMSIZE=224
30
+ [ -z " $EFISIZE " ] && EFISIZE=32
31
+
32
+ # Remove old build directories, create new ones:
33
+
34
+ rm -rf " ${CLFS} /vmdk-system.mnt"
35
+ rm -rf " ${CLFS} /vmdk-boot.mnt"
36
+ rm -rf " ${CLFS} /vmdk-full.img"
37
+
38
+ mkdir -p " ${CLFS} /vmdk-boot.mnt"
39
+ mkdir -p " ${CLFS} /vmdk-system.mnt"
40
+
41
+ echo ' ===> Preparing the target file system:'
42
+ # This copies all shared objects from the lib and lib64 directories to the targetfs.
43
+ # Note that even unused libraries might be copied. To ultimately safe place it might
44
+ # make more sense to run ldd on the binaries first and just copy required libraries.
45
+
46
+ dd if=/dev/zero bs=1M count=1 seek=$(( $SYSTEMSIZE + $EFISIZE - 1 )) of=" ${CLFS} /vmdk-full.img"
47
+ freeloop=` losetup -f `
48
+ losetup $freeloop " ${CLFS} /vmdk-full.img"
49
+ parted -s $freeloop mklabel gpt
50
+ parted -s $freeloop mkpart boot 1M ${EFISIZE} M
51
+ parted -s $freeloop mkpart system ${EFISIZE} M 100%
52
+ parted -s $freeloop set 1 boot on
53
+ parted -s $freeloop set 1 legacy_boot on
54
+ kpartx -a $freeloop
55
+ sync
56
+ sleep 2
57
+ mkfs.ext4 /dev/mapper/${freeloop#/ dev/ } p2
58
+ mkfs.msdos /dev/mapper/${freeloop#/ dev/ } p1
59
+ mount /dev/mapper/${freeloop#/ dev/ } p2 " ${CLFS} /vmdk-system.mnt"
60
+ mount /dev/mapper/${freeloop#/ dev/ } p1 " ${CLFS} /vmdk-boot.mnt"
61
+
62
+ echo ${CLFS} /cross-tools/${CLFS_TARGET} ${CLFS} /targetfs
63
+ tar -C ${CLFS} /cross-tools/${CLFS_TARGET} --exclude=' *.a' --exclude=' *.la' \
64
+ --exclude=' pkgconfig' --exclude=' ldscripts' \
65
+ -cvf - lib lib64 | tar -C " ${CLFS} /targetfs" -xf -
66
+ tar -C ${CLFS} /targetfs -cvf - . | tar -C " ${CLFS} /vmdk-system.mnt" -xf -
67
+ for d in dev proc sys tmp var ; do
68
+ mkdir " ${CLFS} /vmdk-system.mnt/${d} "
69
+ done
70
+
71
+ # You might specify a certain kernel to use a boot kernel by defining the environment
72
+ # variable TINYKERNEL. If you do not do so, the last kernel in the list of installed
73
+ # kernels is used.
74
+ if [ -n " $TINYKERNEL " -a -f " $TINYKERNEL " ] ; then
75
+ kern=" $TINYKERNEL "
76
+ else
77
+ kern=` ls ${CLFS} /targetfs/boot/vmlinuz* | tail -n1 `
78
+ fi
79
+ mkdir -p " ${CLFS} /vmdk-boot.mnt/isolinux/"
80
+ install -m 0644 " $kern " " ${CLFS} /vmdk-boot.mnt/VMLINUZ.EFI"
81
+
82
+ # Copy the bootloader for BIOS. This also copies modules for menus ans graphical menus
83
+ # as well for chainloading bootloaders on harddisks. I you want the bare minimum, start
84
+ # with ldlinux.c32, libutil.c32, libcom32.c32 and libgpl.c32:
85
+ for f in bios/com32/menu/menu.c32 bios/com32/menu/vesamenu.c32 \
86
+ bios/com32/modules/ifcpu64.c32 bios/com32/modules/ifcpu.c32 \
87
+ bios/com32/modules/reboot.c32 bios/com32/chain/chain.c32 \
88
+ bios/com32/elflink/ldlinux/ldlinux.c32 bios/com32/libutil/libutil.c32 \
89
+ bios/com32/cmenu/libmenu/libmenu.c32 bios/com32/lib/libcom32.c32 \
90
+ bios/com32/lua/src/liblua.c32 bios/com32/gpllib/libgpl.c32 ; do
91
+ install -m 0644 ${CLFS} /hosttools/share/syslinux/$f " ${CLFS} /vmdk-boot.mnt/isolinux/"
92
+ done
93
+
94
+ # Copy the configuration file for isolinux as well as the help.txt that is displaed
95
+ # before the prompt boot: - see syslinux' wiki for details:
96
+ for f in syslinux.cfg help.txt ; do
97
+ install -m 0644 patches/${f} " ${CLFS} /vmdk-boot.mnt/isolinux/"
98
+ done
99
+ cp -v " ${CLFS} /vmdk-boot.mnt/isolinux/syslinux.cfg" " ${CLFS} /vmdk-boot.mnt/isolinux/extlinux.conf"
100
+ " ${CLFS} /hosttools/share/syslinux/bios/extlinux/extlinux" --install " ${CLFS} /vmdk-boot.mnt/isolinux/"
101
+
102
+ echo ' ===> Populating the boot media for UEFI:'
103
+
104
+ # Populate the efi partition, the efi boot image will contain the following files:
105
+ #
106
+ # /EFI/BOOT/BOOTX64.EFI
107
+ # /loader/loader.conf
108
+ # /loader/entries/00tinycross.conf
109
+ # /VMLINUZ.EFI
110
+ # /INITRD.GZ
111
+
112
+ mkdir -p " ${CLFS} /vmdk-boot.mnt/EFI/BOOT"
113
+ mkdir -p " ${CLFS} /vmdk-boot.mnt/loader/entries"
114
+
115
+ cp -v ${CLFS} /hosttools/lib/gummiboot/gummibootx64.efi " ${CLFS} /vmdk-boot.mnt/EFI/BOOT/BOOTX64.EFI"
116
+ cp -v patches/loader.conf " ${CLFS} /vmdk-boot.mnt/loader/loader.conf"
117
+ cp -v patches/tiny-hdd.conf " ${CLFS} /vmdk-boot.mnt/loader/entries/00tinycross.conf"
118
+
119
+ # At this point you can run a script that copies additional files to the root filesystem and the boot partition:
120
+ #
121
+ # ${CLFS}/vmdk-boot.mnt
122
+ # ${CLFS}/vmdk-system.mnt
123
+
124
+ sync
125
+ umount /dev/mapper/${freeloop#/ dev/ } p2
126
+ umount /dev/mapper/${freeloop#/ dev/ } p1
127
+ sleep 2
128
+ dmsetup remove /dev/mapper/${freeloop#/ dev/ } p2
129
+ dmsetup remove /dev/mapper/${freeloop#/ dev/ } p1
130
+ dd if=" ${CLFS} /hosttools/share/syslinux/bios/mbr/gptmbr.bin" of=${freeloop} conv=notrunc
131
+ sync
132
+ losetup -d $freeloop
133
+
134
+
0 commit comments